Why changesTo() function does't work?

jamesgo
Giga Contributor

I have a UI action to set change state to pending:


current.state = '-5';


then I use a business rule to check it:

if (current.state.changesTo('-5'))


why this doesn't work? the condition always return false...
11 REPLIES 11

Aaron40
Kilo Guru

Can you show the rest of your business rule? Is this an onbefore or an onafter business rule?

current.state.changesTo() is the correct syntax and should be working.


jamesgo
Giga Contributor

it is a before business rule:



function checkResetConditions() {
var doReset = false; //default to no reset
if (current.state.changesTo(-5)){
doReset = true; //enable the reset
}
return doReset;
}


Now even I put current.state.changesTo into the same UI aciton script, it still returns false...


current.state = -5;
current.update();
gs.log("state change: " + current.state.changesTo(-5));



Aaron


TJW2
Mega Guru

if (current.changesTo(-5)), no quotes.


CapaJC
ServiceNow Employee
ServiceNow Employee

Try breaking it up, and see if that gets around whatever the issue is. Try using:



current.state.changes() && current.state == -5