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

what type is field  u_approval on M2M?

Approval should be coming with the display value of the task by this.

Can you add some logs to print 

current.sysapproval.getDisplayValue();
-Anurag

It is reference field, which is referencing to the sysapproval_approver table.

Below is the attached screenshot.

Approval Value.png

How should I proceed?

if you are truing to add a display value, you need to do that in a string field. 

The document id is the display value of the approval table.

So I would say just use the below 

   gr1.u_approval = current.sys_id;

-Anurag