0

Hello everybody I am currently working on a Flow that contains an Aura component that contains a LWC. The flow contains a Picklist and then a Decision component chooses one Lightning component (that contains a LWC) or other Lightning component (that contains an other different LWC). In this case the LWC form are all different but the Lightning Component are the same. So in order to avoid repetition of the Lightning component code, is there a way that in a LC to put various LWC?

the Lightning component code is:

<aura:component implements="flexipage:availableForAllPageTypes,force:lightningQuickActionWithoutHeader,force:hasRecordId,forceCommunity:availableForAllPageTypes,lightning:availableForFlowScreens,force:hasRecordId" access="global">
<!-- implements="lightning:availableForFlowScreens,flexipage:availableForAllPageTypes,force:lightningQuickAction,force:hasRecordId,forceCommunity:availableForAllPageTypes">     -->
   <aura:html tag="style">
       .slds-modal__container {
            width : 90% !important;
            max-width : 90% !important;
        }
   </aura:html>
   <c:qX_LWC_FormularioIniciarMensajeria recordId="{!v.recordId}" codigoSolicitud="{!v.codigoSolicitud}"/>
   <aura:attribute name="recordId" type="String" access="global" />
   <aura:attribute name="codigoSolicitud" type="String" access="global" />
   
</aura:component>

So all the LWC are going to receive the recordId and codigoSolicitud attribute. Could anybody help me? Give me some resources? or explain me this?

1 Answer 1

0

You should be able to create the component dynamically:

<aura:component implements="flexipage:availableForAllPageTypes,force:lightningQuickActionWithoutHeader,force:hasRecordId,forceCommunity:availableForAllPageTypes,lightning:availableForFlowScreens,force:hasRecordId" access="global">
  <aura:html tag="style">
     .slds-modal__container {
        width : 90% !important;
        max-width : 90% !important;
      }
  </aura:html>
  <aura:attribute name="codigoSolicitud" type="String" access="global" />
  <aura:attribute name="lwcComponentName" type="String" access="global" />
  <aura:handler name="change" value="{!v.lwcComponentName}" action="{!c.loadComponent}" />
  <aura:attribute name="container" type="Aura.Component[]" default="[]" />
  {!v.container}
</aura:component>

({
  loadComponent: function(component, event, helper) {
    $A.createComponent(
      component.get("v.lwcComponentName"),
      {
        recordId: component.get("v.recordId"),
        codigoSolicitud: component.get("v.codigoSolicitud")
      },
      function(newComponent, status, errorMessage) {
        if(status === "SUCCESS") {
          component.set("v.container", newComponent);
        }
        if(status === "INCOMPLETE") {
          // Offline error
        }
        if(status === "ERROR") {
          // Error
        }
      }
    );
  }
})

Note: do not specify an attribute of recordId when you're using force:hasRecordId. This can cause undesirable behavior in some cases.

You must log in to answer this question.