Automatically change demand state to Approved

Anthony Okoth
Tera Guru

SPM: Automatically changing Demand state to Approved

When demand reaches the state “Qualified”, approvals are generated for more than one stakeholders in a related list on the form. When all the stakeholders approve the approvals, the demand field “approval” gets the value “approved” and the demand automatically goes to the state “Approved”.

I would like to change this so that just a single approval is necessary for the state to change to “Approved”.

Does anyone know where I can change this? A business rule that checks for at least one approval doesn’t work because the “When” references the “approval” field mentioned above.

OOTB, which Script include, business rule, flow or workflow sets the Approval field on the demand form to "Approved" when all approving stakeholders approve the demand?

1 ACCEPTED SOLUTION

Anthony Okoth
Tera Guru

This is how i solved this issue:

Since the approvals are generated in the Approval [sysapproval_approver] table, i created an after business rule on this table. The business rule queries the approvals for the current demand and if there is at least one approval from a stakeholder, it changes the demand field Approval to Approved. See code below.

 

 

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

    var gr = new GlideRecord("dmn_demand");
    gr.addQuery("sys_id", current.sysapproval);
    gr.query();
    if (gr.next()) {
        gr.approval = 'approved';
        gr.state = '8';
        gr.update();
    }



})(current, previous);

 

 

View solution in original post

5 REPLIES 5

suryasr
Tera Contributor

Hi Anthony,

Did you find the script/ BR through which the Demand state goes to Approved after stakeholder approves?