- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 11:05 AM
Hello Guys,
For all existing catalog tasks, I want to copy "request_item.requested_for" field on RITM to "user" (custom) field on ScTasks. How can I achieve this? and How does the script look like?
We have few hundreds of catalog tasks, So, I wanted to do a bulk update using script.
Any help is appreciated.
Thanks,
Ben.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:27 PM
Hey Ben,
Just a quick check, in the list view of sc_task table, group by u_end_user field and confirm if all are under empty.
Also, added a new line to the code, please try
var a = "u_end_user=NULL";
var b = "parent.ref_sc_req_item.requested_forISNOTEMPTY";
var sc = new GlideRecord('sc_task');
sc.addEncodedQuery(a);
sc.addEncodedQuery(b);
sc.setLimit(10);
sc.query();
while(sc.next())
{
sc.u_end_user = sc.parent.ref_sc_req_item.requested_for;
sc.update();
sc.setWorkflow(false);
}
Regards,
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 09:39 AM
Hi Mohith,
Since I want to query u_end_user is empty, I have modified second line of your script. but, when I execute the transaction never ends.. like transaction running for more than 4000 seconds and I had to cancel it.
I execute the below script in background scripts.
var sc = new GlideRecord('sc_task');
sc.addEncodedQuery('u_end_userISEMPTY');
sc.query();
while(sc.next())
{
gs.info('found the tasks'+sc.request_item.request.requested_for);
sc.u_end_user =sc.request_item.request.requested_for.toString();
sc.update();
}
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:13 PM
Hey Ben,
i think there are many records in sc task table .
by any chance is it for a specific catalog item where all these tasks are tagged to if yes try below script
var sc = new GlideRecord('sc_task');
sc.addEncodedQuery('u_end_userISEMPTY');
sc.addQuery('request_item.item','<your catalog item sys_id>')
sc.query();
while(sc.next())
{
gs.info('found the tasks'+sc.request_item.request.requested_for);
sc.u_end_user =sc.request_item.request.requested_for.toString();
sc.update();
}
this add query that i have added in thrid line filters only for a specific catalog item .
Try using this it might filter un necessary tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:16 PM
I have around 7000 records. and No these records are not specific to one catalog item.
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:22 PM
then try this and see
var sc = new GlideRecord('sc_task');
sc.addEncodedQuery('u_end_userISEMPTY');
sc.query();
while(sc.next())
{
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id',cs.request_item);
gr.query();
if(gr.next())
{
sc.u_end_user =gr.request.requested_for.toString();
sc.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 07:51 AM
Hi Ben,
You can create a before update business rule on sc_task table. In the actions tab condition builder set the field values as requested for- same as- Requested item.requested for custom field. (This field will be available after you select show related fields)
Please mark this answer as correct/helpful if it has added value.