Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

As a flow designer, you would want to execute your business logic while executing the Flow studio. In such cases, you can use the Custom Control in the Flow Studio to literally come out of the Flow Studio flow and execute your business logic defined in the function node in the Experience Designer.

If you want to continue the Flow Studio flow after executing the Custom Control, you have to connect the output from the function node to the Flow Manager node in the Experience Designer as shown in the screenshot below.

When execution reaches a Flow Studio Flow's Custom control, Orbita directs the response to the 3rd pin of the Flow Manager node in Experience Designer. (See Flow Manager Node documentation for more information.)

When you drag the Custom control to the Flow Studio canvas, you can see a name field and the control's ID. In Experience Designer, developers can write code that executes when the Custom control is reached.

As a Flow Studio designer, you must make a note of the Custom control's ID and the Name displayed on the dialog.

The value of the control ID and Name are available in the msg object atmsg.payload.session.attributes.orbitaSession.flowInfo.controlId and msg.payload.session.attributes.orbitaSession.flowInfo.controlName respectively.

Using Custom Control ID for hook data

Below is a sample script evaluating the Custom control ID and dispatching accordingly.

var controlId = msg.payload.session.attributes.orbitaSession.flowInfo.controlId;
switch(controlId) 
{
    case "727728496933425673":
         return [msg, null];
    case "697728492533472789":
         return [null, msg];
// etc
}

This process can be used to perform a simple calculation, or dispatch control to an entirely separate Flow Studio Flow or survey.

See the following video for a detailed explanation.

Using a Custom Control Name for hook data

You can also configure your logic for a Custom Control based on its Name.

The below code will enable the hook to fire the custom logic based on the Custom Control Name.

try {
    const controlId = msg.payload.session.attributes.orbitaSession.flowInfo.controlId,
    controlName = msg.payload.session.attributes.orbitaSession.flowInfo.controlName,
    hookName = controlName.indexOf(":") > - 1 ? controlName.substr(0, controlName.indexOf(":")) : controlName,
    args = [msg];
    
    if (hookName) {
        const hook = global.get("hooks")[hookName];
        
        msg.hookResult = {
            hookFound: !!hook
        };
        if (hook) {
            hook.apply(null, args);
        } else {
            msg.hookResult.executionSuccess = false;
            msg.hookResult.error = `Could not find hook ${hookName}`;
        
            node.warn(`Could not find hook ${hookName}`);
        
            return msg;
        }
    } else {
        msg.hookResult.executionSuccess = false;
        msg.hookResult.error = `Could not get hook name from controlId ${controlId}`;
    
        node.warn(`Could not get hook name from controlId ${controlId}`);
    
        return msg;
    }
} catch (error) {
    msg.hookResult.executionSuccess = false;
    msg.hookResult.error = error;
    
    node.warn(`Error executing hook`);
    node.warn(error);
    
    return msg;
}

You can create a custom logic how it will be

  • No labels