- 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 07:36 AM
BEN,
CAN YOU POST YOUR SCRIPT HERE PLEASE ? LETS DEBUG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 07:40 AM
Mohith,
I used the script you provided.
var sc = new GlideRecord('sc_task');
sc.addQuery('u_end_user','!=','');
sc.query();
while(sc.next())
{
sc.u_end_user =sc.request_item.request.requested_for;
sc.update();
}
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 07:54 AM
is the RITM being stored on request item field ?for all the tasks?
also try putting logs and check
var sc = new GlideRecord('sc_task');
sc.addQuery('u_end_user','!=','');
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();
}
Can you try with this script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 07:56 AM
Yes, we use request_item.requested_for on ScTasks.
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 07:58 AM
var sc = new GlideRecord('sc_task');
sc.addQuery('u_end_user','!=','');
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();
}
can you try this and check for logs if its going inside the loop