Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to fetch latest approved case record into reference field?

Deepika61
Tera Contributor

Hi All,

Actually we have two case tables (plan and build), on the plan case form , we have reference field called "trigger case" which is refers to Build case table, so now in that reference field I need to set the latest approved build case record , on the build case we have field case status in that we have choices, in that we have "Approved", based on this field , i need to get that lates approved record?

 

I have written a after BR like below

Table Plan

After insert/Update

 var es= new GlideRecord('sn_customerservice_build_case');
    es.addEncodedQuery('state=6');
    es.orderByDesc('sys_updated_on');
    es.setLimit(1);
    es.query();
    if (es.next()) {
      
        current.u_trigger_case_no = es.number;
        current.update();

    }
 
But returns Empty record on that field
 

Please help me to achieve this

Thanks

Deepika

2 REPLIES 2

Deepika61
Tera Contributor

Hi All,

 

Please help me to resolve this

 

Thanks

Deepika

amarbro
Tera Contributor

Hello @Deepika61 ,

Try this 

var es = new GlideRecord('sn_customerservice_build_case');
es.addQuery('state', 6); // replace 6 with actual integer value for 'Approved'
es.orderByDesc('sys_updated_on');
es.setLimit(1);
es.query();

if (es.next()) {
    current.u_trigger_case_no = es.sys_id; // assuming u_trigger_case_no is a reference field, you need to set it to sys_id
    current.update();
}

I think you need to map the sys_id.

 

Thanks

Amarjeet Pal