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

Tai Vu
Kilo Patron
Kilo Patron

Hi @Su522 

Can you help to provide more details on your business requirement?

 

Cheers,

Tai Vu

@Tai Vu 

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

If the State changes, I need to have another validation and display a pop up window. 

I just need help on "If the State changes to a certain state"

Can you help?

Thank you

@Tai Vu 

I tried the OnChange Client Script and it allows the pop up window to come up. But when I click "Yes" to confirm it takes me to a New Record and does not save the form changes on the record I was on.

I'm using GlideModel with this function.

            function onConfirm() {
                gFormAlreadySubmitted = true;
                gsftSubmit(undefined, undefined, g_form.getActionName());
Can you help?

Maddysunil
Kilo Sage

@Su522 

You can write onchange client script on state field, Below is the sample code:

 

function onChangeState(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    // Check if the new state is "In Progress"
    if (newValue === '2') { // Assuming '2' represents "In Progress"
        // Perform validation checks
            // Display an error message
            alert('Validation failed. Please check your data.');
            // Revert the value to the old value
            g_form.setValue('state', oldValue);
        }
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

@Maddysunil 

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

Can you help?

Thank you