- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2024 09:11 AM
Hi all,
I have two tables one is Sc_req_item
Second table is Sc_task
In this two tables i have a state field.
In the sc_task table the State field of is Awaiting and watch list field is User Feedback .
After that if the comment is posted in Additional comment field in sc_req_item table .
The state field in Both the tables need to be changed to In Progress state.
solution script will be more helpful thanks in Advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 07:09 AM - edited 04-22-2024 10:31 AM
@Community Alums
why not review OOB business rules that perform similar actions. One is named "Update Idea State on Close" defined on the 'dmn_demand' table.
However, it is unclear on which table to define the BR on based on your requirements:
"In the sc_task table the State field of is Awaiting and watch list field is User Feedback .
After that if the comment is posted in Additional comment field in sc_req_item table ."
Seems you need to define the BR on the 'sc_req_item' table, when the 'comments' field changes, the script would then check the 'sc_task' records that reference the same 'sc_request' to see what is in the state and watch list fields. And then perform the desired updates to each record. Too complicated for quickly proposing script logic for a BR approach.
I took a stab at a BR defined on the sc_req_item table, for when "Additional Comments" changes, see below:
script follows:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// check sc_task for records for the sc_request here
var scTask = new GlideRecord('sc_task');
scTask.addQuery('request', current.request);
scTask.addQuery('state', 'awaiting'); // there no choice value for state=awaiting in my instance. so that needs to change to the value for 'awaiting'
scTask.addQuery('watch_list', 'CONTAINS', gs.getUserID()); // watch_list is a list of users, looking for current user
var updTaskFlag = false;
scTask.query();
while (scTask.next()) {
updTaskFlag = true;
scTask.state = 'progress'; // there is no choice value for state=progress on either sc_task or sc_req_time, use the value for those in your instance.
gs.addInfoMessage('Updating state on sc_task: ' + scTask.number);
scTask.update();
}
if (updTaskFlag){
current.state = 'progress'; // there is no choice value for state=progress on either sc_task or sc_req_time, use the value for those in your instance.
gs.addInfoMessage('Updating state on sc_req_itme: ' + current.number);
}
})(current, previous);
You need to use the Choice values defined in your instance to state = "Awaiting" and "pending' on your two tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2024 11:11 PM
@Community Alums
It would be nice if you could share what script did you start with along with screenshots.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2024 11:36 PM
I Didn't start with script.
I am asking for Script. so , i could make the changes.
if you want further information i can share.
Thanks & Regards,
Mohammed Sazid.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 07:09 AM - edited 04-22-2024 10:31 AM
@Community Alums
why not review OOB business rules that perform similar actions. One is named "Update Idea State on Close" defined on the 'dmn_demand' table.
However, it is unclear on which table to define the BR on based on your requirements:
"In the sc_task table the State field of is Awaiting and watch list field is User Feedback .
After that if the comment is posted in Additional comment field in sc_req_item table ."
Seems you need to define the BR on the 'sc_req_item' table, when the 'comments' field changes, the script would then check the 'sc_task' records that reference the same 'sc_request' to see what is in the state and watch list fields. And then perform the desired updates to each record. Too complicated for quickly proposing script logic for a BR approach.
I took a stab at a BR defined on the sc_req_item table, for when "Additional Comments" changes, see below:
script follows:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// check sc_task for records for the sc_request here
var scTask = new GlideRecord('sc_task');
scTask.addQuery('request', current.request);
scTask.addQuery('state', 'awaiting'); // there no choice value for state=awaiting in my instance. so that needs to change to the value for 'awaiting'
scTask.addQuery('watch_list', 'CONTAINS', gs.getUserID()); // watch_list is a list of users, looking for current user
var updTaskFlag = false;
scTask.query();
while (scTask.next()) {
updTaskFlag = true;
scTask.state = 'progress'; // there is no choice value for state=progress on either sc_task or sc_req_time, use the value for those in your instance.
gs.addInfoMessage('Updating state on sc_task: ' + scTask.number);
scTask.update();
}
if (updTaskFlag){
current.state = 'progress'; // there is no choice value for state=progress on either sc_task or sc_req_time, use the value for those in your instance.
gs.addInfoMessage('Updating state on sc_req_itme: ' + current.number);
}
})(current, previous);
You need to use the Choice values defined in your instance to state = "Awaiting" and "pending' on your two tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 03:32 AM
thankx a lot @Bert_c1