How To: How to Force String Comparison in BPM Script Action
Fact: Interstage BPM v11.2.1
Fact: Interstage BPM v11.3.0
Fact: Interstage BPM v11.3.1
Fact: Interstage BPM Studio
Fact: script action
Symptom: String comparison performed in script action fails logically
Fix:
To specify two string comparison in script action, refer to BPM documentation ecma-262.pdf.
See page 48 where it states:
String comparison can be forced by: "" + a == "" + b.
See the below sample script code listing:
// the highlight indicates that every string used for comparison contains prefex: "" +
// the code listing below is used in script action in Init Action Set
// it demonstrates how to check whether process initiator is admin user or not based on
// admin group specified in a UDA called AdminRole
var initiator = sec.getProcessInitiator();
Packages.java.lang.System.out.println("Process Initiator ====> " + initiator);
var adminGroupName = uda.get("AdminRole");
Packages.java.lang.System.out.println("Admin Group called ====> " + adminGroupName);
var adminArray = sec.getGroupMembers(adminGroupName);
var errMsg = null;
var isAdmin = null;
var bpmTrigger = "iflowtrigger"; // Process trigger in BPM is named as a fictitious user called "iflowtrigger"
for (i=0; adminArray != null && i < adminArray.length; i++ ) {
var adminUser = adminArray;
Packages.java.lang.System.out.println("#" + (i+1) + ": admin retrieved: " + adminUser + ", while initiator is " + initiator);
if ("" +initiator.toLowerCase() == "" +adminUser.toLowerCase() || "" +initiator.toLowerCase() == "" +bpmTrigger) {
// initiator is BPM admin
Packages.java.lang.System.out.println(initiator + " is admin user or iflowtrigger allowed to start the process.");
isAdmin = "yes";
uda.set("isAdmin","yes");
break;
}
} // end of for loop
if (isAdmin == null) {
// not admin, print out the debug statement to command line console.
Packages.java.lang.System.out.println(initiator + " is not allowed to start a process!");
uda.set("isAdmin","no");
//var errMsg = initiator + ", you are not a BPM admin and is not allowed to start a process!";
//throw errMsg;
}
// end of sample script code listing