- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2014 05:20 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2014 06:05 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2014 05:34 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2014 05:35 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2014 05:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2014 05:37 AM
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