(What is the) Best Way to Insert Records Into an Embedded List With onChange Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2018 03:46 PM
Good Day Everyone,
I have an Approvers table on a Change Request form as an embedded list. I have a requirement to dynamically change the approvers displayed in this embedded list whenever the value in a field called Affected CI (cmdb_ci) is changed (onChange client script):
He're what I would LIKE to be able to do:
1. onChange client script make ajax call to server script include passing Affected CI value (sys_id) to script include function.
2. Script include queries approver reference table containing records to be populated in approvers table and returns results xml.
3. (struggling here) - client script? inserts the data as rows on the embedded list just as if "Insert a new row..." was done by user and table end up looking like this:
4. User reviews data, adds, removes, or changes data in embedded list.
5. User clicks submit and workflow creates approval records on sysapproval_approvers table and away we go!
I'm struggling with step 3 - I don't know how to insert the data returned from the server into the embedded list without committing the new rows to the table.
I can have the script include insert the rows into the table before returning back to the client, but then I'm having problems getting the GlideList2 setFilterAndRefresh() method to work so that the embedded list will refresh to show the approvers for the newValue for Affected CI - so I'm stuck going with that as an alternate solution.
Can anyone help with a solution to either methods described above please?
Thanks in advance for any suggestions.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2018 03:54 PM
I didn't quite catch your problem, could you explain in details please? You don't want to enter the records in the script include because?
also, if the user is saving the record after changing the CI, you can just use a before update or an after update business rule for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2018 04:38 PM
The client has a specific requirement to have the approvers populate the embedded list before the Change Request is submitted. This affords the submitter an opportunity to make updates to the approvers before the Change Request is submitted.
Either solution is fine, but the challenge I have with having the script include insert the records is that I can't get the approvers list to refresh and show the inserted records in the embedded list afterwards. This seems like the easier solution to implement, if only I could get the embedded list to refresh and show the inserted rows - as it would allow the users to review and make changes before the Change Request is submitted.
I hope that add some clarity - please let me know if more info is needed. Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2018 04:52 PM
Unfortunately, related lists don't update unless the form reloads, instead of making the user save the form and having them reload, try refreshing the form using the on change client script.
There is an option called
location.reload();
OR
reloadWindow(window);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2018 05:05 PM
Also, I'd ideally save the form rather than refresh the form because we are changing a field value and simply refreshing the form without saving it will not the save the value that's been changed. So may be consider using this?
g_form.save();
or
gsftSubmit(gel('sysverb_update_and_stay'));