How to pass column from a reference field in $sp.getRecordDisplayValues?

theBeastMaster
Mega Guru

How can we pass reference field columns to $sp.getRecordDisplayValues?

I tried with below code but doesn't work.

var obj = {};
var columnsToGet = 'number,agency.number,agency.name';
$sp.getRecordDisplayValues(obj, gliderecord, columnsToGet); 

where agency is a reference field. Number is populating since it is part of current table but other fields are not populating. Please advise.

1 ACCEPTED SOLUTION

Thanks for your support. But, I somehow made it work through the existing code itself.

 

Instead of item.agency.name,I used item["agency.name"]. My bad, we can not directly fetch values of keys with such names abc.xyz by simply dot-walking. Instead, we need to fetch the same by passing it as a key.

View solution in original post

5 REPLIES 5

Harsh Vardhan
Giga Patron

this way you wont get the value of reference field. 

 

try now. 

 

 

i am adding example here. 

 

Server side code:

 

var locSysId = "";
if (input.setLocation)
locSysId = input.setLocation;
else
locSysId = gs.getUser().getRecord().getValue('location');

var locGR = GlideRecord('cmn_location');
locGR.get(locSysId);
data.loc = {};

data.loc.parent = locGR.getDisplayValue('parent');

$sp.getRecordDisplayValues(data.loc, locGR, 'sys_id,name,street,city,state,zip');

 

 

html:

 

<div class="form-group">
<label class="col-sm-2 control-label">Country</label>
<div class="col-sm-10">
<input type="text" placeholder="{{data.loc.parent}}" class="form-control" readonly>
</div>
</div>

 

 

 

if my answer helped you, kindly mark it as correct and helpful.

 

Hi Harshvardhan,

 

Thank you for your response.

After debugging, I found that value is getting set with whatever code I have written. I found below in logs:

{"number":"TICKET0002645","agency.number":"ACCT0010001","agency.name":"DMV - ACCOUNT0001001"}

But, the issue is with the html code

 

<tr ng-repeat="item in c.data.items">
<td>{{item.number}}</td>
<td>{{item.agency.number}}</td>
<td>{{item.agency.name}</td>
</tr>

 

I am not able to get the value here. Can you please advise here?

it will not work this way. because it is not doing dot walk here inside the function. that's why i passed another variable to fetch reference value. 

 

eg:

 

data.loc.parent = locGR.yourField.dotWalkfield.getDisplayValue();

Thanks for your support. But, I somehow made it work through the existing code itself.

 

Instead of item.agency.name,I used item["agency.name"]. My bad, we can not directly fetch values of keys with such names abc.xyz by simply dot-walking. Instead, we need to fetch the same by passing it as a key.