The CreatorCon Call for Content is officially open! Get started here.

How to Script if State Changes in a Client Script

Su522
Kilo Sage

I have an onSubmit Client Script that I need to perform several validation checks on if the variables changed.

How can I script:

If State changes to In Progress

 

I'm unable to use an onChange Client Script for this scenerio.

Help is greatly appreciated!!

Thank you,

1 ACCEPTED SOLUTION

Dhananjay Pawar
Kilo Sage

Hi,

Write the onChange client script on State field and add below code.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
if(newValue=='2'){
    alert("state changed to in progress");// Add your validations here
}
   
}
 
Thanks,
Dhananjay.

View solution in original post

13 REPLIES 13

Dhananjay Pawar
Kilo Sage

Hi,

Write the onChange client script on State field and add below code.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
if(newValue=='2'){
    alert("state changed to in progress");// Add your validations here
}
   
}
 
Thanks,
Dhananjay.

@Dhananjay Pawar 

I need to keep the OnSubmit Client Script, as a UI Action is affecting this. 

Can you help?

Thank you

Hi,

Try below code in onSubmit client script.

 

function onSubmit() {
   var stateVal=g_form.getValue('state');
   if(stateVal==2){
    alert("state changed to in progress");// add your validations here
   }
   
}
 
Thanks,
Dhananjay.

@Dhananjay Pawar 

Thank you! But now it redirect to the last page I was on, instead of staying on the form.

How can I fix that- I need it to Save and Stay.

Here is the code now:

            function onConfirm() {
               var stateVal=g_form.getValue('state');
               g_form.setValue('state', 2);
               g_form.submit();
}
 
I have tried this bit it does not work:
window.open("incident.do?sys_id="+g_form.getUniqueValue(),"_self");
 
Can you help?
I very much appreciate you!