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.

getDisplayValue is failing on string field

kuttti
Kilo Guru

Hello Everyone,

 

is something wrong with my script :

 

var visa ;
var g = new GlideRecord('sn_hr_core_profile');
g.addQuery('number=HRP0153690');
g.query();
if (g.next){
visa = g.getDisplayValue('u_employment_status');
gs.print("Print Visa value "+ visa);
}

 

Struck with simple query. Any help please ?

 

 

1 ACCEPTED SOLUTION

Mike_R
Kilo Patron
Kilo Patron

String fields do not have display values. Use getValue instead

visa = g.getValue('u_employment_status');

 

also in line 5, you are missing ()

g.next()

View solution in original post

5 REPLIES 5

Mike_R
Kilo Patron
Kilo Patron

String fields do not have display values. Use getValue instead

visa = g.getValue('u_employment_status');

 

also in line 5, you are missing ()

g.next()

Sagar Pagar
Tera Patron

Hi @kuttti,

 

Try this updated scripts -

 

var g = new GlideRecord('sn_hr_core_profile');
g.addQuery('number=HRP0153690');
g.query();
if (g.next()){
visa = g.getValue('u_employment_status');
gs.print("Print Visa value: "+ visa);
}

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Nilesh Wahule
Kilo Sage

Hi @kuttti ,

 

The getDisplayValue Works on the Reference fields as that record table value is already set as true ( Display = True ). For getting string field data you can use simply getValue as shown below or direct field name as 
var visa= gr.u_employement_status

 

 

 

var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('number=HRP0153690');
gr.query();
if (gr.next()){
var visa = gr.getValue('u_employment_status');
gs.print("Print Visa value: "+ visa);
}

 

 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Let me know if any issues….

---

Nilesh Wahule

Roshan Tiwari
Tera Guru

 

var visa ;
var g = new GlideRecord('sn_hr_core_profile');
g.addQuery('number=HRP0153690');
g.query();
if (g.next()){
visa = g.getDisplayValue('u_employment_status');
gs.print("Print Visa value "+ visa.toString());
}