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
Page 1 / 1
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?
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.
Server stack trace error(s): java.lang.NoSuchMethodException: Can't unambiguously select between fixed arity signatures e(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 ejava.lang.String, com.ifsworld.fnd.bpa.process.ProjectionAction] Can't unambiguously select between fixed arity signatures e(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 ejava.lang.String, com.ifsworld.fnd.bpa.process.ProjectionAction]
Any idea?
@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));
Amazing @kamnlk. it worked just like that!
Who would have thought ifsBpaProjectionOperation has it’s own type :D