- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 09:22 AM
Hi All,
Can someone please help me on below requirement.
In Assess state changer manager have access to create a task manually, if the task is not created in the assess if i changed the state without creating a manual task it will throw an error unable to submit the form.
Please help me on this requirement
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 10:49 AM
Hello @nikhitha24 ,
To achieve this requirement in ServiceNow, you can use a Business Rule.
Create a new Business Rule that triggers when an Incident record is being saved and the state is changed to 'Authorise'. In the script of the Business Rule, you can check if a related Task record exists for that Incident.
If not, you can cancel the save operation and display the error message.
Here's a general outline of the steps:
Go to "Business Rules" in the ServiceNow navigation menu.
Create a new Business Rule.
Set the table to "Incident".
Set the "When to run" condition to execute the rule when the incident state changes to 'Authorise'.
In the script section, check if a related Task record exists for the current Incident using GlideRecord queries.
If no related Task record is found, use current.setAbortAction(true) to cancel the save operation and display an error message using gs.addErrorMessage("You can't update the Incident because a task record is not created.").
Certainly! Here's an example of a GlideRecord script that you can use within your Business Rule to check if a related Task record exists for the current Incident:
(function executeRule(current, previous /*, ...otherParams*/) {
// Check if the incident state is changing to 'Authorise'
if (current.state == 'Authorise' && current.state.changes()) {
// Query the Task table for related tasks linked to the incident
var taskGr = new GlideRecord('task');
taskGr.addQuery('incident', current.sys_id); // Adjust the field name if needed
taskGr.query();
// If no related task record is found, cancel the save and display an error message
if (!taskGr.hasNext()) {
current.setAbortAction(true);
gs.addErrorMessage("You can't update the Incident because a task record is not created.");
}
}
})(current, previous);
In this script, replace 'incident' with the correct field name that establishes the relationship between the Incident and Task tables if it's different in your instance.(may be there is 'parent' field)
If I am able to resolve your query please mark this answer as accepted solution.
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 10:49 AM
Hello @nikhitha24 ,
To achieve this requirement in ServiceNow, you can use a Business Rule.
Create a new Business Rule that triggers when an Incident record is being saved and the state is changed to 'Authorise'. In the script of the Business Rule, you can check if a related Task record exists for that Incident.
If not, you can cancel the save operation and display the error message.
Here's a general outline of the steps:
Go to "Business Rules" in the ServiceNow navigation menu.
Create a new Business Rule.
Set the table to "Incident".
Set the "When to run" condition to execute the rule when the incident state changes to 'Authorise'.
In the script section, check if a related Task record exists for the current Incident using GlideRecord queries.
If no related Task record is found, use current.setAbortAction(true) to cancel the save operation and display an error message using gs.addErrorMessage("You can't update the Incident because a task record is not created.").
Certainly! Here's an example of a GlideRecord script that you can use within your Business Rule to check if a related Task record exists for the current Incident:
(function executeRule(current, previous /*, ...otherParams*/) {
// Check if the incident state is changing to 'Authorise'
if (current.state == 'Authorise' && current.state.changes()) {
// Query the Task table for related tasks linked to the incident
var taskGr = new GlideRecord('task');
taskGr.addQuery('incident', current.sys_id); // Adjust the field name if needed
taskGr.query();
// If no related task record is found, cancel the save and display an error message
if (!taskGr.hasNext()) {
current.setAbortAction(true);
gs.addErrorMessage("You can't update the Incident because a task record is not created.");
}
}
})(current, previous);
In this script, replace 'incident' with the correct field name that establishes the relationship between the Incident and Task tables if it's different in your instance.(may be there is 'parent' field)
If I am able to resolve your query please mark this answer as accepted solution.
Thank you,