• Tor
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I am very new to this, but I am trying to display a warning toast to users if the stage name on an opportunity is changed from any value to Pending Approval. To do this I was trying to use Lightning components. 

Please see below for my cmp and js code. I tried to take 2 different approaches with this code and neither one have been successful so hoping that someone can provide some tips. Certainly also open to other ways of accomplishing this.

1. Use <aura:if and call the showWarningToast function if true. In the below code I am able to get it to show a button you can click on if the condition is true, but I have not been able to find a way to call the code without having the user click on the button. Also, the below code always shows the warning button if the value is Pending Approval not only if it is changed to Pending Approval.

2. Use <aura:handler name="change" and call the function itemsChange. This option seems more promising since I could easily add a statement to check if old and new value are different and only show the Toast if it is, but I am unable to show the old and new value. It simply shows old value: [object Object]current value: [object Object]

CMP:
<aura:component description="OpportunityTestComponent" implements="flexipage:availableForRecordHome,force:hasRecordId">
    <aura:attribute name="record" type="Object" description="The record object to be displayed"/>
    <aura:attribute name="OpptyRecord" type="Object" description="A simplified view record object to be displayed"/>

    <force:recordData aura:id="record" layoutType="FULL" recordId="{!v.recordId}" targetRecord="{!v.record}" targetFields="{!v.OpptyRecord}" mode="VIEW"/>

    <aura:handler name="change" value="{!v.OpptyRecord.StageName}" action="{!c.itemsChange}"/>
    
    <aura:if isTrue="{!v.OpptyRecord.StageName == 'Pending Approval'}">
         <lightning:button label="Warning" variant="inverse" onclick="{!c.showWarningToast}"/> 
    </aura:if>
</aura:component>

JS:

({
    showWarningToast : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            title : 'Please review the award date!',
            message: 'Please review the award date and correct as necessary!',
            key: 'info_alt',
            type: 'warning',
            mode: 'sticky'
        });
        toastEvent.fire();
    },
        itemsChange: function(cmp, evt) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            title : 'Please review the award date!',
            message: "old value: " + evt.getParam("oldValue") + "current value: " + evt.getParam("value"),
            key: 'info_alt',
            type: 'warning',
            mode: 'sticky'
        });
        toastEvent.fire();
        }
})

 
  • March 04, 2021
  • Like
  • 0
I am very new to this, but I am trying to display a warning toast to users if the stage name on an opportunity is changed from any value to Pending Approval. To do this I was trying to use Lightning components. 

Please see below for my cmp and js code. I tried to take 2 different approaches with this code and neither one have been successful so hoping that someone can provide some tips. Certainly also open to other ways of accomplishing this.

1. Use <aura:if and call the showWarningToast function if true. In the below code I am able to get it to show a button you can click on if the condition is true, but I have not been able to find a way to call the code without having the user click on the button. Also, the below code always shows the warning button if the value is Pending Approval not only if it is changed to Pending Approval.

2. Use <aura:handler name="change" and call the function itemsChange. This option seems more promising since I could easily add a statement to check if old and new value are different and only show the Toast if it is, but I am unable to show the old and new value. It simply shows old value: [object Object]current value: [object Object]

CMP:
<aura:component description="OpportunityTestComponent" implements="flexipage:availableForRecordHome,force:hasRecordId">
    <aura:attribute name="record" type="Object" description="The record object to be displayed"/>
    <aura:attribute name="OpptyRecord" type="Object" description="A simplified view record object to be displayed"/>

    <force:recordData aura:id="record" layoutType="FULL" recordId="{!v.recordId}" targetRecord="{!v.record}" targetFields="{!v.OpptyRecord}" mode="VIEW"/>

    <aura:handler name="change" value="{!v.OpptyRecord.StageName}" action="{!c.itemsChange}"/>
    
    <aura:if isTrue="{!v.OpptyRecord.StageName == 'Pending Approval'}">
         <lightning:button label="Warning" variant="inverse" onclick="{!c.showWarningToast}"/> 
    </aura:if>
</aura:component>

JS:

({
    showWarningToast : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            title : 'Please review the award date!',
            message: 'Please review the award date and correct as necessary!',
            key: 'info_alt',
            type: 'warning',
            mode: 'sticky'
        });
        toastEvent.fire();
    },
        itemsChange: function(cmp, evt) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            title : 'Please review the award date!',
            message: "old value: " + evt.getParam("oldValue") + "current value: " + evt.getParam("value"),
            key: 'info_alt',
            type: 'warning',
            mode: 'sticky'
        });
        toastEvent.fire();
        }
})

 
  • March 04, 2021
  • Like
  • 0