- 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-27-2022 11:28 AM
Hello Ben,
If the custom field is a Reference field of user's table, than you can use below code
var gr= new GlideRecord('sc_task');
gr.addNullQuery('custom_field_name');
gr.query();
while(gr.next()) {
gr.custom_field_name = gr.request_item.requested_for;
gr.update();
}
Else if it is a string field, use below
var gr= new GlideRecord('sc_task');
gr.addNullQuery('custom_field_name');
gr.query();
while(gr.next()) {
gr.custom_field_name = gr.request_item.requested_for.getDisplayValue();
gr.update();
}
Please let me know if this works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 06:27 AM
Hi ABhinay,
It's a reference field and tried your script it didn't work. any alternative?
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 09:03 AM
Hello Ben,
This should be an easy job.
But based on all your responses I can confirm that the various scripts provided to you are correct but there is some info missing from your end.
1) Where are you trying to run these scripts? eg. Bckgrnd script, client script, business rule etc
2) What role do you have? eg. admin, itil
3) What messages do you get when you run these script? Are there different messages for all the above scripts?
Please advise.
Regards,
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 10:13 AM
Hello Ben,
Please run below script in background and let me know what response do you get
var a = "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
Regards
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 10:31 AM
Abhinay,
I get the number that is total count of catalog tasks i.e. records with end user as empty in my instance.
Thanks,
Ben.