0

I created a LWC which works ok. I created this LWC so that I can use it as a Quick Action. Because LWC can not be used in quick actions for Work Order object, I had to put the LWC in a aura component and then put the aura in the quick action button. The one thing that is not working is the Cancel button. When I hit Cancel, it should close the modal. Also when I hit the submit button it should process the thing we are doing and then automatically close the modal. This close functionality is not happening. Can anyone let me know why?

LWC html:

<template>
    
    <lightning-quick-action-panel>
        <div class="slds-grid slds-wrap">
            <div class="slds-col slds-size_1-of-2 first-last-name">
                <label
                    class="slds-form-element__label slds-float_left your-info-label-field"
                    for="otherSubject">Please enter the zip code</label>
                <lightning-input type="text" variant="label-hidden" label="Zip Code"
                    value={zipCode}
                    onchange={handleZipChange}></lightning-input>
            </div>
        </div>
 
        <div slot="footer">
            <lightning-button variant="neutral"
             label="Cancel" onclick={closeAction}>
            </lightning-button>
            <lightning-button variant="brand"
             label="Add Order" onclick={saveAction} 
             class="slds-m-left_x-small">
            </lightning-button>
        </div>
    </lightning-quick-action-panel>
</template>

LWC JS:

import { LightningElement, api, track } from 'lwc';
import {CloseActionScreenEvent} from 'lightning/actions';
import {getRecordNotifyChange} from 'lightning/uiRecordApi';
import getInfo from '@salesforce/apex/Order_QuickAction.getWipersInfo';
import addWoli from '@salesforce/apex/Order_QuickAction.addWipersToWO';
export default class OrderEntry extends LightningElement {
    @api recordId;
    @track zipCode;
    @track wResponse;
    @track wPartNumber;
    @track wPrice = 0.00;



    handleZipChange(event){ //do I even need this method? I want to pass zip code value to a method that's why I have this 
        this.zipCode = event.target.value;
    }

    closeAction(){
        this.dispatchEvent(new CloseActionScreenEvent());
    }

    saveAction(){
        if(this.recordId){
            getInfo({workOrderId: this.recordId, zipCode: this.zipCode})
            .then(result => {
                console.log('the response is  '+ this.result);
                this.wResponse = result;
                this.wPartNumber = result.PartNumber;
                this.wPrice = result.Price;
                this.wPrice =  this.wipersPrice * 2;
                return addWoli({workOrderId: this.recordId, partNumber: this.wPartNumber, price: this.wPrice})
            }).then(result => {
                
                    getRecordNotifyChange( items [{recordId: this.recordId}]);
                    closeAction();
    
            })
            .catch(error => {
                console.log('Error >>>> :: ' + JSON.stringify(error));
                this.error = error;
            });
        }

    }


}

Aura Component:

<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId">
    <aura:html tag="style">
        .slds-modal__container { min-width: 70vw; }
    </aura:html>
    <c:orderEntry recordId="{!v.recordId}"/>
</aura:component>

Apex:

public class Order_QuickAction {
    @AuraEnabled
    public static ResponseWrapp getWipersInfo (Id workOrderId, String zipCode){
        WorkOrder wo = [SELECT Id, Vehicle__r.Car_Id__c FROM WorkOrder Where Id =:workOrderId];
        System.debug('The card id is ' + wo.Vehicle__r.Car_Id__c);
        System.debug('The zipcode is ' + zipCode);
        System.debug('The response for wipers is ' +  OrderCalls.getWipers(wo.Vehicle__r.Car_Id__c, zipCode));
        return OrderCalls.getWipers(wo.Vehicle__r.Car_Id__c, zipCode);    //I have used this method in other places and it works it is also giving a response successfully so this method can't be the issue
    }
    
    @AuraEnabled
    public static Boolean addWipersToWO(Id workOrderId, String partNumber, Decimal price){
        WorkOrderLineItem woli = new WorkOrderLineItem();
        woli.WorkOrderId = workOrderId;
        woli.Part_Number__c = partNumber;
        woli.Type__c = 'Part';
        //woli.Quantity = 2;
        //woli.UnitPrice = price;
        woli.Part_Type__c = 'Wipers';
        insert woli;
        return true;
        
    }
}

Can someone please help as to why the modal won't close? Thank you

2 Answers 2

0
  1. as closeAction is an event handler function it should have a event param to avoid unexpected js errors, it can solve your problem eg.
    closeAction(event){
        this.dispatchEvent(new CloseActionScreenEvent());
    }
  1. please check if saveAction is working because it should not since you have used closeAction function directly whereas it should be used with this, eg.
saveAction(){
        if(this.recordId){
            getInfo({workOrderId: this.recordId, zipCode: this.zipCode})
            .then(result => {
                console.log('the response is  '+ this.result);
                this.wResponse = result;
                this.wPartNumber = result.PartNumber;
                this.wPrice = result.Price;
                this.wPrice =  this.wipersPrice * 2;
                return addWoli({workOrderId: this.recordId, partNumber: this.wPartNumber, price: this.wPrice})
            }).then(result => {
                
                    getRecordNotifyChange( items [{recordId: this.recordId}]);
                    this.closeAction();  //<<--
    
            })
            .catch(error => {
                console.log('Error >>>> :: ' + JSON.stringify(error));
                this.error = error;
            });
        }

    }
2
  • Hello Shubnam, I put the event in the closeAction and also put this.closeAction(); it still did not work. The method is doing what its supposed to do but the modal won't close May 22, 2023 at 23:22
  • @Shubnam Jangid I put in this.closeAction() and It didn't work May 23, 2023 at 1:39
0

I have seen some comments over on GitHub with regards to this as the close action doesn't work when used within a QuickAction.

https://github.com/salesforce/lwc/issues/2722

A potential fix is noted at the bottom:

this.dispatchEvent(new CloseActionScreenEvent({ bubbles: true, composed: true }));
1
  • this did not work either. The modal is not closing after finishing its work. Hitting the cancel button won't close it either May 23, 2023 at 13:24

You must log in to answer this question.

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