Wait for CHG to be in Scheduled State and then update RITM variable

erin-marie
Tera Contributor

I have a workflow for a catalog item that we would like to hold until a CHG has reached the Scheduled State.  The form asks for the CHG number in a reference field (currently no conditions).  I have a checkbox on the Catalog Item (which will be hidden) that is called CHG Approved.  I have a Wait for Condition that waits for the box to be checked before continuing the workflow.  There is a Business Rule that is supposed to check the box but the BR isn't working.

 

BR

Table: change_request

When to Run: Before Update

Conditions: State changes to Scheduled

                     OR State is one of Scheduled, Implement, Review, Closed

Advanced Actions:

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

    // Add your code here

    var aws = new GlideRecord('sc_req_item');

    aws.addQuery('sys_id', aws.sc_aws_assetdecom_change_request);

    aws.query();
    while (aws.next()) {
        aws.sc_aws_assetdecom_chg_approved = true;
        aws.update();

    }
})(current, previous);
 
Any assistance is appreciated.
Erin
7 REPLIES 7

Brian Lancaster
Tera Sage

So If I understand correct your have a field on the RITM that is a reference to change.

If that is correct then this line of code aws.addQuery('sys_id', aws.sc_aws_assetdecom_change_request); is not correct. It should be aws.addQuery('[field on RITM]', current.sys_id);

 

I updated to reverse those two values and still no go.

CHG reference on RITM field name: sc_aws_assetdecom_change_request

Checkbox on RITM field name: sc_aws_assetdecom_chg_approved

 

 

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

    // Add your code here

    var aws = new GlideRecord('sc_req_item');

    aws.addQuery('sc_aws_assetdecom_change_request',current.sys_id);

    aws.query();
    while (aws.next()) {
        aws.sc_aws_assetdecom_chg_approved = true;

current.sys_id

        aws.update();

    }
})(current, previous);

Are you sure this sc_aws_assetdecom_change_request is the name of the field on the RITM that hold the change number? This is not an out of the box field and when you create a field it normally add u_ at the beginning of the name.

It is a variable on the catalog form not an actual field on the RITM table.  The person that trained me told me to add sc_ to the beginning of all variables.