Document_id is being set as blank when trying to create approval record via BR

Community Alums
Not applicable

Hi Team,

 

I am trying to create approval record via Before Update Business rule as below . The record is getting created buts its creating Approving i.e Document_id as blank or empty even though I am passing the correct record or sys_id which is the current form on which the BR is written.

Below is the BR:

var users = current.users.split(',');

        for (var i = 0; i < users.length; i++) {

            var app = new GlideRecord('sysapproval_approver');
            app.initialize();
            app.state = 'requested';
            app.approver = users[i];
            app.document_id = current.sys_id;
            app.insert();


        }
 
Please help in resolving this?
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

try this -> you need to set the source_table as well

var users = current.users.split(',');

for (var i = 0; i < users.length; i++) {

    var app = new GlideRecord('sysapproval_approver');
    app.initialize();
    app.state = 'requested';
    app.approver = users[i];
    app.source_table = current.getTableName(); // or give hard-coded table name on which BR is present
    app.document_id = current.sys_id;
    app.insert();


}
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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

try this -> you need to set the source_table as well

var users = current.users.split(',');

for (var i = 0; i < users.length; i++) {

    var app = new GlideRecord('sysapproval_approver');
    app.initialize();
    app.state = 'requested';
    app.approver = users[i];
    app.source_table = current.getTableName(); // or give hard-coded table name on which BR is present
    app.document_id = current.sys_id;
    app.insert();


}
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