+ Start a Discussion
ALAL 

Retrieving Record field value to fire an action

Hello, I'm looking to create a component that fires an action (i.e. popup modal) if a custom account check box is populated. I have the  popup box appearing if I click on the account's 'edit' button which I overrode, but I'd like to create an 'if' condition. Any help would be appreciated. Thank you. 

Component
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,lightning:actionOverride,force:hasRecordId,force:lightningQuickAction" access="global" >
	
    <aura:attribute name="isModalOpen" type="boolean" default="false"/>
    <aura:attribute name="AOff" type="Account" default="{'sobjectType': 'Account'
                                                        'Offsite_Data_Transfer_Prohibited__c': false}"/>
   
 <!--   <lightning:button variant="brand" label="Override" onclick="{!c.handleModal}" /> -->
    
    
    <force:recordData aura:id="forceRecord"
                recordId="{!v.recordId}"
                targetRecord="{!v.forceRecord}"
                targetFields="{!v.AOff}"
                fields="Id,Offsite_Data_Transfer_Prohibited__c"
                mode="EDIT" />
    
    <aura:handler name="init" value="{!this}" action="{!c.handleModal}" ></aura:handler>
    
  
    <div class="slds-m-around_xx-large">
        
        <!--
        <lightning:button variant="brand"
                          label="What is Modal/PopUp Box?"
                          title="What is Modal/PopUp Box?"
                          onclick="{! c.openModel }" />  -->
    
    <!--Use aura:if tag to display/hide popup based on isModalOpen value-->  
        <aura:if isTrue="{!v.isModalOpen}">
    
     <!-- Modal/Popup Box starts here-->
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">


 <div class="slds-modal__container">
                    <!-- Modal/Popup Box Header Starts here-->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close"
                                              onclick="{! c.closeModel }"
                                              alternativeText="close"
                                              variant="bare-inverse"
                                              class="slds-modal__close"/>



 <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">OffSite Data Transfer Prohibited</h2>
                    </header>


 <!--Modal/Popup Box Body Starts here-->
                    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <p><b>The transfer of data offiste for this account is prohibited. 
                            </b>
                        </p>
                    </div>

<!--Modal/Popup Box Footer Starts here-->
                    <footer class="slds-modal__footer">
                        <lightning:button variant="neutral"
                                          label="Cancel"
                                          title="Cancel"
                                          onclick="{! c.closeModel }"/>
                        <lightning:button variant="brand"
                                          label="OK"
                                          title="OK"
                                          onclick="{!c.submitDetails}"/>
                    </footer>
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
        </aura:if>
    </div>
    
</aura:component>

Controller 
 
({
    handleModal: function(component, event, helper) {
       
        // Set isModalOpen attribute to true
    
      component.set("v.isModalOpen", true);
    },
    
      closeModel: function(component, event, helper) {
      // Set isModalOpen attribute to false  
      component.set("v.isModalOpen", false);
   },
    
    
   submitDetails: function(component, event, helper) {
      // Set isModalOpen attribute to false
      //Add your code to call apex method or do some processing
      component.set("v.isModalOpen", false);
   }
    
    
    
})

 
Deepali KulshresthaDeepali Kulshrestha
Hi,

I've gone through your requirement and you can refer below example to achieve your requirement:

(Note--> v.newAccount.CheckBox__c ,create a checkbox in account before )

1.Aura component:

<aura:component controller="InsertAccoutnRecord" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="newAccount" type="Account" default="{'sobjectType':'Account',
                                                              'Name':'',
                                                              'Phone':'',
                                                              'Description':'',
                                                              'Status__c':'Open',
                                                              }" />
    
    <div class="row">
        <div class="container-fluid">
            <h3> Enter Account Information </h3>
            <div class="form-group">
                <label>Account Name: </label>
                <lightning:input value="{!v.newAccount.Name}"/>
                
                <label>Account Phone: </label>
                <lightning:input value="{!v.newAccount.Phone}"/>
                                
                <label>Account Status: </label>
                <lightning:input value="{!v.newAccount.CheckBox__c}"/>
                
                <label>Account Description: </label>
                <lightning:input  value="{!v.newAccount.Description}"/>
                
                
                <lightning:button label="Submit" onclick="{!c.handleClick}"/>
            </div>
        </div>
        
   
        <aura:if isTrue="{!v.v.newAccount.CheckBox__c}">
            
            <!--###### MODAL BOX Start######--> 
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
                <div class="slds-modal__container">
                    <!-- ###### MODAL BOX HEADER Start ######-->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close"
                                              onclick="{! c.closeModel }"
                                              alternativeText="close"
                                              variant="bare-inverse"
                                              class="slds-modal__close"/>
                        <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">About Sfdcmonkey.com</h2>
                    </header>
                    <!--###### MODAL BOX BODY Part Start######-->
                    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        
                    </div>
                    <!--###### MODAL BOX FOOTER Part Start ######-->
                    <footer class="slds-modal__footer">
                        <lightning:button variant="neutral" 
                                          label="Cancel"
                                          title="Cancel"
                                          onclick="{! c.closeModel }"/>
                        <lightning:button variant="brand" 
                                          label="Like and Close"
                                          title="Like and Close"
                                          onclick="{!c.likenClose }"/>
                    </footer>
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
            <!--###### MODAL BOX Part END Here ######-->
            
        </aura:if>
    </div>
 </div>
</aura:component>

2.Controller:

({
 
   likenClose: function(component, event, helper) {
      // Display alert message on the click on the "Like and Close" button from Model Footer 
      // and set set the "isOpen" attribute to "False for close the model Box.
      alert('thanks for like Us :)');
      component.set("v.isOpen", false);
   },
})



I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
ALAL
Thank you very much for modifying the code. Is it possible to render the pop-up message only one time (i.e. the initial time that the user edits the acocunt)?

The proposed workflow we'd like to have is that if a user is on an account record and the checkbox field is populated, then the pop up modal will appear. However, we don't need the popup to appear every time the user is editing the account within the same browsing session. Not sure if that makes sense?