getDisplayValue()

Joshuu
Kilo Sage

Hi All,

 

I have written below script for incident creation through inbound integration. And I am using "getDisplayValue()" to insert the actual Display name from source instance.

 

But it is not working. Please correct me if I am wrong with this approach. 

 

 CRinc.initialize();

                    CRinc.correlation_id= reqeustJSONParser.id.getDisplayValue();
                    CRinc.state = reqeustJSONParser.state.getDisplayValue();
                    CRinc.hold_reason = reqeustJSONParser.hold_reason.getDisplayValue();
                    CRinc.description = reqeustJSONParser.description.getDisplayValue();
                    CRinc.short_description = reqeustJSONParser.short_description.getDisplayValue();
                    CRinc.sys_class_name = reqeustJSONParser.ticket_type.getDisplayValue();
                    CRinc.category = reqeustJSONParser.category.getDisplayValue();
                    CRinc.impact = reqeustJSONParser.impact.getDisplayValue();
                    CRinc.urgency = reqeustJSONParser.urgency.getDisplayValue();
                    CRinc.priority = reqeustJSONParser.priority.getDisplayValue();
                    CRinc.subcategory = reqeustJSONParser.subcategory.getDisplayValue();
                    CRinc.cmdb_ci = reqeustJSONParser.cmdb_ci.getDisplayValue();
                    CRinc.contact_type = reqeustJSONParser.contact_type.getDisplayValue();
                    CRinc.assignment_group = reqeustJSONParser.assignment_group.getDisplayValue();
                    CRinc.close_notes = reqeustJSONParser.close_notes.getDisplayValue();
                    CRinc.close_code = reqeustJSONParser.close_code.getDisplayValue();
                    CRinc.work_notes = reqeustJSONParser.work_notes.getDisplayValue();
                    CRinc.comments = reqeustJSONParser.comments.getDisplayValue();

                    CRinc.insert();

 

Please help.

 

Thanks,

Priya.

7 REPLIES 7

Tony Chatfield1
Kilo Patron

Hi, getDisplayValue() is a method that returns the display value of a ServiceNow record/reference
//developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideRecordAPI#r_GlideRecord-getDisplayValue?navFilter=getdisplayValue

 

This method will not work in an integration payload, as the payload is a text field.

Perhaps you could share details of your payload in plain text format so that it can be reviewed, your configuration\requirements better understood and appropriate advise can be provided.


Anurag Tripathi
Mega Patron
Mega Patron

Hi,

getDisplayValue works on ServiceNow fields(reference, dropdown etc) where the field can one one visible value and one back end value. 

It cannot get the display value of any payload. You need to get the actual value passed in the payload and if needed you can convert it to string using the toString method.

-Anurag

-Anurag

Hi Anurag,

 

 

{ "number": "INC0010168", "ticket_type":"Incident", "state": "In Progress", "description":"test", "short_description": "test", "category": "Data", "subcategory": "Data Loss", "impact":"3 - Low", "urgency":"3 - Low", "contact_type":"Chat"}

 

 

Here, From source instance they are passing state value as New/In Progress/On Hold/Resolved. But in my instance the state is not getting updated.

 

If they change the state value in the JSON payload as 1,2,3 then it  is working.

 

Could you please help on this. What changes do I need to make in the script ? How can I convert it?

 

Please assist.

 

Thanks,

Priya.

 

 

You can use set display value fi that is what they are sending.

Sample below

var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = 'Network problem';
gr.category = 'software';
gr.caller_id.setDisplayValue('Joe Employee');
gr.insert();
-Anurag