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

Version 1 Current »

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

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 streamId = FLEXDEPLOY.findStreamId(projectId, "main");
    FLEXDEPLOY.buildProject(streamId, projectId, "DEV")
  }
}

ORDS - Export Module

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 streamId = FLEXDEPLOY.findStreamId(projectId, 'trunk');
  LOG.setMessage('Building project ${projectId}');
  FLEXDEPLOY.buildProject(streamId, projectId);
}

OIC - Export Integrations

import flexagon.fd.model.pojos.workflowrequest.ExecuteOptions;
import flexagon.fd.model2.pojo.CodeValueInputPOJO;

def functionName = "Export OIC Extensions"; 
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)) 
{ 
  // find all the given IDs and put them into comma-separated list
  def builder = new StringBuilder();
  def integrationIds = PAYLOAD.properties["Integration IDs"].findAll()[0];
  
  for (def integration in integrationIds) 
  { 
    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

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 streamId = FLEXDEPLOY.findStreamId(projectId, "main")
LOG.info("Discovering Files..")
SALESFORCE.discoverFilesAndCommit(projectId, streamId, 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(streamId,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;
  }
}
  • No labels