How to script If a value has changed?

Su522
Kilo Sage

I need an onSubmit Client Script but I also need it to check if the 'State' field value has changed.

How can this be scripted?

 

Thank you,
Susan

8 REPLIES 8

James Chun
Kilo Patron

Hi @Su522,

 

Can you elaborate on what you are trying to do?

 

Cheers

@James Chun 

Several validation checks with a pop up window for confirmation.

Need to use an OnSubmit Client Script becuase other UI actions are being performed, which are related.

In the onSubmit Client script - also need to do a validation on several values. Including to see if the State value has changed. 

@Su522 thanks for the info.

 

You can save the initial value of the 'state' with a g_scratchpad variable via a Display Business Rule.

Then within the onSubmit client script, you can do something like:

 

 

if(g_scratchpad.initialState == g_form.getValue('state'))

 

 

For how to set up a g_scratchpad variable, refer to this article - https://www.servicenow.com/community/developer-forum/g-scratchpad-functionality-and-its-use/m-p/1772...

 

OR instead of a client script, you can use a Business Rule to compare the previous and the new value of the state.

 

Hope it helps, thanks

@James Chun 

Thank you. I'll might try the scratchpad but I think I got it to work like this:

var stateVal = g_form.getValue('state');
var stateValue = g_form.getControl('state');
function onSubmit() {
if(stateValue.changed){
    g_form.addInfoMessage('It works!');

 

I dont think I can use a Before Update BR for this purpose bc I need a Pop Up window to confirm- Yes (continue processing) or Cancel. I'm using a GlideModal. The GlideModal is for client side... Thoughts?