1

I have a requirement that when Opportunity stage goes from stage A to B (which happens automatically using Flows when user fills few required fields on Opportunity and hit save.), this stage movement should open up a popup(modal) with a couple of custom fields for them to fill in and when they hit 'Ok', that would then save the popup fields on Opportunity. I am using Lightning Data Service and here is my lightning component

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickActionwithoutheader" access="global" >
<aura:attribute name="opportunityRecord" type="Opportunity"/>
<aura:attribute name="recordError" type="String"/>
<aura:attribute name="openModal" type="Boolean" default="false" />

    <force:recordData aura:id="opportunityRecordCmp"
                      recordId="{!v.recordId}"
                      fields="Id,StageName"
                      targetFields="{!v.opportunityRecord}"
                      recordUpdated="{!c.openModalBox}"
                      targetError="{!v.recordError}" 
                        mode="EDIT"/>
    <aura:if isTrue="{!v.openModal}" >
        <div class="demo-only" style="height: 100px;">
            <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">
                    <!-- Header of Modal -->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close" class="slds-modal__close" size="small" variant="bare" alternativeText="Close" onclick="{! c.closeModal }"/>
                        <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Warning</h2>
                    </header>
                     <!-- Body of Modal -->
                    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <p> INSERT FIELD FORM HERE</p>
                    </div>
                    <!-- Footer of Modal -->
                    <footer class="slds-modal__footer">
                        <lightning:button variant="brand" label="OK" title="Save" onclick="{!c.handleOk}" />
                        <lightning:button variant="brand" label="Cancel" title="Cancel" onclick="{! c.handleCancel }" />   
                    </footer>
                </div>
            </section>
            <!-- Backdrop to set background slightly opaque. -->
            <div class="slds-backdrop slds-backdrop_open"></div>
        </div>
    </aura:if>
    <!--End of Modal Footer-->
    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            <ui:message title="Error" severity="error" closable="true">
                {!v.recordError}
            </ui:message>
        </div>
    </aura:if>
</aura:component>

Controller -

({
    openModalBox:function(component, event, helper) {
        var changeType = event.getParams().changeType;
        console.log("I am here");
        if (changeType === "CHANGED" && (('StageName' in event.getParams().changedFields))) {
            var newStageName = event.getParams().changedFields.StageName.value;
            var oldStageName = event.getParams().changedFields.StageName.oldValue;
            if(newStageName == 'B' && oldStageName == 'A'){
                component.set('v.openModal',true);
            }
        }
    },
    
    handleOk:function(component, event, helper) {
        
        component.set('v.openModal',false);
        
    },
    
    handleCancel : function(component, event, helper) {
        component.set('v.openModal',false);
    }
})

The problem is when I am filling those required fields on Opportunity for moving from Stage A to B, the popup (modal) is not opening up. I have tried putting console.log in the openModalBox but nothing is getting displayed in console. When I tried to invoke this using a quick action button, its opening the popup (modal) but not happening with field (StageName) update. Can you please help in what I might be doing wrong here?

1 Answer 1

0

Due to lack of reputation points I am sorry I cannot add this as a comment. I am facing a similar issue and wanted to ask if you ever solved this? As far as I can see the recordUpdated method is only called when screen is loaded. Add the changeType to your console.log output to this happening.

1
  • While your frustration and desire to get an update are understandable, your "answer" still is likely to be deleted. You only need 39 more rep points (50 total) to be able to comment. It should not take long to get those points if you add legitimate answers to some unanswered questions, and those answers get upvoted and/or accepted; or you make some helpful edits to existing questions or answers (although that would take jiust a little longer to get enough points).
    – Moonpie
    Commented Dec 5, 2022 at 21:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .