Yo guys, I'm rewriting a condition script that we have which has been timing out regularly.
Currently, the condition script dynamically builds an array of users who have performed a particular transition in the workflow.
I'm looking to create a physical array on the item details page, that can be used as above (but moving the time required to build the arrays into an action script)
What I have in mind is two arrays, "to approve" and "has approved". The condition script then simply looks at the "to aprove" array, and allows multiple transitions to these users. When they perform a transition, I want the action script to remove their name from the first array, and move it to the second.
I have been trying to use Array.slice() for this purpose, however I keep getting errors in the script tool. "Cannot find function slice in object"
Here is my code:
var usr = Security.loadUser(userID); var usrName = usr.lastName+", "+usr.firstName; var toApprove = item.ORIGINAL_APPROVERS; var hasApproved = item.APPROVED_BY; for (var user in toApprove){ var toApproveMember = toApprove[user]; if (toApproveMember === usrName) { hasApproved.add(toApprove[user]); toApprove.remove(toApprove[user]); break; } } // println(typeof(toApprove)); // var ABCDEFG = toApprove.slice(user,1); // println(ABCDEFG);
Using .add and .remove has allowed me to move the names around the arrays, but the limitation here is that I can't read the length of "toApprove", to determine when there is only 1 approver remaining (who pushes down a different transition from the others).
Any Suggestions?
Cheers
Hi Martin and thanks for the super-quick response!
Both my' to..' and 'has..' fields are set as multi-select picklists (specifically, the built-in "Users, all" picklist). I'm wondering whether these field types act and look like array objects, but are in actual fact something else? This would explain why I can't get Array.splice() to work on them.
I'll suggest the groups idea to our PLM team, although as this is our supplier enquiry workspace nearly every employee will review a supplier quote at some point and so we need to retain the ability to select specific users per record.
Cheers
Cool, thanks Martin.
I can get around it other ways, for example I can compare the array length of the approved users to the original. It will mean the code has an extra line to compare the values, but I can't imagine it'll add any noticeable time on. I'll report back once I'm done,
Cheers
Hey Stuart,
Instead of:
// println(typeof(toApprove)); // var ABCDEFG = toApprove.slice(user,1); // println(ABCDEFG);
What about converting that object into an array with this, so you can use the Array methods?:
var convertedToApproveArr = Object.keys(toApprove).map(function (key) { return toApprove[key]; }); println(convertedToApproveArr); var ABCDEFG = arr.slice(user,1); println(ABCDEFG);
Let us know how it goes.
Cheers,
Giliar