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
Jonathan Wolff 7Jonathan Wolff 7 

Aura:if does not worked like hoped

Hello, I have a component on account object. I want to render part of the component dependend on if the checkbox 'Urlaub__c' on the ownerUser is true. The problem I have is, that with the way I did it the section Is not showing up even tough the checkbox is true. Could you tell me what to change so that it works?
 
<aura:if isTrue="{!v.OwnerUser.Urlaub__c}">
            <lightning:layoutItem padding="around-small">                
                <br></br> 
                
                <div class="header-column" width="100%">
                    <div style="font-size: 15px;"><b>{!v.OwnerUser.Vertreter__c.Name}</b></div>
                    <div style="font-size: 10px;">Team {!v.OwnerUser.Team_2020__c}</div>
                    <div>
                        <a href="{!'tel:' + v.OwnerUser.Vertreter__c.MobilePhone}"><lightning:icon iconName="action:call" size="xx-small" alternativeText="Telefon" title="Telefon"   /></a>&nbsp;
                        <a href="{!'mailto:' + v.OwnerUser.Vertretung__c.Email}"><lightning:icon iconName="action:email" size="xx-small" alternativeText="E-Mail" title="E-Mail" /></a>&nbsp;
                        <a href="{!v.OwnerUser.Vertreter__c.Link_BookingTime__c}" target="_blank"><lightning:icon iconName="action:new_event" size="xx-small" alternativeText="BookingTime" title="BookingTime" /></a> 
                    </div>
                    
                </div>
                   
            </lightning:layoutItem>
              </aura:if>

 
Best Answer chosen by Jonathan Wolff 7
CharuDuttCharuDutt
Hi Jhon

Try Below Code
And Make Sure The User You Are Getting From Apex In Query Have All The Fields That You Want To Use in Code
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="OwnerUser" type="user" default="{'sobjectType' : 'User'}" />   
    <aura:attribute name="ids" type="id" default="{!v.recordId}" />
    
    <div class="c-container" style=" border-radius: 4px;  background-color: #FFFFFF; ">
        <lightning:layout >            
            <lightning:layoutItem padding="around-small">
                <div class="header-column">
                    <img src="{!v.OwnerUser.FullPhotoUrl}" class="img_size" variant="circle" height="180px;"  />
                </div>
            </lightning:layoutItem>            
            <lightning:layoutItem padding="around-small">                
                <br></br>                
                <div class="header-column" width="100%">
                    <div style="font-size: 15px;"><b>{!v.OwnerUser.Name}</b></div>

                    <div style="font-size: 10px;">Urlaub {!v.OwnerUser.Urlaub__c}</div>
                    <div>
                        <a href="{!'tel:' + v.OwnerUser.MobilePhone}"><lightning:icon iconName="action:call" size="xx-small" alternativeText="Telefon" title="Telefon" /></a>&nbsp;
                        <a href="{!'mailto:' + v.OwnerUser.Email}"><lightning:icon iconName="action:email" size="xx-small" alternativeText="E-Mail" title="E-Mail" /></a>&nbsp;
                        
                    </div>
                    
                </div>
            </lightning:layoutItem>

		<aura:if isTrue="{!v.OwnerUser.Urlaub__c}">
            <lightning:layoutItem padding="around-small">                
                <br></br> 
                <div class="header-column" width="100%">
                    <div style="font-size: 15px;"><b>{!v.OwnerUser.Name}</b></div>

                    <div>
                       

                    </div>
                </div>
            </lightning:layoutItem>
              </aura:if>


        </lightning:layout>        
    </div>    
</aura:component>






public class UserDetails {
@AuraEnabled (cacheable=true)
    public static User getFieldsAndRecords(Id AccountId){
        User oUser =[SELECT FullPhotoUrl, Id, Name, AccountId, Urlaub__c FROM User WHERE AccountId = :AccountId];
            return oUser;
    }
}
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Johnathan 
If Your Iterating The Data
<aura:iteration items="{!v.data}" var="OwnerUser">
<aura:if isTrue="{!OwnerUser.Urlaub__c}">
            <lightning:layoutItem padding="around-small">                
                <br></br> 
                
                <div class="header-column" width="100%">
                    <div style="font-size: 15px;"><b>{!OwnerUser.Vertreter__c.Name}</b></div>
                    <div style="font-size: 10px;">Team {!OwnerUser.Team_2020__c}</div>
                    <div>
                        <a href="{!OwnerUser.Vertreter__c.MobilePhone}"><lightning:icon iconName="action:call" size="xx-small" alternativeText="Telefon" title="Telefon"   /></a>&nbsp;
                        <a href="{!OwnerUser.Vertretung__c.Email}"><lightning:icon iconName="action:email" size="xx-small" alternativeText="E-Mail" title="E-Mail" /></a>&nbsp;
                        <a href="{!OwnerUser.Vertreter__c.Link_BookingTime__c}" target="_blank"><lightning:icon iconName="action:new_event" size="xx-small" alternativeText="BookingTime" title="BookingTime" /></a> 
                    </div>
                </div>
            </lightning:layoutItem>
              </aura:if>
</aura:iteration>
Please Mark It As Best Answer If It Helps
Thank You!
Jonathan Wolff 7Jonathan Wolff 7
Hi CharuDutt, I still face the same problem. Maybe for better understanding:
The Urlaub__c field is on the user object. I give you my whole code, maybe you see where my mistake comes from
 
<aura:component controller="VisitenkarteRecordDetails" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="OwnerUser" type="user" default="{'sobjectType' : 'User'}" />   
    <aura:attribute name="ids" type="id" default="{!v.recordId}" />
    
    <div class="c-container" style=" border-radius: 4px;  background-color: #FFFFFF; ">
        <lightning:layout >            
            <lightning:layoutItem padding="around-small">
                <div class="header-column">
                    <img src="{!v.OwnerUser.SmallPhotoUrl}" class="img_size" variant="circle" height="180px;"  />
                </div>
            </lightning:layoutItem>            
            <lightning:layoutItem padding="around-small">                
                <br></br>                
                <div class="header-column" width="100%">
                    <div style="font-size: 15px;"><b>{!v.OwnerUser.Name}</b></div>
                    <div style="font-size: 10px;">Team {!v.OwnerUser.Team_2020__c}</div>
                    <div style="font-size: 10px;">Urlaub {!v.OwnerUser.Urlaub__c}</div>
                    <div>
                        <a href="{!'tel:' + v.OwnerUser.MobilePhone}"><lightning:icon iconName="action:call" size="xx-small" alternativeText="Telefon" title="Telefon" /></a>&nbsp;
                        <a href="{!'mailto:' + v.OwnerUser.Email}"><lightning:icon iconName="action:email" size="xx-small" alternativeText="E-Mail" title="E-Mail" /></a>&nbsp;
                        <a href="{!v.OwnerUser.Link_BookingTime__c}" target="_blank"><lightning:icon iconName="action:new_event" size="xx-small" alternativeText="BookingTime" title="BookingTime" /></a> 
                    </div>
                    
                </div>
            </lightning:layoutItem>
           <aura:iteration items="{!v.data}" var="OwnerUser">
		<aura:if isTrue="{!OwnerUser.Urlaub__c}">
            <lightning:layoutItem padding="around-small">                
                <br></br> 
                
                <div class="header-column" width="100%">
                    <div style="font-size: 15px;"><b>{!OwnerUser.Vertreter__c.Name}</b></div>
                    <div style="font-size: 10px;">Team {!OwnerUser.Team_2020__c}</div>
                    <div>
                        <a href="{!OwnerUser.Vertreter__c.MobilePhone}"><lightning:icon iconName="action:call" size="xx-small" alternativeText="Telefon" title="Telefon"   /></a>&nbsp;
                        <a href="{!OwnerUser.Vertretung__c.Email}"><lightning:icon iconName="action:email" size="xx-small" alternativeText="E-Mail" title="E-Mail" /></a>&nbsp;
                        <a href="{!OwnerUser.Vertreter__c.Link_BookingTime__c}" target="_blank"><lightning:icon iconName="action:new_event" size="xx-small" alternativeText="BookingTime" title="BookingTime" /></a> 
                    </div>
                </div>
            </lightning:layoutItem>
              </aura:if>
</aura:iteration>

        </lightning:layout>        
    </div>    
</aura:component>
 
({     
    doInit : function(component, event, helper) {       
        var AccountIDS=component.get("v.ids");             
        console.log('account ids'+ AccountIDS);              
        var action = component.get("c.fetchUserDetail");         
        action.setParams({                   
            "Accountids" : AccountIDS });        
        action.setCallback(this, function(response) {            
            var state = response.getState();            
            if (state === "SUCCESS") {               
                var res = response.getReturnValue();                
                component.set('v.OwnerUser', res);             
            }                                 
        });               
        $A.enqueueAction(action);      
    }, 
})

 
CharuDuttCharuDutt
Hi Jhon

Try Below Code
And Make Sure The User You Are Getting From Apex In Query Have All The Fields That You Want To Use in Code
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="OwnerUser" type="user" default="{'sobjectType' : 'User'}" />   
    <aura:attribute name="ids" type="id" default="{!v.recordId}" />
    
    <div class="c-container" style=" border-radius: 4px;  background-color: #FFFFFF; ">
        <lightning:layout >            
            <lightning:layoutItem padding="around-small">
                <div class="header-column">
                    <img src="{!v.OwnerUser.FullPhotoUrl}" class="img_size" variant="circle" height="180px;"  />
                </div>
            </lightning:layoutItem>            
            <lightning:layoutItem padding="around-small">                
                <br></br>                
                <div class="header-column" width="100%">
                    <div style="font-size: 15px;"><b>{!v.OwnerUser.Name}</b></div>

                    <div style="font-size: 10px;">Urlaub {!v.OwnerUser.Urlaub__c}</div>
                    <div>
                        <a href="{!'tel:' + v.OwnerUser.MobilePhone}"><lightning:icon iconName="action:call" size="xx-small" alternativeText="Telefon" title="Telefon" /></a>&nbsp;
                        <a href="{!'mailto:' + v.OwnerUser.Email}"><lightning:icon iconName="action:email" size="xx-small" alternativeText="E-Mail" title="E-Mail" /></a>&nbsp;
                        
                    </div>
                    
                </div>
            </lightning:layoutItem>

		<aura:if isTrue="{!v.OwnerUser.Urlaub__c}">
            <lightning:layoutItem padding="around-small">                
                <br></br> 
                <div class="header-column" width="100%">
                    <div style="font-size: 15px;"><b>{!v.OwnerUser.Name}</b></div>

                    <div>
                       

                    </div>
                </div>
            </lightning:layoutItem>
              </aura:if>


        </lightning:layout>        
    </div>    
</aura:component>






public class UserDetails {
@AuraEnabled (cacheable=true)
    public static User getFieldsAndRecords(Id AccountId){
        User oUser =[SELECT FullPhotoUrl, Id, Name, AccountId, Urlaub__c FROM User WHERE AccountId = :AccountId];
            return oUser;
    }
}
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer