Skip to content

Commit

Permalink
Merge pull request #630 from vlocityinc/beta
Browse files Browse the repository at this point in the history
W-14563678 omniout js update for OmniStudio enabled orgs.
  • Loading branch information
manas-sf authored Dec 11, 2023
2 parents 09b5154 + aab5984 commit 88bd2e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
20 changes: 12 additions & 8 deletions javascript/lwcOmniOutRetrieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = async function(vlocity, currentContextData, jobInfo, callback)
if(jobInfo.queries.length > 0) {
for (const element of jobInfo.queries) {
if(element.VlocityDataPackType === 'OmniScript') {
var query = element.query.replace(/%vlocity_namespace%/g, vlocity.namespace);
var query = vlocity.omnistudio.updateQuery(element.query).replace(/%vlocity_namespace%/g, vlocity.namespace);
}
}
}
Expand All @@ -26,24 +26,28 @@ module.exports = async function(vlocity, currentContextData, jobInfo, callback)

var body = {
sClassName: 'Vlocity BuildJSONWithPrefill',
sType: record[vlocity.namespace + '__Type__c'],
sSubType: record[vlocity.namespace + '__SubType__c'],
sLang: record[vlocity.namespace + '__Language__c']
sType: record[vlocity.namespace + '__Type__c'] || record['Type'],
sSubType: record[vlocity.namespace + '__SubType__c'] || record['SubType'],
sLang: record[vlocity.namespace + '__Language__c'] || record['Language']
};

vlocity.jsForceConnection.apex.post('/' + vlocity.namespace + '/v1/GenericInvoke/', body, async function(err, prefilledJson) {
if (err) { return console.error(err); }

if (!record[vlocity.namespace + '__Type__c'] || !record[vlocity.namespace + '__SubType__c'] || !record[vlocity.namespace + '__Language__c']) return;
if (!vlocity.isOmniStudioInstalled && (!record[vlocity.namespace + '__Type__c'] || !record[vlocity.namespace + '__SubType__c'] || !record[vlocity.namespace + '__Language__c']) ||
vlocity.isOmniStudioInstalled && (! record['Type'] || ! record['SubType'] || ! record['Language'])
) return;

vlocity.datapacksexpand.targetPath = jobInfo.projectPath + '/' + jobInfo.expansionPath;

listOfCustomLwc = await extractLwcDependencies(JSON.parse(prefilledJson) || {});

let lwcname = vlocity.isOmniStudioInstalled ? (record['Type'] + record['SubType'] + record['Language']) : record[vlocity.namespace + '__Type__c']+record[vlocity.namespace + '__SubType__c']+record[vlocity.namespace + '__Language__c'];
// add the OmniScript itself
const currentOmniScriptLwc = await fetchOmniOutContents(record[vlocity.namespace + '__Type__c']+record[vlocity.namespace + '__SubType__c']+record[vlocity.namespace + '__Language__c'], vlocity);
const currentOmniScriptLwc = await fetchOmniOutContents(lwcname, vlocity);
const parsedOmniScriptRes = await extractSources(currentOmniScriptLwc['compositeResponse'][1]['body']['records'], vlocity.namespace);
await createFiles(parsedOmniScriptRes, vlocity, 'modules', `vlocityomniscript/${record[vlocity.namespace + '__Type__c']+record[vlocity.namespace + '__SubType__c']+record[vlocity.namespace + '__Language__c']}`);

await createFiles(parsedOmniScriptRes, vlocity, 'modules', `vlocityomniscript/${lwcname}`);

// add all custom LWCs as well
for (const element of listOfCustomLwc) {
Expand Down Expand Up @@ -164,7 +168,7 @@ const extractSources = async (items, namespace) => {

let parsed = [];

if(items.length > 0) {
if(items?.length > 0) {
items.map(async (i) => {
let path = i['FilePath'].replace('lwc', '');

Expand Down
15 changes: 8 additions & 7 deletions javascript/omniOutRetrieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ var path = require('path');

module.exports = function(vlocity, currentContextData, jobInfo, callback) {

var query = 'Select vlocity_namespace__Type__c, vlocity_namespace__Language__c, vlocity_namespace__SubType__c from vlocity_namespace__OmniScript__c WHERE vlocity_namespace__IsActive__c = true AND vlocity_namespace__IsProcedure__c = false'.replace(/vlocity_namespace/g, vlocity.namespace);
var query = vlocity.omnistudio.updateQuery('Select %vlocity_namespace%__Type__c, %vlocity_namespace%__Language__c, %vlocity_namespace%__SubType__c from %vlocity_namespace%__OmniScript__c WHERE %vlocity_namespace%__IsActive__c = true AND %vlocity_namespace%__IsProcedure__c = false').replace(/%vlocity_namespace%/g, vlocity.namespace);

vlocity.jsForceConnection.query(query, function(err, result) {
if (err) { return console.error(err); }
async.eachSeries(result.records, function(record, seriesCallback) {

var body = {
sClassName: 'Vlocity BuildJSONWithPrefill',
sType: record[vlocity.namespace + '__Type__c'],
sSubType: record[vlocity.namespace + '__SubType__c'],
sLang: record[vlocity.namespace + '__Language__c']
sType: record[vlocity.namespace + '__Type__c'] || record['Type'],
sSubType: record[vlocity.namespace + '__SubType__c'] || record['SubType'],
sLang: record[vlocity.namespace + '__Language__c'] || record['Language']
};

vlocity.jsForceConnection.apex.post('/' + vlocity.namespace + '/v1/GenericInvoke/', body, function(err, prefilledJson) {
if (err) { return console.error(err); }

if (!record[vlocity.namespace + '__Type__c'] || !record[vlocity.namespace + '__SubType__c'] || !record[vlocity.namespace + '__Language__c']) return;

var filename = record[vlocity.namespace + '__Type__c'] + '_' + record[vlocity.namespace + '__SubType__c'] + '_' + record[vlocity.namespace + '__Language__c'];
if (!vlocity.isOmniStudioInstalled && (!record[vlocity.namespace + '__Type__c'] || !record[vlocity.namespace + '__SubType__c'] || !record[vlocity.namespace + '__Language__c']) ||
vlocity.isOmniStudioInstalled && (! record['Type'] || ! record['SubType'] || ! record['Language'])
) return;

var filename = vlocity.isOmniStudioInstalled ? (record['Type'] + record['SubType'] + record['Language']) : record[vlocity.namespace + '__Type__c']+record[vlocity.namespace + '__SubType__c']+record[vlocity.namespace + '__Language__c'];
vlocity.datapacksexpand.targetPath = jobInfo.projectPath + '/' + jobInfo.expansionPath;
var file = vlocity.datapacksexpand.writeFile('OmniOut', 'OmniOut', filename, 'json', prefilledJson, false);

Expand Down

0 comments on commit 88bd2e9

Please sign in to comment.