How to trigger changes when data updated on list view?

Community Alums
Not applicable

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?

1 ACCEPTED SOLUTION

Dave Smith1
ServiceNow Employee
ServiceNow Employee

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?


View solution in original post

8 REPLIES 8

Community Alums
Not applicable

Thank you all. Business Rule worked perfect.


lSurya 24
Giga Guru

Hello Rajini,



Let me know if that answered your question. If so, please mark the response as correct/helpful.



Thanks,


Surya Amara


Paramahanns
Tera Expert

Hi Rajinis,



Did you get requirement working. How did you manage the cell edit.



Regards


Param


Community Alums
Not applicable

Parama, I did an After Business rule.



find_real_file.png



find_real_file.png