Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Validate the State from Script Include (oob one)

Lucky1
Tera Guru

Hello All,

 

I want to validate the State value given in the JSON payload with the oob script include.

Scenario:

Third-party sends an JSON payload containing the state value of a Change request.

Now, before updating the change request with the 'State' value they sent. I need to validate the state transitions.

For that, there is an oob Script include,

ChangeRequestStateHandler.canMoveTo(toState) to validate if the given value is allowed.

Then if ok, I need to use ChangeRequestStateHandler.moveTo(toState) 

 

So, how can I use them?

I understand I need to pass the state value they sent, in the function parameter. But need a bit clear response from you all.

Note:

There is already a script-include, I have written to validate some other date fields. And I want to validate the State transitions as well here.

In my script include, I am using 'chg' to refer to change request that is present in the system.

And, u_state to use the state field value they sent.

 

 

Now, could someone please help me how to use it?

 

 

Regards,

Lucky

 

So, I was told to use changerequeststatehandler.

 

So, can sone

0 REPLIES 0