- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
What will i use to achieve this, is it Catalog client script or Catalog UI Policy?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
3 ways to handle
1) normal onChange client script on state field of sc_task and check if state is closed complete then make those mandatory
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == '3') {
if (g_form.getValue('variables.variableName1') == '')
g_form.setMandatory('variables.variableName1', true);
}
}
2) You need to ensure this is handled via the OOTB Close Task UI action as well as user can close the task from button as well
function closeTask() {
g_form.setValue('state', 3);
//Call the UI Action and skip the 'onclick' function
if (g_form.getValue('variables.variableName1') == '') {
g_form.setMandatory('variables.variableName1', true);
return;
}
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateTask();
function updateTask() {
current.state = 3;
current.update();
}
3) before update business rule on sc_task table
State Changes to Close Complete && current.request_item.cat_item.name == 'Your Item Name'
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if (current.variables.variableName == '') {
current.setAbortAction(true);
gs.addErrorMessage('Please add file before closing task');
}
})(current, previous);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Use a UI Policy at the Catalog item level and use the Applies to checkbox to make the policy run only on Catalog Task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @Johnson13 ,
Use UI policy (recommended)/ Client script on sc_task to make variable field mandatory when the catalog task STATE changes to 'Closed Complete' .
In my project we were facing some issue while tried using ui policy ( not able to recall exact reason), we have achieved it by client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
3 ways to handle
1) normal onChange client script on state field of sc_task and check if state is closed complete then make those mandatory
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == '3') {
if (g_form.getValue('variables.variableName1') == '')
g_form.setMandatory('variables.variableName1', true);
}
}
2) You need to ensure this is handled via the OOTB Close Task UI action as well as user can close the task from button as well
function closeTask() {
g_form.setValue('state', 3);
//Call the UI Action and skip the 'onclick' function
if (g_form.getValue('variables.variableName1') == '') {
g_form.setMandatory('variables.variableName1', true);
return;
}
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateTask();
function updateTask() {
current.state = 3;
current.update();
}
3) before update business rule on sc_task table
State Changes to Close Complete && current.request_item.cat_item.name == 'Your Item Name'
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
if (current.variables.variableName == '') {
current.setAbortAction(true);
gs.addErrorMessage('Please add file before closing task');
}
})(current, previous);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thank you Ankur, I used the option 1 to achieved my requirement.
