Skip to main content
Solved

Create a JSON in a workflow

  • December 3, 2024
  • 4 replies
  • 271 views

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

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

1var SpinJSON = org.camunda.spin.Spin.JSON;
2var jsonObject = SpinJSON("{}");
3var customerId = execution.getVariable("CustomerId");
4var eventType = execution.getVariable("ifsBpaProjectionOperation");
5jsonObject.prop("CustomerId", customerId);
6jsonObject.prop("event_type", eventType);
7execution.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 

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

 

View original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+9
  • Hero (Employee)
  • 136 replies
  • 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
  • Author
  • Ultimate Hero (Partner)
  • 895 replies
  • 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.

1Customer/Form (server error)
2Unexpected internal server error occurred.
3Error details: N/A
4
5Server stack trace error(s):
6 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]
7 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)
  • 136 replies
  • Answer
  • 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 

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

 


dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Author
  • Ultimate Hero (Partner)
  • 895 replies
  • 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