Skip to content

Commit

Permalink
Merge pull request #505 from vlocityinc/patch_js
Browse files Browse the repository at this point in the history
Fix for OmniScript Activation with jsRemote failing because of Winter…
  • Loading branch information
Adam Rutland authored Sep 16, 2022
2 parents d784a5e + 050a16a commit aa27714
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 32 deletions.
21 changes: 21 additions & 0 deletions lib/datapacksutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
64 changes: 35 additions & 29 deletions lib/datapacktypes/omniscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 12 additions & 3 deletions lib/datapacktypes/vlocityuitemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit aa27714

Please sign in to comment.