- 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 04:50 AM
Try below:
(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.toString(); // check field backend name //current.update();
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 05:06 AM
Hi Raghav,
Thanks for your reply. I try your code but it's not working. The all assignee list is become empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 05:33 AM - edited 12-09-2022 06:03 AM
why is curent.update(); commented from your code? is it a before BR?
Also I have added one info message, check if that works and give you 1st value in array.
(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
}
gs.addInfoMessage(TaskAssigneeList[0]);
current.u_all_assignee =TaskAssigneeList.toString(); // check field backend name
current.update();
})(current, previous);
Raghav
MVP 2023
- 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