Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
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 ID'sIDs and put them into CSVcomma-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

Code Block
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;
  }
}