function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hugogmendeshugogmendes 

LWC Output Field is not showing values for some lookup fields

Hello everyone!

I've created a lightning-record-view-form with several fields. Some of the fields are lookups and the lookup fields are for differents objects, including custom and standard objects. The issue is that some of lookups isn't showing any value, but other do show.
 

<lightning-record-view-form record-id={recordId} object-api-name="Suprimentos__c">
	<div class="slds-form" role="list">
		<div class="slds-section slds-is-open">
			<h3 class="slds-section__title slds-theme_shade">
				<span class="slds-truncate slds-p-horizontal_small" title="Detalhes do chamado">
					Detalhes do chamado
				</span>
			</h3>

			<div aria-hidden="false" class="slds-section__content">
				<div class="slds-form__row">
					<template if:true={exibirPropChamado}>
						<div class="slds-form__item slds-size_1-of-2" role="listitem">
							<lightning-output-field variant="label-stacked"
								field-name="Proprietario_do_chamado__c" id="Read_Proprietario_do_chamado__c">
							</lightning-output-field>
						</div>
					</template>
				</div>

				<div class="slds-form__row">
					<div class="slds-form__item slds-size_1-of-2" role="listitem">
						<lightning-output-field field-name="Empresa__c" id="Read_Empresa__c" variant="label-stacked">
						</lightning-output-field>
					</div>
				</div>
			</div>
		</div>
	</div>
</lightning-record-view-form>


In my code above, both fields Proprietario_do_chamado__c (User) and Empresa__c (Account) are filled, but only Proprietario_do_chamado__c is showing the value.

I'm pretty sure that api field name is correct for Empresa__c.


Someone knows how to solve this?

Best Answer chosen by hugogmendes
hugogmendeshugogmendes
I decided to implement the view form with lightning-record-edit-form. Every lightning-input-field has the disabled attribute and the value attribute is filled by an object queried from server.

All Answers

Nayana KNayana K
Does the running user have atleast read permission on Account? 
hugogmendeshugogmendes
Yes! It's a admin user, with view all data permission enabled.
Nayana KNayana K
Please make sure Suprimentos__c.Empresa__c field level security is read-only or visible. I tried in my peronal org. It respects field level security.
hugogmendeshugogmendes

I checked it and I have all necessary permissions. Actually, in standard layout, the field Empresa__c is showing correctly.
Also, in lightning-record-edit-form the value is displayed. So, I believe that the problem is with lightning-record-view-form.

I'm not sure if it's a bug or I coded something wrong.

hugogmendeshugogmendes

I realized that the field value is only displayed when the field is present in the page layout. I debug load event and found that, actually, the value is populated, but not its mask.

Output JSON:

(...)
"Empresa__c": {
	"displayValue": null,
	"value": "001P000001OpVUCIA3"
},
(...)
It seems that aura component has the same problem Lookup fields which is not a part of page layout is not working as expected with lightning data services (https://success.salesforce.com/issues_view?id=a1p3A000001RWq7QAG)
hugogmendeshugogmendes
I decided to implement the view form with lightning-record-edit-form. Every lightning-input-field has the disabled attribute and the value attribute is filled by an object queried from server.
This was selected as the best answer