- 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 10:46 AM
Great, thank you for sharing. From this we can confirm that the query is working.
Now we can run a small update test
var a = "u_end_user=NULL";
var count1 = 0;
var sc = new GlideRecord('sc_task');
sc.addEncodedQuery(a);
sc.setLimit(10);
sc.query();
while(sc.next())
{
gs.print("Parent Sys_id: "sc.parent.requested_for);
count1++;
}
gs.print(count1);
Are you able to see 10 sys_ids?
Regards
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 10:46 AM
Great, thank you for sharing. From this we can confirm that the query is working.
Now we can run a small update test
var a = "u_end_user=NULL";
var count1 = 0;
var sc = new GlideRecord('sc_task');
sc.addEncodedQuery(a);
sc.setLimit(10);
sc.query();
while(sc.next())
{
gs.print("Parent Sys_id: "+sc.parent.requested_for);
count1++;
}
gs.print(count1);
Are you able to see 10 sys_ids?
Regards
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 11:07 AM
No, I see count as 10 but sys ids as empty like below.
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: Parent Sys_id:
*** Script: 10
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 10:19 AM
Hi Abhinay,
I am running in background script and I have admin access. And, for most of the suggested scripts the transaction is taking too long to execute but catalog task records are not being updated.
The below script executes quickly but records are not being updated.
updatetasks();
function updatetasks()
{
var sc = new GlideRecord('sc_task');
while(sc.next())
{
sc.u_end_user =sc.getValue('request_item.requested_for');
sc.update();
}
}
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 10:25 AM
Thank you for sharing.
Now, please run below script in background and let me know what response do you get
var a = "parent.numberSTARTSWITHRITM^u_end_user=NULL";
var count1 = 0;
var sc = new GlideRecord('sc_task');
sc.addEncodedQuery(a);
sc.query();
while(sc.next())
{
count1++;
}
gs.print(count1);
Please advise