Creates a deployment for a script with a new script ID using script

The Following function can be used for creating a new deployment for a script with a new script ID.

/**
 * Creates a deployment for a script with a new script ID.
 * @param {string} deploymentInternalId - The internal ID of the existing deployment.
 * @param {string} newScriptId - The new script ID for the deployment.
 * @returns {Object} An object containing the new deployment ID and any error message.
 */
function createDeployment(deploymentInternalId, newScriptId) {
  log.debug('Creating deployment', 'Id: ' + newScriptId);
  var newDeploymentId = '';

  try {
    var deploymentRec = record.copy({
      type: record.Type.SCRIPT_DEPLOYMENT,
      id: deploymentInternalId
    });

    deploymentRec.setValue('scriptid', newScriptId);
    deploymentRec.setValue('status', 'NOTSCHEDULED');

    var newDeploymentInternalId = deploymentRec.save();
    newDeploymentId = 'customdeploy' + newScriptId;

    log.debug('New deployment script id', newDeploymentInternalId + ' - ' + newDeploymentId);
  } catch (ex) {
    log.error('Error creating deployment', ex.message);
    return { deploymentId: '', error: ex.message };
  }

  return { deploymentId: newDeploymentId, error: null };
}

Leave a comment

Your email address will not be published. Required fields are marked *