How to write OnCellEdit client script to restrict list view updating based on other field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2023 03:33 AM
Hello,
I need help with onCellEdit client script to restrict list view updating on a table based on other field value in lost view.
Requirement is, on Demand Table list View, if "portfolio" is selected as "IT" then user cannot select "Non Conversion" Type field option.
can anyone help on this.
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2023 07:35 AM
@Lakshmi laks Here is the approach from my side. Following is the function definition for onCellEdit client script.
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
callback(saveAndClose);
}
According to ServiceNow documentation
As we do not have access to the other fields of record currently being edited here, checking the value of other field appears a bit difficult here.
However, we do have a an array of sysIDs here, which can be used to check if the portfolio populated is IT or not.
In order to check this, you would need to perform this check via a Script Include method on the server side, this script include method will get a comma separated list of sysIDs from the client side. It will do GlideRecord query to get portfolio associated with all the SysIDs and will check if the portfolios are IT portfolio or not. On the basis of this check you can return true or false to the client script and if the portfolios are not IT portfolio then you can pass false in the callback function so that the changes are not saved on the record.
Do let me know if at any step you need any further assistance.