- 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 11:06 AM
Please let me know
Now we can run a small 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:41 AM
Hello Ben,
var a = "u_end_user=NULL";
var b = "parent.ref_sc_req_item.requested_forISNOTEMPTY";
var count1 = 0;
var sc = new GlideRecord('sc_task');
sc.addEncodedQuery(a);
sc.addEncodedQuery(b);
sc.setLimit(10);
sc.query();
while(sc.next())
{
gs.print("Parent Sys_id: "+sc.parent.ref_sc_req_item.requested_for);
count1++;
}
gs.print(count1);
I hope this will work, only if requested_for field is not modified
Please share the output if possible
Regards,
Abhinay Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 11:49 AM
Abhinay,
Now I see 10 sys ids.
*** Script: Parent Sys_id: cba77605XXXXXXXXX2cc309e7c9619bc
*** Script: Parent Sys_id: eb883XXXXXXXXX407a2c9c94db9619c1
*** Script: Parent Sys_id: bba74605dbXXXXXXXXe7c9619bcd54f6
*** Script: Parent Sys_id: eXXXXXXXX4rf5640157f5a78dc9619d5
*** Script: Parent Sys_id: bba74605db7be70482ccXXXXXXXXf54f
*** Script: Parent Sys_id: eb883a9edbXXXXXXXXc94db9619c1d3f
*** Script: Parent Sys_id: bba74605dXXXXXXXX09e7c9619bc5rf6
*** Script: Parent Sys_id: eXXXXXXXXf56tt40157f5a78dc9619d5
*** Script: Parent Sys_id: fb8XXXXXXXXc9c94db961913c5rft6yh
*** Script: Parent Sys_id: ebe255fedb156b40157fXXXXXXX619d5
*** Script: 10
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 11:55 AM
Great News, now lets try to actually update 10 records
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();
}
Please let me know if atleast 10 records gets updated
Regards,
Abhinay Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:07 PM