Need to get the value

Abhishek_Thakur
Mega Sage

Hello Community,

 

I am getting the sys_id in the approval field, though it has referenced to sysapproval_approver table.

Could anybody help to get the value instead of sys_id.

Getting Sys_Id.png

 

Below is the script, I am using ; -

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

    // check if the state is being set to reffered back
    var count = current.u_rejected_count;
    if (current.state == 'rejected' && previous.state != 'rejected') {
        current.u_rejected_count = count + 1;
        var gr = new GlideRecord('u_m2m');
        gr.addQuery('u_approval', current.sys_id);
        gr.query();
        if (gr.next()) {
            gr.u_refer_back_code=current.u_refer_back_code;
            gr.u_reason_refer_back=current.u_refer_back_reason;
            gr.u_refer_back_count = current.u_rejected_count;
            gr.update();
        } else {
            var gr1 = new GlideRecord('u_m2m');
            gr1.initialize();
            gr1.u_approval = current.getDisplayValue('sys_id').toString();
            gr1.u_approval_for = current.document_id.getValue();
            gr1.u_refer_back_code=current.u_refer_back_code;
            gr1.u_reason_refer_back=current.u_refer_back_reason;
            gr1.u_refer_back_count = current.u_rejected_count;
            gr1.insert();
        }
    }
    current.update();

})(current, previous);
 
Please help here, if somebody knows about it.
12 REPLIES 12

Anurag Tripathi
Mega Patron
Mega Patron

Try this

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

    // check if the state is being set to reffered back
    var count = current.u_rejected_count;
    if (current.state == 'rejected' && previous.state != 'rejected') {
        current.u_rejected_count = count + 1;
        var gr = new GlideRecord('u_m2m');
        gr.addQuery('u_approval', current.sys_id);
        gr.query();
        if (gr.next()) {
            gr.u_refer_back_code=current.u_refer_back_code;
            gr.u_reason_refer_back=current.u_refer_back_reason;
            gr.u_refer_back_count = current.u_rejected_count;
            gr.update();
        } else {
            var gr1 = new GlideRecord('u_m2m');
            gr1.initialize();
            gr1.u_approval = current.getDisplayValue();
            gr1.u_approval_for = current.document_id.getValue();
            gr1.u_refer_back_code=current.u_refer_back_code;
            gr1.u_reason_refer_back=current.u_refer_back_reason;
            gr1.u_refer_back_count = current.u_rejected_count;
            gr1.insert();
        }
    }
    current.update();

})(current, previous);
-Anurag

Hello @Anurag Tripathi ,

 

Thanks for your prompt response, but now when I am using below code, I am not getting anything in approval field as attached in the screenshot. Also, could you please help to populate the document Id field as well coming from 'sysapproval_approver' table.

getting sys_id 2.png

What is your current here? what table is the BR running on?

-Anurag

It is running on sysapproval_approver table.