Reference field is not displaying/getting populate on portal ?

Virendra K
Kilo Sage

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. 

find_real_file.png

 

 

 

10 REPLIES 10

Uncle Rob
Kilo Patron

Are you using g_form.setValue in a client script that has "All" for the UI Type?
If so, are you sending both field name and value in string?

g_form.setValue('fieldname', 'string');

No, I am not using g_form.

I am getting a string with the field name and value. Splitting the string and pushing it in the array. 

After comparing the fieldname and inserting the values.

Please refer below code I posted to Chuck Tomasi.

Chuck Tomasi
Tera Patron

Can you share code for the widget. I suspect there's a missing getDisplayValue() somewhere. You can't simply use 

data.name = userGr.name;

in service portal. You MUST use getValue() and getDisplayValue() to get the string values of those. Using the 'dot notation' returns an object - which often doesn't work.

Server Script ( where I am getting a string having field label and field value  from the custom table) 

This is the string I am getting, "{"order_date":"02/11/2019","test":"Test VK","name":"Snow team","customer_name":"4b065209dbe48b0cd26c715a8c961969"}) "

Below is the Server code,  

var sysid = $sp.getParameter('saved_template');
if(sysid){

var itemdtl;
var testURL;
data.MyURL='';
var mygr = new GlideRecord('u_u_portal_user_saved_templates');
mygr.addQuery('sys_id', sysid);
mygr.query();
if (mygr.next()){
itemdtl= mygr.getValue('u_item_details');

}
//gs.addInfoMessage('inner'+itemdtl);
var pairs = JSON.parse(itemdtl);


//gs.addInfoMessage("Pairs : " + pairs +"testurl :"+testURL);
Object.keys(pairs).forEach(function(key) {

if (testURL== undefined) {
testURL=key + '=' + pairs[key] ;
}
else{
testURL=testURL+ '&' + key + '=' + pairs[key];
}
// gs.addInfoMessage(testURL);


});
data.MyURL=testURL;
//gs.addInfoMessage(testURL);
}

============================= ========================================

 

Client Script (where I am splitting the string and inserting the values in the specific fields of the sc_cat_item table comparing with field label)

 

var fields= $scope.data.sc_cat_item._fields;
//var pairs = location.search.slice(1).split('&');

if (c.data.MyURL!= undefined){
var pairs = c.data.MyURL.split('&');

var result = {};
pairs.forEach(function(pair) {
pair = pair.split('=');
result[pair[0]] = decodeURIComponent(pair[1] || '');

});
console.log('result xx ',result)
for(var obj in fields) {
//console.log('Field name x : '+ fields[obj].label );
Object.keys(result).forEach(function(key) {
if(fields[obj].name == key) {
fields[obj].value = result[key];
}

});
}


}