Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <aura:component implements="flexipage:availableForAllPageTypes" access="global">
- <aura:attribute name="recordId" type="String"/>
- <aura:attribute name="DeveloperName" type="String"/>
- <aura:attribute name="inputVariables" type="Object"/>
- <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
- <aura:registerEvent name="actionEvent" type="c:BI_LEX_GenericApprovalConfirm"/>
- <lightning:overlayLibrary aura:id="modalLib"/>
- <div class="slds-text-align_right"><lightning:buttonIcon variant="bare" iconName="utility:close" onclick="{!c.closeFlow}" size="large"/></div>
- <lightning:flow aura:id="flowData" onstatuschange="{!c.statusChange}"/>
- ({
- doInit : function(component, event, helper){
- var flow = component.find("flowData");
- flow.startFlow(component.get("v.DeveloperName"), component.get("v.inputVariables"));
- },
- closeFlow : function(component, event, helper){
- var actionEvent = $A.get("e.c:BI_LEX_GenericApprovalConfirm");
- actionEvent.setParams({
- "bypass" : false
- });
- actionEvent.fire();
- component.find("modalLib").notifyClose();
- },
- statusChange : function(component, event) {
- var result;
- var message;
- var params = {};
- var messageIndex;
- var generatedIndex;
- var generatedRecordId;
- var status = event.getParam("status");
- console.log("params: " + JSON.stringify(event.getParams()));
- debugger;
- //Contain outputVariables for generated record check
- if(event.getParams().hasOwnProperty('outputVariables')){
- var outputVariables = event.getParam("outputVariables");
- messageIndex = outputVariables.findIndex(x => x.name === 'CPQ_TxtErrorMsg');
- generatedIndex = outputVariables.findIndex(x => x.name === 'CPQ_GeneratedRecordId');
- //Error message found
- if(messageIndex !== -1 && outputVariables[messageIndex].value !== null){
- message = outputVariables[messageIndex].value;
- }
- //New record Id found
- if(generatedIndex !== -1 && outputVariables[generatedIndex].value !== null){
- generatedRecordId = outputVariables[generatedIndex].value;
- }
- }
- var actionEvent = $A.get("e.c:BI_LEX_GenericApprovalConfirm");
- switch(status){
- case 'FINISHED':
- result = message !== undefined ? false : true;
- break;
- case 'FINISHED_SCREEN':
- result = message !== undefined ? false : true;
- break;
- case 'ERROR':
- result = false;
- break;
- }
- //Finished or error found
- if(result !== undefined){
- params["bypass"] = result;
- //Related new record Id
- if(generatedRecordId !== null){
- params["generatedrecordid"] = generatedRecordId;
- }
- //Error message [default one if flow doesn't retrieve one]
- if(!result){
- params["message"] = message !== undefined ? message : $A.get("$Label.c.CPQ_LightningFlowTrouble");
- }
- console.log('***params: ' + JSON.stringify(params));
- debugger;
- actionEvent.setParams(params);
- actionEvent.fire();
- component.find("modalLib").notifyClose();
- }
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement