Business Rule - Creating New issue is not setting correct value on field

Aaron Duncan
Mega Sage

When we Finalize and Observation, we have a business rule that sets values on the newly created issue.

 

We know the overall business rule is setting values, but with the upgrade to Yokohama, we're seeing where the final value we're setting is not carrying over.

 

I confirmed the value in the script is correct before the update, but after the update, the value is changed.

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var new_issue = new GlideRecord('sn_grc_issue');
    new_issue.get(current.confirmed_issue.toString());
    if (new_issue) {
        new_issue.recommendation = current.explanation;
        new_issue.watch_list = current.watch_list;
        new_issue.due_date = current.issue_due_date;
        new_issue.u_impact = current.u_impact;
        new_issue.u_impacted_population = current.u_impacted_population;
        if (current.audit_task.sys_class_name == 'sn_audit_control_test') {
            new_issue.u_audit_control_testing = current.audit_task.toString();
        }
        if (current.u_type.getDisplayValue() == 'Compliance') {
            new_issue.classification = '1';
        } else if (current.u_type.getDisplayValue() == 'Audit') {
            new_issue.classification = '3';
        }

        new_issue.update();
    }

})(current, previous);

 

 

The only thing I found in the logs is this, but I can't figure out where it's referencing parent variable.

 

com.glide.script.RhinoEcmaError: "parent" is not defined.
   <refname> : Line(1) column(0)
==>   1:  parent.top_task
 Stack trace:
	at <refname>:1

 

 

1 ACCEPTED SOLUTION

@Aaron Duncan 

seems some other script is getting triggered when record is updated and that is causing this issue

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Aaron Duncan 

no where in your script you are using parent variable

Are you sure error is from this business rule only?

try this and check log

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var new_issue = new GlideRecord('sn_grc_issue');
    if (new_issue.get(current.confirmed_issue.toString())) {
		gs.info("Inside IF");
        new_issue.recommendation = current.explanation;
        new_issue.watch_list = current.watch_list;
        new_issue.due_date = current.issue_due_date;
        new_issue.u_impact = current.u_impact;
        new_issue.u_impacted_population = current.u_impacted_population;
        if (current.audit_task.sys_class_name == 'sn_audit_control_test') {
            new_issue.u_audit_control_testing = current.audit_task.toString();
        }
        if (current.u_type.getDisplayValue() == 'Compliance') {
            new_issue.classification = '1';
        } else if (current.u_type.getDisplayValue() == 'Audit') {
            new_issue.classification = '3';
        }
        new_issue.update();
    }

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I added a couple of outputs to see the value.

 

        gs.info("Inside IF");
        new_issue.recommendation = current.explanation;
        new_issue.watch_list = current.watch_list;
        new_issue.due_date = current.issue_due_date;
        new_issue.u_impact = current.u_impact;
        new_issue.u_impacted_population = current.u_impacted_population;
        if (current.audit_task.sys_class_name == 'sn_audit_control_test') {
            new_issue.u_audit_control_testing = current.audit_task.toString();
        }
        if (current.u_type.getDisplayValue() == 'Compliance') {
            new_issue.classification = '1';
        } else if (current.u_type.getDisplayValue() == 'Audit') {
            new_issue.classification = '3';
        }
        gs.info('Before Update is run: ' + new_issue.classification);
        new_issue.update();
        gs.info('After Update is run: ' + new_issue.classification);
    }

 

Here's the output.

 

*** Script: Inside IF
*** Script: Before Update is run: 1
Script execution error: Script Identifier: unknown, Error Description: "parent" is not defined., Script ES Level: 180
Evaluator: com.glide.script.RhinoEcmaError: "parent" is not defined.
   script : Line(1) column(0)
==>   1:  parent.top_task
 Stack trace:
	at <refname>:1
	at null.null.script:24

*** Script: After Update is run: 3

 

I suspect the error is based on the update method, and you can see how the value changes just before and after the update. Any thoughts on this?

@Aaron Duncan 

seems some other script is getting triggered when record is updated and that is causing this issue

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader