Lookup field default shows up as Id

  • 1
  • Question
  • Updated 4 years ago
I often set default values in Javascript. This will usually be via a page load snippet, which will update the fields to the predefined values. I'm running into an issue with lookup fields where if I update a lookup field, the field shows the Id value "a0234128792132" instead of "Bob Jones". I can't figure out how to get it to display the name value. Is there a way to do this?
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Here is code from a tutoria that Zach wrote about mass adding statements.  It programmatically sets a condition on new rows with the Name of a contact. 


// Now, auto-generate a new Statement record 
// for each Contact in this Account.
$.each(<strong>contacts</strong>.data,function(){
var row = newStatements.createRow({
additionalConditions: [
{ field: '<strong>Contact__c</strong>', value: this.Id, operator: '=', nameFieldValue: this.Name }
]
});
});


I believe inserting the nameFieldValue is the trick you are after. 

Here is the full tutorial
(Edited)
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,704 Points 20k badge 2x thumb
Until it's saved I think the Name field won't show. I bet you can get the Name field to show if you put the default value into it's own model and then set the lookup field.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
OK thanks Rob but I am working with an existing row, meaning I'm doing something like this:
myModel.updateRow(myRow,{
    myLookup_Field__c : myUpdateVal
});
I have used that syntax from Zach for creating new rows, but what If I'm trying to update an existing row? How can I get at the nameFieldValue in an update situation? Can I add "additional conditions" to an existing row?
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Pat I'm dealing with data that already exists. So supposing I want to default a custom lookup field to the current user. I can get the current user Id in Javascript, say I have a var called "userId". If I update the row like :
myModel.updateRow(myRow,{
    myLookup_Field__c : userId
});
My custom field will actually get updated it just doesn't look good to the user who sees a bunch of nonsense inside the field. Skuid automatically shows the Name instead of the Id in a lookup field. I want to be able to have my Id update show up as a Name to the user.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
About to fall off the page here... Any ideas?
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,470 Points 10k badge 2x thumb
Hi Moshe,

When you update a reference field like that, you need to give it a name as well.  Skuid isn't smart enough (yet) to go to the server and get the name of the user you just referenced.  However, if you just provide the name in your javascript, it should display correctly.

myModel.updateRow(oppRow,{ 
    myLookup_Field__c : userId, 
    myLookup_Field__r : { Name : 'My Name'}
});
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Perfect! In retrospect it makes perfect sense, I should have figured that out myself... It's working great now!