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

USe 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.sysapproval.getDisplayValue();
            gr1.u_approval_for = current.document_id.getDisplayValue();
            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 help, but still, it is not working.

Hi @Abhishek_Thakur 

 

Can you pls specify what do you want in u_approval field ( Approver name or Change Request number?)

Sanjana8_1-1720606538639.png

 

Hello @Sanjana8 ,

As per the attached screenshot, I have highlighted the value which I want to populate.

Approval table.png

 

Hi @Abhishek_Thakur 

 

Try Using current.document_id.getDisplayValue();

 

Thanks

Sanjana