- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 03:08 AM
Hi All,
I want to make assigned to mandatory when state changes to Closed Complete in List view.
I have created a client script onCellEdit. Field- state
I added the logic if State is Closed Complete and Assigned to or Assignment group is empty then it will not allow to save.
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
var ag = g_form.getValue('assignment_group');
var as = g_form.getValue('assigned_to');
if (newValue == 7 && ((ag == '') || (as == '')) {
alert("Assignment group or Assigned to should not be empty")
saveAndClose = false;
} else {
saveAndClose = true;
}
callback(saveAndClose);
}
It is not working. Please help in this.
Thanks,
Samiksha
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 03:41 AM
Hi Samiksha,
just for my understanding: do you want to have Assigned To mandatory so that it will block the row update in list view, when state changes to "Closed Complete"? In this case, you could consider a data policy. This should run on your task table for the condition that "State [is] Closed Complete". The data policy action would define "Assigned To" as mandatory[=]true.
If you use the data policy as UI policy as well, you with the same step apply your requirement to the form view.
Or did I get your request wrong?
Best regards
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 03:23 AM
onCell edit can only access value of the field on which onCell edit runs.
So g_form cannot be used there.
For this you need to use before update BR with similar conditions and abort the update
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ag = current.getValue('assignment_group');
var as = current.getValue('assigned_to');
if (current.state == 7 && ((ag == '') || (as == ''))) {
gs.addErrorMessage("Assignment group or Assigned to should not be empty");
current.setAbortAction(false);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 03:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 03:41 AM
It should work provided your BR triggers with correct condition
what's the BR trigger condition?
It should be state changes to closed complete
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 03:45 AM