/
Example Incoming Webhook Functions for Browser Extension

Example Incoming Webhook Functions for Browser Extension

Here’s some sample webhook functions that would be executed once the webhook sent by the extension is received in FlexDeploy. These examples are specific to the context of the browser extension, but check out the incoming webhook function samples for more general ideas of what’s possible with incoming webhook functions. Also, see the reference page for the context variables and methods available.

APEX - Build Application

Create at /extension/apex or whatever webhook URI you defined in your browser extension action.

This script builds each APEX application passed in the payload against a set environment. The project is sourced from App Builder, so the branch is irrelevant here

def functionName = "Build APEX Application"; LOG.info("Running function: ${functionName}"); if ("Build Application(s)".equals(PAYLOAD.actionName)) { for (def application in PAYLOAD.properties["Application Names"]) { def projectId = FLEXDEPLOY.findProjectId(application); def branchId = FLEXDEPLOY.findBranchId(projectId, "main"); FLEXDEPLOY.buildProject(branchId, projectId, "DEV") } }

ORDS - Export Module

Create at /extension/ords or whatever webhook URI you defined in your browser extension action.

def functionName = "ORDS Export Module"; LOG.info("Running function: ${functionName}"); if ('Export ORDS Module'.equals(PAYLOAD.actionName)) { def moduleNames = PAYLOAD.properties['Module Names']; def module = moduleNames[0]; def projectId = FLEXDEPLOY.findProjectId(module[0].concat(' REST')); def branchId = FLEXDEPLOY.findBranchId(projectId, 'trunk'); LOG.setMessage('Building project ${projectId}'); FLEXDEPLOY.buildProject(branchId, projectId); }

OIC - Export Integrations

Create at /extension/oic or whatever webhook URI you defined in your browser extension action.

import flexagon.fd.model.pojos.workflowrequest.ExecuteOptions; import flexagon.fd.model2.pojo.CodeValueInputPOJO; def functionName = "Export OIC Integrations"; LOG.info("Running function: ${functionName}"); // make sure to name your action this, or to change what's its checking for here. if ("Export OIC".equals(PAYLOAD.actionName)) { def objectType = PAYLOAD.properties["Object Type"] if ("Integrations".equals(objectType)) { // find all the given integrations and put them into comma-separated list def builder = new StringBuilder(); def integrations = PAYLOAD.properties["Objects"].findAll()[0]; for (def integration in integrations) { builder.append(integration); builder.append(","); } // Give the list as a workflow input ExecuteOptions eo = new ExecuteOptions(); def integrationListInput = new CodeValueInputPOJO("INTEGRATION_LIST", builder.toString()); eo.setWorkflowInputs([integrationListInput]); // execute the utility project that will export the integrations and save them to SCM. Project ID is hardcoded here, since there is only 1 project. FLEXDEPLOY.executeUtility(24945992, "DEV", eo); } }

Salesforce - Commit Files and Build Package

Create at /extension/salesforce or whatever webhook URI you defined in your browser extension action.

import flexagon.fd.model2.exceptions.FlexDeployConstraintViolationException; import flexagon.fd.model.pojos.project.ProjectPackagePojo; def functionName = "Commit Files and Build Package"; LOG.info("Running function: ${functionName}"); def fileType = PAYLOAD.properties["File Type"].findAll()[0]; def file = PAYLOAD.properties["File Name"].findAll(); def packageName = PAYLOAD.properties["Add to Package"].findAll()[0]; def committer = PAYLOAD.properties["User"].findAll()[0]; def commitMessage = PAYLOAD.properties["Message"].findAll()[0]; fileType = fileType.replace(' ' , '').replace(':' , ''); // create package in case it doesn't already exist def application = "<Salesforce Application>" LOG.info("Project Name: ${application}"); def projectId = FLEXDEPLOY.findProjectId(application); tryCreatePackage(projectId, packageName, "New package from extension"); def projectPackage = FLEXDEPLOY.getPackage(projectId, packageName) // commit and discover new file def branchId = FLEXDEPLOY.findBranchId(projectId, "main") LOG.info("Discovering Files..") SALESFORCE.discoverFilesAndCommit(projectId, branchId, packageName, committer, commitMessage, fileType, file); LOG.info("Discover Complete.") // add file to package LOG.info("Adding files - ${files}"); FLEXDEPLOY.addFilesToPackage(projectId, packageName, file) // build package def projectPackagePojo = new ProjectPackagePojo(projectId, packageName, null); LOG.info("Building Package : ${projectPackage}"); FLEXDEPLOY.buildPackage(branchId,projectPackagePojo); // create package def tryCreatePackage(projectId, name, description) { try { LOG.info("Attempting to create package ${name}."); def packageId = FLEXDEPLOY.createPackage(projectId, name, description, []); LOG.info("Package doesn't exist. Created package ${name}. Id = ${packageId}"); } catch(FlexDeployConstraintViolationException e) { // flexagon.fd.model2.exceptions.FlexDeployConstraintViolationException: FDML-99007: Package with same name already exists for the project. if(e.getMessage().contains('Package with same name')){ LOG.warning("Package ${name} exists.. continuing."); } else throw e; } }

OTBI - Download WebCatalog Items

Create at /extension/otbi or whatever webhook URI you defined in your browser extension action.

  • Use the below sample code for the incoming webhooks from Browser Extension to call the Utility project to download OTBI objects and commit to git.

  • You can download a Folder or specific WebCatalog items.

  • Use the sample Utility workflow from Automate check-in of development OTBI catalog items to SCM

import flexagon.fd.model.pojos.workflowrequest.ExecuteOptions; import flexagon.fd.model2.pojo.CodeValueInputPOJO; import flexagon.fd.model.pojos.project.ProjectPackagePojo; import org.apache.commons.lang3.StringUtils; //Execute FLEXDEPLOY functions on an incoming webhook message LOG.info("Running function: ${FUNCTION_NAME}"); def selectedOtbiFolder = PAYLOAD.properties["Current Folder"].findAll()[0]; // def builder = new StringBuilder(); def selectedObjectNames = PAYLOAD.properties["Object Names"].findAll()[0]; def objectPathCsv = ""; if (selectedObjectNames != null && selectedObjectNames.size() > 0 ) { def otbiObjects = new ArrayList(); for (objectName in selectedObjectNames) { def obj = selectedOtbiFolder + "/" + objectName; otbiObjects.add(obj); } objectPathCsv = StringUtils.join(otbiObjects, ","); } else { // if no files selected, download for the selected folder objectPathCsv = selectedOtbiFolder; } ExecuteOptions eo = new ExecuteOptions(); def otbiWCPathsInput = new CodeValueInputPOJO("INPUT_WEB_CATALOG_ITEMS", objectPathCsv); eo.setWorkflowInputs([otbiWCPathsInput]); LOG.info("Sync OTBI Objects ${objectPathCsv} to Git") // Utility project for OTBI FLEXDEPLOY.executeUtility(140200332L, "DEV", eo);

OBI - Download WebCatalog Items

Create at /extension/obi or whatever webhook URI you defined in your browser extension action.

import flexagon.fd.model.pojos.workflowrequest.ExecuteOptions; import flexagon.fd.model2.pojo.CodeValueInputPOJO; import flexagon.fd.model.pojos.project.ProjectPackagePojo; import org.apache.commons.lang3.StringUtils; //Execute FLEXDEPLOY functions on an incoming webhook message LOG.info("Running function: ${FUNCTION_NAME}"); def selectedOtbiFolder = PAYLOAD.properties["Current Folder"].findAll()[0]; // def builder = new StringBuilder(); def selectedObjectNames = PAYLOAD.properties["Object Names"].findAll()[0]; def objectPathCsv = ""; if (selectedObjectNames != null && selectedObjectNames.size() > 0 ) { def otbiObjects = new ArrayList(); for (objectName in selectedObjectNames) { def obj = selectedOtbiFolder + "/" + objectName; otbiObjects.add(obj); } objectPathCsv = StringUtils.join(otbiObjects, ","); } else { // if no files selected, download for the selected folder objectPathCsv = selectedOtbiFolder; } ExecuteOptions eo = new ExecuteOptions(); def otbiWCPathsInput = new CodeValueInputPOJO("INPUT_WEB_CATALOG_ITEMS", objectPathCsv); eo.setWorkflowInputs([otbiWCPathsInput]); LOG.info("Sync OBI Objects ${objectPathCsv} to Git") // Utility project for OTBI FLEXDEPLOY.executeUtility(140200332L, "DEV", eo);

OBI - Export WebCatalog Items Using Package Project

  • The project id can be OTBI/OBI or OAC projects.

import flexagon.fd.model.pojos.workflowrequest.ExecuteOptions; import flexagon.fd.model2.pojo.CodeValueInputPOJO; import flexagon.fd.model.pojos.project.ProjectPackagePojo; import flexagon.fd.model.pojos.workflowrequest.BuildOptions; import flexagon.fd.model.pojos.workflowrequest.PackageSearchOptions; def selectedOtbiFolder = PAYLOAD.properties["Current Folder"].findAll()[0]; def selectedObjectNames = PAYLOAD.properties["Object Names"].findAll()[0]; List<ProjectPackagePojo> packages = null; PackageSearchOptions options = new PackageSearchOptions(); options.setActivePackage(true) options.setProjectSCMType(flexagon.fd.core.enums.SCMTypeEnum.NONE) if (selectedObjectNames != null && selectedObjectNames.size() > 0) { List otbiObjects = new ArrayList<>() for (def objectName in selectedObjectNames) { otbiObjects.add(selectedOtbiFolder + "/" + objectName) } LOG.info("Sync OTBI Objects: ${otbiObjects.toString()}") packages = FLEXDEPLOY.findProjectPackagesForFilesByProjectId(140200165L,otbiObjects, options) } else { LOG.info("No files selected, find dynamic packages using selected folder path") options.setPackageType("DYNAMIC") options.setIncludePath(selectedOtbiFolder +"/.*") packages = FLEXDEPLOY.findProjectPackagesForFilesByProjectId(140200165L, null, options) } if(packages != null && packages.size() > 0) { // using the first project package from the list def packagePojo = packages.get(0) Long projectId = packagePojo.getProjectId() LOG.info("Found project ${projectId}, package ${packagePojo}") // using main branch. if branch name is master use master Long branchId = FLEXDEPLOY.findBranchId(projectId,"main") LOG.info("Submitting build for project ${projectId}, package ${packagePojo.getPackageName()}") BuildOptions bo = new BuildOptions() // using default DEV environment bo.setEnvironmentCode("DEV") FLEXDEPLOY.buildPackage(branchId,packagePojo, bo); } else { LOG.info("No packages found for the incoming files") }

Azure Power BI - Export Contents Using Utility Project

import flexagon.fd.model.pojos.workflowrequest.ExecuteOptions; import flexagon.fd.model2.pojo.CodeValueInputPOJO; import flexagon.fd.model.pojos.project.ProjectPackagePojo; LOG.info("Running function: ${FUNCTION_NAME}"); def selectedObjectNames = PAYLOAD.properties["Object Names"].findAll().getAt(0); def workspaceName = PAYLOAD.properties["Current Workspace"].findAll().getAt(0); def workspace = workspaceName; ExecuteOptions eo = new ExecuteOptions(); def workflowInputs = []; if (selectedObjectNames instanceof List) { selectedObjectNames.each { objectName -> workflowInputs.add(new CodeValueInputPOJO("INPUT_REPORT_NAME", objectName)); } } else { workflowInputs.add(new CodeValueInputPOJO("INPUT_REPORT_NAME", selectedObjectNames)); } workflowInputs.add(new CodeValueInputPOJO("INPUT_WORKSPACE_NAME", workspace)); eo.setWorkflowInputs(workflowInputs); FLEXDEPLOY.executeUtility(PROJECT_ID, "DEV", eo);

Related content

The following macros are not currently supported in the footer:
  • style