- 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 12:16 PM
Ben, looks like there is a business rule which is causing issues.
In Dev environment , please Inactivate the business rule named "Copy Security Risk ... " and run the code again.
The code is perfect to get the desired result.
Please advise.
Regards,
Abhinay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:18 PM
I have already tried deactivating that business rule and executed the script but still end user on catalog tasks is not updated. It's weird that this looks like a complex thing to achieve.
Thanks,
Ben.
- 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 12:37 PM
Hi Abhinay,
First of all I would like to thank you for continously working with me to achieve this. And executed the updated script with new line of code and looks like the end user field catalog task records got updated.
Can you also tell me why did it look this complex? because I initally thought it would be pretty straight forward code. but all this happend.
Thanks,
Ben.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 12:49 PM
Great Ben,
Thank you for confirming and congratulations that we achieved this.
Firstly, To be honest, the relational link between the tables and the dot walk get complicated many times.
Secondly, every environment is different and there are some business rules in your environment which restricts updating the OOTB tables.
Thus, the added line restricts all business rules to act when our code runs.
I will still say that this is a straightforward update, but due to the unknowns we took our time.
Please mark the above code as correct answer, as I believe it will help many.
Regards,
Abhinay