Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

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

Hi,



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