Client Script updating values onLoad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 06:26 AM
ClientScript is working but when reloading the form it will set to the original value and overwrite if changed after reloading. For Instance, Location is set by the Users data but if Location is updated and Request is saved, upon opening the Request again the Location will be set back to the User table value. Is there a way to ensure this doesn't happen, maybe like on save or submit then disregard the Client Script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 06:29 AM
Could you post your client script code? You may want to add and check and not change the field if it's already populated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 07:38 AM
function onChange(control, oldValue, newValue, isLoading) {
var id = g_form.getValue('u_recipient');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',id);
user.query();
if ( user.next() ) {
g_form.setValue('location', user.location);
}
}
Just very simple, very straightforward.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 08:25 AM
function onChange(control, oldValue, newValue, isLoading) {
if(!isLoading){
var id = g_form.getValue('u_recipient');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',id);
user.query();
if ( user.next() ) {
g_form.setValue('location', user.location);
}
}
}
Adding a !isLoading before should prevent from running on load (if thats what you are looking for..).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2015 06:45 AM
that is because you have an onLoad script running. So everytime it runs it will set the value to the script.
As Brad stated you need to update your script
if(fieldname == "") {
run your script here
}
That way if it's not blank, it wont run.