Architect Scripting

I am looking for a way to use architect scripting (not archy) to reuse a template flow to create more flows. Within the new flows I want to change the names of the datatables which will be dependent on the divsion in which the new flow is created. Is there any documentation which will help me 1) extract a flow 2) modify datatable names 3) publish the flow with a new name.

Hi @sankles,

Here's a script I just wrote that I believe should do what you're asking for, or at least get you closer to your end result. In this example I'm just creating a flow with a single division, but you can always add in additional logic to loop through available divisions in the org to create flows for each division.

const scripting = require('purecloud-flow-scripting-api-sdk-javascript');

const flowFactory = scripting.factories.archFactoryFlows;
const archFactoryFilters = scripting.factories.archFactoryFilters;

const session = scripting.environment.archSession;

async function scriptMain() {
    // Load up your existing flow. For this example im just using an inbound call flow
    const loadedFlow = await flowFactory.loadFlowByFlowNameAsync("MY_TEMPLATE_FLOW", scripting.enums.archEnums.FLOW_TYPES.inboundCall, 'latest');
    // export this flow to an object
    const exportedFlow = await loadedFlow.exportToObjectAsync();

    // const allDivisions = session.orgInfo.getAllDivisions() - could be used to loop through all divisions available?

    // For this example, I'm just going to lookup a single division in my org
    const archDivision = session.orgInfo.getDivisionByName('MY_DIVISION_NAME');

    // Also in this example I'm just going to create a new inbound call flow.
    const newFlow = await flowFactory.createFlowInboundCallAsync('My New Flow Name', 'my description', scripting.languages.archLanguages.englishUnitedStates, undefined, archDivision);

    // import the template flow into this new flow
    await newFlow.importFromContentAsync(exportedFlow.content);

    // create a filter object
    const filter = archFactoryFilters.createFilterObject();

    // add a clause to it to find any properties that have `isArchActionDataTableLookup` that equals `true`
    filter.addClausePropertyValueEquals('isArchActionDataTableLookup', true, true);

    // create an array to hold the data table lookup actions in the flow
    const foundDataTableActions = [];

    // traverse your newly created flow
    newFlow.traverse(traverseInfo => {
        // if we found a match object, push it onto the foundDataTableActions array
        foundDataTableActions.push(traverseInfo.matchObject);
    }, filter);

    // Then we can loop through the data table lookup actions that were found, and modify as needed
    for (const dataTableAction of foundDataTableActions) {
        await dataTableAction.setDataTableByNameAsync('MY_DATA_TABLE_NAME_BASED_ON_DIVISION');
        dataTableAction.lookupValue.setLiteralString('MY_NEW_LOOKUP_VALUE');
        // ...configure rest of properties as needed for the data table action
    }

    // validate the flow
    await newFlow.validateAsync();
    
    // publish the flow
    await newFlow.publishAsync();

    console.log('Finished!');
}

async function test() {
    session.endTerminatesProcess = true;
    // start up the architect scripting session with a Client Credentials OAuth Client that calls into the scriptMain function
    // you can get the location from scripting.enums.archEnums.LOCATIONS for example: scripting.enums.archEnums.LOCATIONS.prod_us_east_1
    await session.startWithClientIdAndSecret('LOCATION', scriptMain, 'CLIENT_ID', 'CLIENT_SECRET', undefined, true);
    console.log('Waited for client to resolve');
}

test();

And of course, the documentation for the different functions being used in this example can all be found on the Architect Scripting documentation page.

Thanks,
Jon

Thanks! this is perfect!

@sankles if you run into any issues, let me know and I can do my best to help!

- Jon

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.