- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2017 03:49 PM
Scripts are not triggering when making updates to records in List View.
There are scripts in place to autopopulate certain fields based on changes ot other fields. For example, on a HW Asset record, if State changes from On Order to In Stock, the Order Received date field should autopopulate with TODAY's date. This works if you edit the record and click Save or Update, but not if you update the State in the List View. This can result in lost or missing data. This is especially true in the above scenario where Deskside may be updating dozens or even a hundred HW Asset records to 'receive' them into inventory. It isn't feasible to update 100 records for the same update (State change) by editing each record in turn. With an average load time approaching 30 seconds between records you are introducing 50 minutes just to open and close records when the list view for same 100 could be updated in 5-7 minutes.
This is the onchange script I have and it works on single form edit. But I want this to trigger changes on list view also (bulk records)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue=='disposed'){
var SetDisposedDateObj = new GlideAjax('SetNowDate'); //Calls Script Includes: SetNowDate
SetDisposedDateObj.addParam('sysparm_name','now');
SetDisposedDateObj.getXMLWait();
var disposedDate = SetDisposedDateObj.getAnswer();
g_form.setValue('u_disposed_date', disposedDate);
}
else{
g_form.setValue('u_disposed_date', '');
}
}
What is the best way to script this?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2017 01:34 AM
As Surya has mentioned, onCellEdit is needed for list changes; onChange only works for form changes.
A AfterUpdate BR is safer, since that will trigger no matter which method is used to amend the data. It's also more efficient to use server-side methods over client-side methods.
By the way, is what you're trying to achieve possible with a UI Policy?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2017 03:53 PM
You can create business rule on table so bulk updates from list view can be triggered via business rule.
Business rule will trigger on both form view and list view.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2017 10:13 PM
Hi Rajinis,
You can write After Inset Update business rule.
and there you can mention in condition that state changes from order to stock
then set value date.
Try with this approach this will help for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2017 10:19 PM
Hello Rajini,
You can use "onCellEdit" type in client scripts in order to get work the scripts on list edit.
http://wiki.servicenow.com/index.php?title=Client_Scripts#onCellEdit.28.29_Scripts
Thanks,
Surya Amara
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2017 01:34 AM
As Surya has mentioned, onCellEdit is needed for list changes; onChange only works for form changes.
A AfterUpdate BR is safer, since that will trigger no matter which method is used to amend the data. It's also more efficient to use server-side methods over client-side methods.
By the way, is what you're trying to achieve possible with a UI Policy?