I am getting org.mozilla.javascript.NativeArray@16e67ab error in work notes.

ritesh1
Tera Contributor

I have written a business rule to get all the affected CI of an incident. But when I am trying to update the work notes with an array of affected CI's, I am getting org.mozilla.javascript.NativeArray@16e67ab. 

Here is my code I'm using in Business Rule

(function executeRule(current, previous /*null when async*/ ) {
    //gs.addInfoMessage('Calling from BR');
    var myObj = new GlideRecord('task_ci');
    var arr = [];
    myObj.addQuery('task', current.sys_id);
    myObj.query();
    while (myObj.next()) {
        gs.addInfoMessage("Affected CI List: " + myObj.ci_item.getDisplayValue());

        arr.push((myObj.ci_item.getDisplayValue()).toString());

        current.update();
    }
    current.work_notes = "Test";
    current.work_notes = arr;
    current.update();

})(current, previous);

 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hi @ritesh 

Update your script as:

(function executeRule(current, previous /*null when async*/ ) {
    //gs.addInfoMessage('Calling from BR');
    var myObj = new GlideRecord('task_ci');
    var arr = [];
    myObj.addQuery('task', current.sys_id);
    myObj.query();
    while (myObj.next()) {
        gs.addInfoMessage("Affected CI List: " + myObj.ci_item.getDisplayValue());
        arr.push((myObj.ci_item.getDisplayValue());

    }
    current.work_notes = arr.toString();

})(current, previous);

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar

View solution in original post

5 REPLIES 5

Aman Kumar S
Kilo Patron

Never use current.update() in your BR

Remove current.update() and make your BR before update

Best Regards
Aman Kumar

Aman Kumar S
Kilo Patron

Hi @ritesh 

Update your script as:

(function executeRule(current, previous /*null when async*/ ) {
    //gs.addInfoMessage('Calling from BR');
    var myObj = new GlideRecord('task_ci');
    var arr = [];
    myObj.addQuery('task', current.sys_id);
    myObj.query();
    while (myObj.next()) {
        gs.addInfoMessage("Affected CI List: " + myObj.ci_item.getDisplayValue());
        arr.push((myObj.ci_item.getDisplayValue());

    }
    current.work_notes = arr.toString();

})(current, previous);

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar

Hi Aman, thanks for your help. Now I'm able to get the list of affected CI as an array in Incident's work notes. But the work notes is getting updated only when I modify anything in Incident, and then update the incident. 

I want the work notes to be updated the moment I save the incident.

Can you help me in this?

When is your BR running?

Mark Insert and Update checkbox in When to run section in the business rule

Best Regards
Aman Kumar