Lookup field default shows up as Id

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?

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 <br>// for each Contact in this Account.<br>$.each(<strong>contacts</strong>.data,function(){<br>var row = newStatements.createRow({<br>additionalConditions: [<br>{ field: '<strong>Contact__c</strong>', value: this.Id, operator: '=', nameFieldValue: this.Name }<br>]<br>});<br>});

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

Here is the full tutorial

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.

OK thanks Rob but I am working with an existing row, meaning I’m doing something like this:

myModel.updateRow(myRow,{<br>&nbsp; &nbsp; myLookup_Field__c : myUpdateVal<br>});

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?

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,{<br>&nbsp; &nbsp;&nbsp;myLookup_Field__c : userId<br>});

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.

About to fall off the page here… Any ideas?

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'} });<br>

Perfect! In retrospect it makes perfect sense, I should have figured that out myself… It’s working great now!