diff --git a/lib/datapacksutils.js b/lib/datapacksutils.js index 17a7def6..d28a8924 100644 --- a/lib/datapacksutils.js +++ b/lib/datapacksutils.js @@ -2620,6 +2620,27 @@ DataPacksUtils.prototype.loadFilesFromDir = function(srcpath) { return this.loadedFiles; } +DataPacksUtils.prototype.activateOmniScript = async function(omniscriptId) { + var self = this; + + var payload = { + sClassName: this.vlocity.namespace + '.EmbeddingBusinessProcessController.EmbeddingBusinessProcessControllerOpen', + sMethodName: 'activateScript', + input: JSON.stringify({ + sBPId: omniscriptId, + index: 1 + }) + }; + + VlocityUtils.verbose('Activating OmniScript', omniscriptId); + + if (self.vlocity.namespace) { + payload = JSON.parse(JSON.stringify(payload).replace(/%vlocity_namespace%/g, self.vlocity.namespace)); + } + + return await this.vlocity.datapacks.makeApexPostRequest('/' + this.vlocity.namespace + '/v1/invoke/', payload); +} + DataPacksUtils.prototype.jsRemote = async function(action, method, data, page) { var body = { diff --git a/lib/datapacktypes/omniscript.js b/lib/datapacktypes/omniscript.js index 771dd656..3c7e0007 100644 --- a/lib/datapacktypes/omniscript.js +++ b/lib/datapacktypes/omniscript.js @@ -420,48 +420,54 @@ OmniScript.prototype.onActivateError = async function (dataPackData) { var currentOmniScriptId = dataPackData.dataPacks[0].VlocityDataPackRecords[0].VlocityRecordSalesforceId; if (currentOmniScriptId && omniScriptDataPack[this.osFieldMap(`${defaultNS}IsReusable__c`)]) { + var searchKey = `${omniScriptDataPack[this.osFieldMap(`${defaultNS}Type__c`)]}|${omniScriptDataPack[this.osFieldMap(`${defaultNS}SubType__c`)]}|${omniScriptDataPack[this.osFieldMap(`${defaultNS}Language__c`)]}`; - if (!this.vlocity.sfdxUsername && !this.vlocity.oauthConnection) { - VlocityUtils.log('Skipping Individual Activation because using SFDX Authentication is required'); - } else { - var searchKey = `${omniScriptDataPack[this.osFieldMap(`${defaultNS}Type__c`)]}|${omniScriptDataPack[this.osFieldMap(`${defaultNS}SubType__c`)]}|${omniScriptDataPack[this.osFieldMap(`${defaultNS}Language__c`)]}`; + VlocityUtils.verbose('Handling Reusable OmniScript Activation Directly', searchKey) + + var resultOfActivate = await this.vlocity.datapacksutils.activateOmniScript(currentOmniScriptId); - VlocityUtils.verbose('Handling Reusable OmniScript Activation Directly', searchKey) - - var resultOfActivate = await this.vlocity.datapacksutils.jsRemote(`${this.vlocity.namespace}.EmbeddingBusinessProcessController`, 'activateScript', [ currentOmniScriptId, 1], `${this.vlocity.namespace}__embeddingbusinessprocesspage`); + try { + if (typeof resultOfActivate == "string") { + resultOfActivate = JSON.parse(resultOfActivate); + } + } catch (e) { + throw resultOfActivate; + } - if (resultOfActivate && resultOfActivate[0].statusCode >= 300) { - VlocityUtils.error('Error Activating OmniScript', resultOfActivate[0].message); + if (resultOfActivate.errorCode != "INVOKE-200") { + VlocityUtils.error('Error Activating OmniScript', resultOfActivate.error); - onActivateErrorResult.ActivationStatus = 'Error'; - onActivateErrorResult.message = resultOfActivate[0].message; + onActivateErrorResult.ActivationStatus = 'Error'; + onActivateErrorResult.message = resultOfActivate.error; - return onActivateErrorResult; - } + return onActivateErrorResult; + } - let reusableOmnis = await this.vlocity.jsForceConnection.query(this.vlocity.omnistudio.updateQuery(`SELECT Id, ${this.vlocity.namespacePrefix}OmniScriptId__c FROM ${this.vlocity.namespacePrefix}Element__c WHERE ${this.vlocity.namespacePrefix}SearchKey__c = '${searchKey}' AND ${this.vlocity.namespacePrefix}OmniScriptId__r.${this.vlocity.namespacePrefix}IsActive__c = true`)); + let reusableOmnis = await this.vlocity.jsForceConnection.query(this.vlocity.omnistudio.updateQuery(`SELECT Id, ${this.vlocity.namespacePrefix}OmniScriptId__c FROM ${this.vlocity.namespacePrefix}Element__c WHERE ${this.vlocity.namespacePrefix}SearchKey__c = '${searchKey}' AND ${this.vlocity.namespacePrefix}OmniScriptId__r.${this.vlocity.namespacePrefix}IsActive__c = true`)); + + for (var i = 0; i < reusableOmnis.records.length; i++) { - for (var i = 0; i < reusableOmnis.records.length; i++) { - - var activationResult = await this.vlocity.datapacksutils.jsRemote(`${this.vlocity.namespace}.EmbeddingBusinessProcessController`, 'activateScript', [ reusableOmnis.records[i][`${this.vlocity.namespacePrefix}OmniScriptId__c`], 1], `${this.vlocity.namespacePrefix}embeddingbusinessprocesspage`); + var activationResult = await this.vlocity.datapacksutils.activateOmniScript(reusableOmnis.records[i][this.osFieldMap(`${this.vlocity.namespacePrefix}OmniScriptId__c`)]); - if (activationResult && activationResult instanceof Array) { - activationResult = activationResult[0]; - } else if (activationResult && typeof(activationResult) === 'string') { + try { + if (typeof activationResult == "string") { activationResult = JSON.parse(activationResult); } - - if (activationResult.statusCode < 400) { - onActivateErrorResult.ActivationStatus = 'Success'; - } else { - onActivateErrorResult.ActivationStatus = 'Error'; - onActivateErrorResult.message = activationResult.message; - break; - } + } catch (e) { + throw activationResult; } - return onActivateErrorResult; + if (activationResult.errorCode == "INVOKE-200") { + onActivateErrorResult.ActivationStatus = 'Success'; + } else { + onActivateErrorResult.ActivationStatus = 'Error'; + onActivateErrorResult.message = activationResult.error; + break; + } } + + return onActivateErrorResult; + } return null; diff --git a/lib/datapacktypes/vlocityuitemplate.js b/lib/datapacktypes/vlocityuitemplate.js index dcfb04a6..229180e0 100644 --- a/lib/datapacktypes/vlocityuitemplate.js +++ b/lib/datapacktypes/vlocityuitemplate.js @@ -22,10 +22,19 @@ VlocityUITemplate.prototype.onDeployFinish = async function(jobInfo) { VlocityUITemplate.prototype.activateOmniScript = async function(inputMap) { var omniscript = inputMap.omniscript; - var resultOfActivate = await this.vlocity.datapacksutils.jsRemote(`${this.vlocity.namespace}.EmbeddingBusinessProcessController`, 'activateScript', [ omniscript.Id, 1], `${this.vlocity.namespace}__embeddingbusinessprocesspage`); - if (resultOfActivate && resultOfActivate[0].statusCode >= 300) { - VlocityUtils.error('Error Re-Activating OmniScript', resultOfActivate[0].message); + var resultOfActivate = await this.vlocity.datapacksutils.activateOmniScript(omniscript.Id); + + try { + if (typeof resultOfActivate == "string") { + resultOfActivate = JSON.parse(resultOfActivate); + } + } catch (e) { + throw resultOfActivate; + } + + if (resultOfActivate.errorCode != "INVOKE-200") { + VlocityUtils.error('Error Re-Activating OmniScript', omniscript.Id, resultOfActivate); } }