- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
I have a requirement. In the first task there is a variable 'ticket_number' and in the second task the variable is 'u_ticket_number'.
Once the first task is closed with 'ticket_number' , I want to populate the same value in 'u_ticket_number' variable.
I have written a BR with before/update and below script:
Conditions: Item is catalog item name & Short description is second task' short description
Code:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
What's the requirement to replicate same information in other variable?
Why not show this variable on 2nd task as well for agent to work.
If you still want to proceed then see below points
I assume agent working on 1st task will fill that variable and close/update the sc_task
If yes then you should have after update on sc_task
Condition: current.request_item.item.name == 'Your Item Name'
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var ritm = current.request_item.getRefRecord();
ritm.variables.u_ticket_number = current.variables.ticket_number;
ritm.update();
})(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 || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @User205031 ,
You’re using 'ritmSysId' as a string instead of the variable ritmSysId.
your Business Rule should run on the first task when it’s closed — not on the second task.
Trigger:
Table: sc_task
When: after update
Condition: task is closed or whatever your “closed” state is.
Try the below script:
(function executeRule(current, previous /*null when async*/) {
var ritmSysId = current.request_item;
if (!ritmSysId) {
gs.info('No RITM linked to this task.');
return;
}
var ticketNum = current.variables.ticket_number;
if (!ticketNum) {
gs.info('No ticket_number value found on the closed task.');
return;
}
// Find the "second" task under same RITM
var grSecondTask = new GlideRecord('sc_task');
grSecondTask.addQuery('request_item', ritmSysId);
grSecondTask.addQuery('sys_id', '!=', current.sys_id);
grSecondTask.orderBy('sys_created_on');
grSecondTask.query();
if (grSecondTask.next()) {
// Assume this is the second task
grSecondTask.variables.u_ticket_number = ticketNum;
grSecondTask.update();
gs.info('Updated second task (' + grSecondTask.number + ') with u_ticket_number: ' + ticketNum);
} else {
gs.info('No other task found for this RITM.');
}
})(current, previous);
Mark this as helpful and correct, if this helps you.
Thanks,
Yaswanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
What's the requirement to replicate same information in other variable?
Why not show this variable on 2nd task as well for agent to work.
If you still want to proceed then see below points
I assume agent working on 1st task will fill that variable and close/update the sc_task
If yes then you should have after update on sc_task
Condition: current.request_item.item.name == 'Your Item Name'
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var ritm = current.request_item.getRefRecord();
ritm.variables.u_ticket_number = current.variables.ticket_number;
ritm.update();
})(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 || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Ankur Bawiskar ,
I added the first variable in the second task to populate the variable. It is displaying the value.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
hi @User205031
The Modern Method is using the Flow Designer, as it requires no scripting and anyone can look at the flow and see exactly what's happening. It's the standard, supported way to manage variable handoffs.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
