Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

endsWith() in business rule

sigmachiuta
Kilo Guru

Can i use current.name.endsWith() in a BR?   It doesnt seem to only be running on those conditions but is meeting all conditions.   As if the condition does not apply

function onBefore(current, previous) {

  //This function will be automatically called when this rule is processed.

  if (current.name.endsWith('foo') || current.name.endsWith('bar')){

var gr= new GlideRecord('table')   .................

}

1 ACCEPTED SOLUTION

i ended up moving the condition in the script up to the actual condition on the BR, and that worked


View solution in original post

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

use this



if(current.name.slice(-3)=='foo' || current.name.slice(-3)=='bar')


-Anurag

Does this still apply if I have a name thats longer than 3 char?


yea, any length



current.name.slice(-3) //this will extract last 3 characters of the string


-Anurag

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi,



endsWith will work in global scope but not in scoped applications.