Approver process on demands for approvers stakeholders

Rajeshshardul
Tera Contributor

Hi Everyone,

 

Configured BR's and Properties as per community suggestion.

 

But Facing the below issues,

 

1. Approvers are getting added twice.

2. Once Approvers approving the state of demand not changing into Approved.

3. When Refreshing window Same Approver ID adding again.

 

Business Rules:

BR Name - Demand Approval Request

When to Run - After with update and condition added as state = Qualified

Script:

(function executeRule(current, previous /*null when async*/ ) {
    var grStakeHolder = new GlideRecord('dmn_m2m_demand_stakeholder');
    grStakeHolder.addQuery('demand', current.sys_id);
    grStakeHolder.addQuery('approver', 'yes');
    grStakeHolder.query();
    while (grStakeHolder.next()) {
        var grApproval = new GlideRecord('sysapproval_approver');
        grApproval.initialize();
        grApproval.approver = grStakeHolder.stakeholder.user;
        grApproval.state = 'requested';
        grApproval.source_table = current.sys_class_name; // Not hard coded to support TeamSpaces
        grApproval.document_id = current.sys_id;
        grApproval.sysapproval = current.sys_id;
        grApproval.insert();
    }
})(current, previous);

Rajeshshardul_0-1769093666950.png

 

Rajeshshardul_1-1769093666940.png

 

 

BR Name: Demand Approved

When to Run: Before Update and condition is Approval changes to Approved.

Action did set as : State is Approved.

Rajeshshardul_2-1769093667172.png

 

 

Rajeshshardul_3-1769093667154.png

 

Demand 

  1. System Properties -> Approval Engines
  2. Did Update Demand Approval Engine to: Approval Rule

 

Rajeshshardul_4-1769093666876.png

 

 Issue Snapshots:

Initially it is adding id two times and once approved and then after screen refreshing adding id's again and again. 

Rajeshshardul_5-1769093666918.png

 

Rajeshshardul_6-1769093666942.png

 

State value is not changing

Rajeshshardul_7-1769093666864.png

 

Please help me on it.

2 REPLIES 2

Itallo Brandão
Giga Guru

Hi @Rajeshshardul ,

Unfortunately, the screenshots are too blurry to read.

Could you please re-upload them with higher resolution?

Also, if you can paste the Script code directly here as text, it would be much easier for us to help you debug the logic.

Best regards,
Brandão.

Hi @Itallo Brandão ,

Added code which i used and Snapshots readded.

Please help me out to fix the issue.

BR,

Rajesh.