- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 04:44 AM
Hi All,
I'm Getting a Error 'org.mozilla.javascript.NativeArray@ede053' while running a before BR Script
(function executeRule(current, previous /*null when async*/ ) {
var grChildTask = new GlideRecord("u_model_resource");
grChildTask.addQuery("u_task_id", current. u_task_id); //check task no field name properly
grChildTask.query();
var TaskAssigneeList=[];
while (grChildTask.next()) {
TaskAssigneeList.push(grChildTask.getValue('u_assignee')); // check field backend name
}
current.u_all_assignee =TaskAssigneeList; // check field backend name
//current.update();
})(current, previous);
Also we have a Sc task and those Sc task have some child task with some task id and child table name is -u_model_resource and the parent table name is sc_task. The name of the child task number field is - u_task_id and the name of the assignee filed is - u_assignee and we want that every time a new task id is created (i.e child task is created) then the BR will run and the new assignee which is added to that list will be update to all the child task assignee list field which is - u_assignee_list.
Please help by providing the correct script to remove the error and to achieve this functionality.
Thanks & Regards,
Siddharth Gupta
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 05:32 AM
@Siddharth4 Try to change the code as below
(function executeRule(current, previous /*null when async*/ ) {
var grChildTask = new GlideRecord("u_model_resource");
grChildTask.addQuery("u_task_id", current.u_task_id); //there was a space between current. and u_task_id
grChildTask.query();
var TaskAssigneeList=[];
while (grChildTask.next()) {
TaskAssigneeList.push(grChildTask.getValue('u_assignee')); // check field backend name
}
current.u_all_assignee =TaskAssigneeList.toString(); //As the field is of string type and we are trying to store array in it
current.update();
})(current, previous);
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 06:01 AM
Hi Jaheerhattiwale,
Thanks for your reply, it's working fine now and i get the value in the all assignee list. Can you plz help me with the condition that I mention in the question that when we create a new child task in the parent sc task then each child task cointain a assignee value and i am trying to get a functionality that every time i create a child task and assignee that to someone then all the child task which was assigned to that sc task will update and the new assignee name get added to the field assignee list with coma separation
something like this so that every time a new child task get created then a new name get added to the all assignee list. The child table name is -u_model_resource and the parent table name is sc_task. The name of the child task number field is - u_task_id and the name of the assignee filed is - u_assignee and the field where i want to add all the assignee name using coma separation is - u_all_assignee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 06:10 AM
@Siddharth4 Write a business rule on child task table
Add you conditions in when to run section
Add below code
var scTask = new GlideRecord("sc_task");
if(scTask.get(current.parent.toString()){
scTask.u_all_assignee += current.getValue("u_assignee");
scTask.update();
}
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 06:35 AM
Hi Jaheerhattiwale,
Do I need to create a new BR or I can add the above script in the old BR in which i was working because the old BR is already created on the child table and it's working fine now.
Also I tried the above code in the current BR and it's not working.
Thanks & Regards,
Siddharth Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 07:24 AM
@Siddharth4 parent field is not there that's the issue. The code should be as follows
var scTask = new GlideRecord("sc_task");
if(scTask.get(current.u_task_id.toString()){
scTask.u_all_assignee += current.getValue("u_assignee");
scTask.update();
}
We should have this code in the child task as we dont need to query all the child tasks again as we did in first script.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 01:36 AM
Hi Jaheerhattiwale,
Thanks for your reply. I tried the above script but it's not working.
Thanks