hello,

I have a workflow that assign and remove multiple resources using a loop as described in some cool solution.

As there is multiple types of resources to choose, there are multiple pick lists in the form.

Then in order to get only one list of all resources to add and all resources to revoke , I use a mapping activity to compile all the resources selected (in different picklists) and all the resources already assigned
1) List of resources already assigned (got from the request form):
var array = new Packages.java.util.ArrayList();
array.addAll(flowdata.getObject('start/request_form/AssignedAccess'));
array.addAll(flowdata.getObject('start/request_form/AssignedTools'));
array.addAll(flowdata.getObject('start/request_form/AssignedEquipment'));
array.addAll(flowdata.getObject('start/request_form/AssignedRHApplications'));
array.addAll(flowdata.getObject('start/request_form/AssignedApplications'));
return array;
})();

This is mapped to flowdata.AllAssigned

2) List of resources selected in the different picklists (from request from):

var array = new Packages.java.util.ArrayList();
array.addAll(flowdata.getObject('start/request_form/AvailableAccess'));
array.addAll(flowdata.getObject('start/request_form/AvailableTools'));
array.addAll(flowdata.getObject('start/request_form/AvailableEquipment'));
array.addAll(flowdata.getObject('start/request_form/AvailableRHApplications'));
array.addAll(flowdata.getObject('start/request_form/AvailableApplications'));
return array;
})();

Is mapped to flowdata.AllSelected

3) Then I have an approval form, that get both lists in 2 mveditor fieds and I make the comparaison in the "onload" event of each field:
3-1)

/* To add resources in selection but not assigned */
var Assigned = form.getValues("AllAssigned")
var Selected = form.getValues("AllSelected")
var nToAdd = new Array();
var j=0;
for (var i=0; i < Selected.length; i++) {
if (Assigned.toString().indexOf( Selected[i] ) < 0 ) {
nToAdd[j]=Selected[i];
j+= 1;
}
}
field.setValues(nToAdd);

3-2)
/* To remove resources assigned but not in selection */
var Assigned = form.getValues("AllAssigned")
var Selected = form.getValues("AllSelected")
var nToRemove = new Array();
var j=0;
for (var i=0; i < Assigned.length; i++) {
if (Selected.toString().indexOf( Assigned[i] ) < 0 ) {
nToRemove[j]=Assigned[i];
j+= 1;
}
}
field.setValues(nToRemove)


This works fine, but now I want to remove the approval form and goes directly from the request form to the resource assignment and revokation loop in the workflow.

So, I remove the Approval activity I added a new mapping activity to make the comparaison beetween the assigned resources and selected resources:


The new mapping activity map the following:

var Assigned = Array(flowdata.getObject('AllAssigned'))
var Selected = Array(flowdata.getObject('AllSelected'))
var nToAdd = new Array();
var j=0;
for (var i=0; i < Selected.length; i++) {
if (Assigned.toString().indexOf( Selected[i] ) < 0 ) {
nToAdd[j]=Selected[i];
j+= 1;
}
}
nToAdd

To flowdata.AllToAdd

And this:

var Assigned = Array(flowdata.getObject('AllAssigned'))
var Selected = Array(flowdata.getObject('AllSelected'))
var nToRemove = new Array();
var j=0;
for (var i=0; i < Assigned.length; i++) {
if (Selected.toString().indexOf( Assigned[i] ) < 0 ) {
nToRemove[j]=Assigned[i];
j+= 1;
}
}
nToRemove


To flowdata.AllTo Remove.


There is something wrong here, as the result does not give the list of resources but the following in the trace file :

2017-02-23 11:10:46,992 [pool-3-thread-3] DEBUG com.novell.soa.script.impl.lang.es.impl.EcmaScript Engine- [RBPM] Evaluating the script : wi.XPath("flow-data/AllAssigned")
2017-02-23 11:10:46,992 [pool-3-thread-3] DEBUG com.novell.soa.script.impl.lang.es.impl.EcmaScript Engine- [RBPM] Evaluating the script : wi.XPath("flow-data/AllSelected")
2017-02-23 11:10:46,992 [pool-3-thread-3] DEBUG com.novell.soa.script.impl.lang.es.impl.EcmaScript Engine- [RBPM] Evaluating the script : flowdata.getObject('AllToAdd')
2017-02-23 11:10:46,992 [pool-3-thread-3] DEBUG com.novell.soa.script.impl.lang.es.impl.EcmaScript Engine- [RBPM] Evaluating the script : wi.XPath("flow-data/AllToAdd")
2017-02-23 11:10:46,992 [pool-3-thread-3] DEBUG com.novell.soa.script.impl.lang.es.impl.EcmaScript Engine- [RBPM] Evaluating the script : wi.createXPath("flow-data/AllToAdd[1]").setValue("com.novell.soa.script.mozilla.javascr ipt.NativeArray@ec0d644")
2017-02-23 11:10:46,992 [pool-3-thread-3] DEBUG com.novell.soa.script.impl.lang.es.impl.EcmaScript Engine- [RBPM] Evaluating the script : flowdata.getObject('AlltoRemove')
2017-02-23 11:10:46,992 [pool-3-thread-3] DEBUG com.novell.soa.script.impl.lang.es.impl.EcmaScript Engine- [RBPM] Evaluating the script : wi.XPath("flow-data/AlltoRemove")
2017-02-23 11:10:46,992 [pool-3-thread-3] DEBUG com.novell.soa.script.impl.lang.es.impl.EcmaScript Engine- [RBPM] Evaluating the script : wi.createXPath("flow-data/AlltoRemove[1]").setValue("com.novell.soa.script.mozilla.javascr ipt.NativeArray@2c33864e")


I guess I'm wrong manipulating the variables, but I was unsuccessful trying different options.

Thanks for your help.

Sylvain