Run Clientscript one time only

Elias11
Giga Expert

Hi Experts

 

I am trying to create a client script that has to run only on time in every Record.

e.g. I have 2 fields, Field A and Field B , both are a reference type to the table users.

The Client script I have created is OnChange which if the Field A has changes or Loaded the Manager of the user of the field A will be set in the Field B.

 

So far so good. it works.,

 

Now as soon the manager in Field B is set for the first time I do not want anymore that the Field B changed.

the clientscript must not run till a new record is created.

 

Anyone an idea?

 

Thanks

Elias

1 ACCEPTED SOLUTION

Elias11
Giga Expert

I GOT IT



My Idea was correct but I wrote it wrong



I did ask if the value is Empty then run the script and if not return;



function onChange(control, oldValue, newValue, isLoading, isTemplate) {




var FieldB = g_form.getValue('u_fieldB');

if(FieldB== '') {
  var fieldA= g_form.getReference('u_fieldA');
  if (fieldA.manager != '')
  g_form.setValue('u_fieldB' , fieldA.manager);
} else {
  return;
}
}



Thank you


Elias


View solution in original post

8 REPLIES 8

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Elias,



You can use "isNewRecord"


Please refer section 13.6 in the below wiki link for further details


GlideForm (g form) - ServiceNow Wiki



Thanks,


Pradeep Sharma


Also you can refer the below link


» How to Use Script to Check for Modified or Changed Fields on a Record in Service-now



Mark your question as answered if this answers your question.



Thanks,


Pradeep Sharma


AnishSasidharan
Mega Expert

Once the Field B value has set and make it as readOnly. Don't give access to anyone to change the Field B as set at the first time.


Well Anish



the problem is that the client script that is running will change it again everytime the form will load or the Field A will change.



Thanks