- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi experts, I have a use case:
In my RITM Record, there are a couple of Catalog item variables which are mandatory. I want that the catalog task that is linked to the RITM should not be close complete/close incomplete/close skipped until and unless the mandatory RITM variables are filled.
Is there any way we can achieve this. Kindly help
Example below are the RITM Variables
Below is the catalog task where before the task moves to close complete, the RITM variables should be filled and only then the task can be made closed complete/incomplete/skipped
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @Deepika54
You can use either an onSubmit Client Script OR a Business Rule on the sc_task table
Option 1 ( this one we have used in our project): Create an OnSubmit client script on sc_task
- Navigate to System Definition > Client Scripts > click New.
- Table: sc_task
- Type: onSubmit
Sample code:
function onSubmit() {
var state = g_form.getValue('state');
// Assuming States: 3=Closed Complete, 4=Closed Incomplete, 7=Closed Skipped)
if (state == '3' || state == '4' || state == '7') {
var mandatoryVar = g_form.getValue('variables.VARIABLE_NAME'); // // Replace 'VARIABLE_NAME' with the actual variable name
if (mandatoryVar == '')
{
g_form.addErrorMessage('Please fill out the mandatory RITM variable before closing this task.');
return false;
}
}
}
Option 2: Create a BR
- Navigate to System Definition > Business Rules and click New.
- Table: sc_task
- Advanced: Check the box.
- When: before
- Insert / Update: Check both.
- Condition: State changes to Closed Complete OR State changes to Closed Incomplete OR State changes to Closed Skipped.
(function executeRule(current, previous /*null when async*/) {
var ritm = current.request_item.getRefRecord();
var manVariable = ritm.variables.VARIABLE_NAME; //Replace 'VARIABLE_NAME' with the actual name of your variable
if (manVariable.nil()) {
gs.addErrorMessage('You cannot close this task until the mandatory RITM variable is filled.');
current.setAbortAction(true);
}
})(current, previous);
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Deepika54
@you could control the logic with a before business rule to ensure the logic is fulfilled before save to the database.
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @Deepika54
You can use either an onSubmit Client Script OR a Business Rule on the sc_task table
Option 1 ( this one we have used in our project): Create an OnSubmit client script on sc_task
- Navigate to System Definition > Client Scripts > click New.
- Table: sc_task
- Type: onSubmit
Sample code:
function onSubmit() {
var state = g_form.getValue('state');
// Assuming States: 3=Closed Complete, 4=Closed Incomplete, 7=Closed Skipped)
if (state == '3' || state == '4' || state == '7') {
var mandatoryVar = g_form.getValue('variables.VARIABLE_NAME'); // // Replace 'VARIABLE_NAME' with the actual variable name
if (mandatoryVar == '')
{
g_form.addErrorMessage('Please fill out the mandatory RITM variable before closing this task.');
return false;
}
}
}
Option 2: Create a BR
- Navigate to System Definition > Business Rules and click New.
- Table: sc_task
- Advanced: Check the box.
- When: before
- Insert / Update: Check both.
- Condition: State changes to Closed Complete OR State changes to Closed Incomplete OR State changes to Closed Skipped.
(function executeRule(current, previous /*null when async*/) {
var ritm = current.request_item.getRefRecord();
var manVariable = ritm.variables.VARIABLE_NAME; //Replace 'VARIABLE_NAME' with the actual name of your variable
if (manVariable.nil()) {
gs.addErrorMessage('You cannot close this task until the mandatory RITM variable is filled.');
current.setAbortAction(true);
}
})(current, previous);
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti