Reference field is not displaying/getting populate on portal ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 03:59 AM
Hello Friends,
I am facing one issue in the reference field of the Portal (London).
I am fetching the values from the custom table and displaying it on the portal. There is one reference field referred from sys_user where I am passing the sys_id to that reference field. The field is not displaying the name/value but I can see the " i " icon (below snap). If I click on the icon, the specific user record is getting displayed on a separate window. It means assigning sys_id to that fields is working but the value is not displayed in the field.
Please help me to resolve this issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 04:10 AM
Based on this line,
{"order_date":"02/11/2019","test":"Test VK","name":"Snow team","customer_name":"4b065209dbe48b0cd26c715a8c961969"}
It looks like you need to take that customer ID (the value of customer_name) and get the record from the customer table to get the proper value from the field (typically using getDisplayValue().) This will require another GlideRecord query once you have parsed out your JSON.
Standard disclaimer: The following code is untested, requires review and potential modifications.
data.custName = '';
var custGr = new GlideRecord('YOURCUSTOMERTABLENAMEHERE');
if (custGr.get(cust_name)) {
data.custName = custGr.getDisplayValue();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 04:26 AM
Thanks for the reply. Your approach is correct, but my challenge is, what the sc item is there/may search is not fixed. Variables/fields may differ according to an item and among those variables, how we could know which field is reference field?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 04:41 AM
Reference fields always contain a sys_id. The format is 32 hex characters. A regular expression can verify when you've got one.
Something like this (untested code);
var patt = /^[0-9a-f]{32}$/;
if (cust_name.match(patt)) {
// Looks like a sys_id
}
UPDATE: I updated the RegEx pattern to be more accurate for sys_ids
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2019 08:25 AM
I've seen that behavior when the sys_id you use in setValue does not actually match a record in the sys_user table.
Validate that you're getting the correct sys_id (log it and manually try to bring up that record) and that you are passing it as a string (sometimes you need to add .toString() when you get the sys_id value from a object).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2019 02:14 AM
Thanks for the reply. I added .toString(), but no luck.