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

@Maddysunil 

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?

Harish KM
Kilo Patron
Kilo Patron

Hi @Su522 in onsubmit client script you cannot check previous state value, the alternate is to use before update Business rule.

cond: state chagesTo WIP

script:

you can access variable values using

current.variables.variablename and then you can do your validation.

Regards
Harish

@Harish KM 

I dont think a Before Update BR will work in this use case- I need to use GlideModel for a pop up window... 

A UI Action that is needed triggers my OnSubmit Client Script. Once it triggers my CS pop ups a window asking if you want to continiue. But before it does- my validation checks in the CS run.

Can you help?

Thank you

Anubhav24
Mega Sage

Hi @Su522 ,

What happened when the UI Action operation is performed ?