Skip to main content
Solved

Create a JSON in a workflow

  • December 3, 2024
  • 4 replies
  • 220 views

dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)

Hi All,

 

I need to create a json payload inside a workflow to send to an external Rest API.

I used the org.camunda.spin.Spin.JSON   according to the camunda documentation.

Below is my script

var SpinJSON = org.camunda.spin.Spin.JSON;
var jsonObject = SpinJSON("{}");
var customerId = execution.getVariable("CustomerId");
var eventType = execution.getVariable("ifsBpaProjectionOperation");
jsonObject.prop("CustomerId", customerId); 
jsonObject.prop("event_type", eventType); 
execution.setVariable("varJsonBody", jsonObject.toString());

In the Debug mode, everything looks fine

Trigger for this is an event and we are trying to sync customer records with a 3rd party system

 

But in the execution, it gives an unexpected server eror

 

Looks like it Spin.Json prop() doesn’t work. Is this a bug?

 

IFS version: 24.1.3

 

Best answer by kamnlk

@dsj 

It seems like in run time the value we get for “ifsBpaProjectionOperation” is not compatible with Spin libs prop().

Can you try change the script slightly like the following. Adding String() will get the string representation of the value of the `ifsBpaProjectionOperation` which should solve the issue you are seeing 

jsonObject.prop("event_type", String(eventType)); 

 

View original

Forum|alt.badge.img+9
  • Hero (Employee)
  • December 3, 2024

Hi,

From workflow perspective it looks like spin is working as expected. since the json variable is created properly. 

Can you give bit more detail on what you are trying to do ? if the external system call happening inside the workflow as an IFS REST task or how are you using the json variable (varJsonBody) to set it to the external Rest API call?


dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • December 18, 2024

Hi ​@kamnlk 

Thanks for the reply.

Yes, the external system call happens as a REST task.

Debug works fine and create the json payload properly send the request, which means the syntax in the Create Delete payload script (which mentioned above) is fine.

Then I deploy the BPA, and getting the above mentioned exception when trying to trigger the workflow by deleting a customer record. I enabled the devtools and got some additional details about the error.

Customer/Form (server error)
Unexpected internal server error occurred.
Error details: N/A

Server stack trace error(s):
  java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures [(java.lang.String, java.lang.Number), (java.lang.String, java.lang.String), (java.lang.String, java.lang.Boolean), (java.lang.String, boolean), (java.lang.String, int)] of the method org.camunda.spin.impl.json.jackson.JacksonJsonNode.prop for argument types [java.lang.String, com.ifsworld.fnd.bpa.process.ProjectionAction]
  Can't unambiguously select between fixed arity signatures [(java.lang.String, java.lang.Number), (java.lang.String, java.lang.String), (java.lang.String, java.lang.Boolean), (java.lang.String, boolean), (java.lang.String, int)] of the method org.camunda.spin.impl.json.jackson.JacksonJsonNode.prop for argument types [java.lang.String, com.ifsworld.fnd.bpa.process.ProjectionAction]

Any idea?


Forum|alt.badge.img+9
  • Hero (Employee)
  • December 18, 2024

@dsj 

It seems like in run time the value we get for “ifsBpaProjectionOperation” is not compatible with Spin libs prop().

Can you try change the script slightly like the following. Adding String() will get the string representation of the value of the `ifsBpaProjectionOperation` which should solve the issue you are seeing 

jsonObject.prop("event_type", String(eventType)); 

 


dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • December 18, 2024

Amazing ​@kamnlk. it worked just like that!

Who would have thought ifsBpaProjectionOperation has it’s own type :D

Thanks a lot for your help


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings