Getting a Error 'org.mozilla.javascript.NativeArray@ede053' while running a before BR

Siddharth4
Tera Contributor

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

 

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage
Mega Sage

@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.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

10 REPLIES 10

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 

Siddharth4_3-1670594471011.png

 

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

 

Siddharth4_2-1670594446375.png

 

@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.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

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

@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.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi Jaheerhattiwale,

 

Thanks for your reply. I tried the above script but it's not working.

 

Thanks