When working with Workflows you might encounter errors indicating SPIN/DOM-XML. These errors can be random but when occurred once can occur repeatedly.
The error is 'Cannot serialize object in variable 'var' : SPIN/DOM-XML-01030 Cannot create context'. It is visible in troubleshoot mode as below.
ENVIRONMENT: IFS Cloud
AUDIENCE: ALL
RESOLUTION/ANSWER:
When this error is encountered at the point of using an array in a script task, following workaround can be used.
Instead of an array use the java ArrayLIst implementation in the script task.
For example, the error seen in the image can be overcome by replacing the script with the following.
var c = new java.util.ArrayList();
c.add(‘x’);
execution.setVariable("abc",c);
CAUSE: N/A
ADDITIONAL INFORMATION: N/A
SCRIPTS/LOGS: N/A
SOURCE: CS0206101
VERIFIED: NO
Page 1 / 1
Here is some example code illustrating use of ArrayList and HashMap for BPA workflow.
var ArrayList = Java.type('java.util.ArrayList'); var HoursArrayList = new ArrayList(); var HashMap = Java.type('java.util.HashMap');
// create entries
var map1 = new HashMap(); map1.put('ResourceId', 'PDREAD'); map1.put('Hours', 20); HoursArrayList.add(map1); var map1 = new HashMap(); map1.put('ResourceId', 'JJONES'); map1.put('Hours', 5); HoursArrayList.add(map1); var map1 = new HashMap(); map1.put('ResourceId', 'QWARK'); map1.put('Hours', 14); HoursArrayList.add(map1); var fOutput = 0;
// Get a value from the list
var searchName = 'JJONES'; for (j=0; j<HoursArrayList.size(); j++) { if (HoursArrayList.get(j).containsValue(searchName )) { fOutput = HoursArrayList.get(j).Hours; } }
Without the HashMap class, I would get a serialization error about 7-8 out of 10 executions. I’ve now ran the same workflow over 25 times with no error, so I believe this method fixes the intermittent serialization issue when dealing with objects.
Hi @Lahirumala de Mel@kamnlk,
Is there a workaround for storing an object in a process variable? I am experiencing the same issue, but I am not storying an array/ArrayList, I am trying to store an object. I tried storing the object as the 0th index of an ArrayList, but that also fails with a different serialization error message. Note the items collection in the below request is stored as an ArrayList.
When Serialization Doesn’t Fail:
When Serialization Fails:
Trying to store object as 0th element of ArrayList:
.map() is a ES6 syntax in javascript and that is currently not supported form of syntax in workflow
but you should be able to do the same thing using it in the following way
var orderNos = Array.prototype.map.call(CustomerOrderSet_Set, function(order) { return order.OrderNos; }).join(", ");
execution.setVariable("OrderNos",orderNos );
Can you give it a try and see
@Lahirumala de Mel
Is this the same for using javascript array functions like map?
We had an issue where we tried the following:
var orderNos = CustomerOrderSet_Set.map(function(order) { return order.OrderNos; }).join(', '); execution.setVariable("OrderNos",orderNos);
The workflow engine complains with a message “map is not a function”
This code works perfectly if you try it outside of IFS but when trying to use it on a collection which is a result of an API READ action it gives this error?
Can you confirm that we need to do the same type of fix when we want to apply some array functions on a collection coming from a READ action?