How to query a lookup label field value and find matching record?

robinsnow
Tera Contributor

Hi Heroes,

I am struggling to fetch a lookup select box field value. The variable is called "existing_pcc_code", with two lookup label fields "u_id" and "u_name".

I want to query the u_id and find the record that matches the u_id field on the table. Then I want to take the value from the u_project field and enter it into the task short description.

Task activity script in workflow:

if(current.variables.specify_type_of_request == 'modify_pcc_code'){
var gr = new GlideRecord('u_work_order');
gr.addQuery('u_id','CONTAINS', current.variables.existing_pcc_code.u_id);
if(gr.next()){


var proj = gr.u_project;
task.short_description = current.short_description + ". ** Project: " + proj;
    }
}

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

Hello,

The lookup select box variable can have multiple display labels but it can only have a single value at the backend which is the value of field selected in Lookup value. You need to set it as u_id and then try this script

if(current.variables.specify_type_of_request == 'modify_pcc_code'){
var gr = new GlideRecord('u_work_order');
gr.addQuery('u_id','CONTAINS', current.variables.existing_pcc_code);
if(gr.next()){
var proj = gr.u_project;
task.short_description = current.short_description + ". ** Project: " + proj;
    }
}

View solution in original post

1 REPLY 1

Alikutty A
Tera Sage

Hello,

The lookup select box variable can have multiple display labels but it can only have a single value at the backend which is the value of field selected in Lookup value. You need to set it as u_id and then try this script

if(current.variables.specify_type_of_request == 'modify_pcc_code'){
var gr = new GlideRecord('u_work_order');
gr.addQuery('u_id','CONTAINS', current.variables.existing_pcc_code);
if(gr.next()){
var proj = gr.u_project;
task.short_description = current.short_description + ". ** Project: " + proj;
    }
}