@@ -1814,13 +1814,26 @@ DataPacksJob.prototype.deployDataPackMetadataConfigurations = async function(pat
18141814 }
18151815} ;
18161816
1817+ DataPacksJob . prototype . ensureDocumentExists = async function ( ) {
1818+
1819+ var query = `Select Id from Document LIMIT 1` ;
1820+ let result = await this . vlocity . jsForceConnection . query ( query ) ;
1821+
1822+ if ( ! result . records || result . records . length == 0 ) {
1823+ VlocityUtils . verbose ( 'Adding Default Document to Org as it affects LWC Compilation and OmniScript Runtime' ) ;
1824+ await this . vlocity . datapacksutils . runApex ( '.' , 'AddDocument.cls' ) ;
1825+ }
1826+ }
1827+
18171828DataPacksJob . prototype . updateSettings = async function ( jobInfo ) {
18181829 var projectPathsToDeploy = [ 'latest' ] ;
18191830
18201831 if ( ! this . vlocity . organizationId ) {
18211832 return ;
18221833 }
18231834
1835+ await this . ensureDocumentExists ( ) ;
1836+
18241837 if ( this . vlocity . isOmniStudioInstalled && ! this . vlocity . isOmniStudioIndustryInstalled ) {
18251838 return ;
18261839 }
@@ -2061,52 +2074,57 @@ DataPacksJob.prototype.activateAll = async function(dataPack, jobInfo, attempts)
20612074
20622075 var shouldRetry = false ;
20632076
2064- for ( var dataPack of dataPackData . dataPacks ) {
2065- if ( dataPack . ActivationStatus == 'Activated' || allActivated . includes ( dataPack . VlocityDataPackKey ) ) {
2066- await this . vlocity . datapacksutils . handleDataPackEvent ( 'afterActivationSuccess' , dataPack . VlocityDataPackType , { dataPack : dataPack , jobInfo : jobInfo } ) ;
2067- } else if ( dataPack . ActivationStatus == 'Ready' && dataPack . VlocityDataPackStatus == 'Success' ) {
2068-
2069- // If it is the only one in the deploy and it fails to activate it must be set to error. Otherwise retry the deploy and activation separate from others.
2070- if ( dataPackData . dataPacks . length == 1 ) {
2071- var onActivateErrorResult = await this . vlocity . datapacksutils . handleDataPackEvent ( 'onActivateError' , dataPack . VlocityDataPackType , dataPackData ) ;
2072-
2073- var errorMessage = ' --- Not Activated' ;
2074-
2075- if ( onActivateErrorResult ) {
2076- if ( onActivateErrorResult . ActivationStatus === 'Success' ) {
2077- continue ;
2077+ if ( ! dataPackData . dataPacks ) {
2078+ shouldRetry = attempts < 3 ;
2079+ attempts ++ ;
2080+ } else {
2081+ for ( var dataPack of dataPackData . dataPacks ) {
2082+ if ( dataPack . ActivationStatus == 'Activated' || allActivated . includes ( dataPack . VlocityDataPackKey ) ) {
2083+ await this . vlocity . datapacksutils . handleDataPackEvent ( 'afterActivationSuccess' , dataPack . VlocityDataPackType , { dataPack : dataPack , jobInfo : jobInfo } ) ;
2084+ } else if ( dataPack . ActivationStatus == 'Ready' && dataPack . VlocityDataPackStatus == 'Success' ) {
2085+
2086+ // If it is the only one in the deploy and it fails to activate it must be set to error. Otherwise retry the deploy and activation separate from others.
2087+ if ( dataPackData . dataPacks . length == 1 ) {
2088+ var onActivateErrorResult = await this . vlocity . datapacksutils . handleDataPackEvent ( 'onActivateError' , dataPack . VlocityDataPackType , dataPackData ) ;
2089+
2090+ var errorMessage = ' --- Not Activated' ;
2091+
2092+ if ( onActivateErrorResult ) {
2093+ if ( onActivateErrorResult . ActivationStatus === 'Success' ) {
2094+ continue ;
2095+ }
2096+
2097+ errorMessage = ' --- ' + onActivateErrorResult . message ;
2098+ } else if ( allActivationErrors [ dataPack . VlocityDataPackKey ] ) {
2099+ errorMessage = ' --- ' + allActivationErrors [ dataPack . VlocityDataPackKey ] ;
20782100 }
2079-
2080- errorMessage = ' --- ' + onActivateErrorResult . message ;
2081- } else if ( allActivationErrors [ dataPack . VlocityDataPackKey ] ) {
2082- errorMessage = ' --- ' + allActivationErrors [ dataPack . VlocityDataPackKey ] ;
2101+
2102+ jobInfo . hasError = true ;
2103+ jobInfo . currentStatus [ dataPack . VlocityDataPackKey ] = 'Error' ;
2104+ jobInfo . currentErrors [ dataPack . VlocityDataPackKey ] = 'Activation Error >> ' + dataPack . VlocityDataPackKey + errorMessage ;
2105+ jobInfo . errors . push ( 'Activation Error >> ' + dataPack . VlocityDataPackKey + errorMessage ) ;
2106+ VlocityUtils . error ( 'Activation Error' , dataPack . VlocityDataPackKey + errorMessage ) ;
2107+
2108+ } else if ( attempts < 3 ) {
2109+ shouldRetry = true ;
2110+ } else {
2111+ jobInfo . currentStatus [ dataPack . VlocityDataPackKey ] = 'ReadySeparate' ;
20832112 }
2084-
2113+ } else if ( dataPack . ActivationStatus == 'Error' ) {
2114+
2115+ var message = 'Activation Error >> ' + dataPack . VlocityDataPackKey + ' --- ' + ( dataPack . VlocityDataPackMessage ? dataPack . VlocityDataPackMessage : ( activateResult . error != 'OK' ? activateResult . error : '' ) ) ;
2116+
20852117 jobInfo . hasError = true ;
20862118 jobInfo . currentStatus [ dataPack . VlocityDataPackKey ] = 'Error' ;
2087- jobInfo . currentErrors [ dataPack . VlocityDataPackKey ] = 'Activation Error >> ' + dataPack . VlocityDataPackKey + errorMessage ;
2088- jobInfo . errors . push ( 'Activation Error >> ' + dataPack . VlocityDataPackKey + errorMessage ) ;
2089- VlocityUtils . error ( 'Activation Error' , dataPack . VlocityDataPackKey + errorMessage ) ;
2090-
2091- } else if ( attempts < 3 ) {
2092- shouldRetry = true ;
2093- } else {
2094- jobInfo . currentStatus [ dataPack . VlocityDataPackKey ] = 'ReadySeparate' ;
2095- }
2096- } else if ( dataPack . ActivationStatus == 'Error' ) {
2097-
2098- var message = 'Activation Error >> ' + dataPack . VlocityDataPackKey + ' --- ' + ( dataPack . VlocityDataPackMessage ? dataPack . VlocityDataPackMessage : ( activateResult . error != 'OK' ? activateResult . error : '' ) ) ;
2099-
2100- jobInfo . hasError = true ;
2101- jobInfo . currentStatus [ dataPack . VlocityDataPackKey ] = 'Error' ;
2102-
2103- jobInfo . currentErrors [ dataPack . VlocityDataPackKey ] = message ;
2104-
2105- if ( jobInfo . errors . indexOf ( message ) == - 1 ) {
2106- jobInfo . errors . push ( message ) ;
2119+
2120+ jobInfo . currentErrors [ dataPack . VlocityDataPackKey ] = message ;
2121+
2122+ if ( jobInfo . errors . indexOf ( message ) == - 1 ) {
2123+ jobInfo . errors . push ( message ) ;
2124+ }
2125+
2126+ VlocityUtils . error ( 'Activation Error' , dataPack . VlocityDataPackKey , dataPack . VlocityDataPackMessage ? dataPack . VlocityDataPackMessage : ( activateResult . error != 'OK' ? activateResult . error : '' ) ) ;
21072127 }
2108-
2109- VlocityUtils . error ( 'Activation Error' , dataPack . VlocityDataPackKey , dataPack . VlocityDataPackMessage ? dataPack . VlocityDataPackMessage : ( activateResult . error != 'OK' ? activateResult . error : '' ) ) ;
21102128 }
21112129 }
21122130
@@ -2364,6 +2382,18 @@ DataPacksJob.prototype.deployPack = async function(inputMap) {
23642382 var stepPostDeployResults = [ ] ;
23652383 let dataPackData = await this . vlocity . datapacks . getDataPackData ( dataPackId ) ;
23662384
2385+ if ( ! dataPackData . dataPacks ) {
2386+ VlocityUtils . error ( "Error Fetching DataPack Data" , result . VlocityDataPackId , allDeploymentKeys ) ;
2387+ allDeploymentKeys . forEach ( key => {
2388+ jobInfo . hasError = true ;
2389+ jobInfo . currentStatus [ key ] = 'Error' ;
2390+ jobInfo . currentErrors [ dataPack . VlocityDataPackKey ] = `${ key } - Error Fetching DataPack Data` ;
2391+ jobInfo . errors . push ( `${ key } - ${ result . message } ` ) ;
2392+ } ) ;
2393+
2394+ return ;
2395+ }
2396+
23672397 for ( var dataPack of dataPackData . dataPacks ) {
23682398 var objectName = self . vlocity . datapacksutils . getBulkJobObjectName ( dataPack . VlocityDataPackType ) ;
23692399 var objectKey = self . vlocity . datapacksutils . getBulkJobObjectKey ( dataPack . VlocityDataPackType ) ;
@@ -2707,10 +2737,16 @@ DataPacksJob.prototype.deployJob = async function(jobInfo) {
27072737
27082738 // Ensure there is a sfdx-project.json file
27092739 this . vlocity . datapacksutils . getSFDXProject ( { ...jobInfo , sfdxForcePath : tempSfdxLwcFolder } ) ;
2710-
2711- // Deploy using sfdx
2712- const deployGeneratedLwcFolder = await this . vlocity . utilityservice . sfdx ( 'source:deploy' , tempDeployOptions ) ;
2713- jobInfo . currentStatus = Object . assign ( jobInfo . currentStatus , this . vlocity . datapacksutils . formatSalesforceDeployResponse ( deployGeneratedLwcFolder ) ) ;
2740+ try {
2741+ // Deploy using sfdx
2742+ const deployGeneratedLwcFolder = await this . vlocity . utilityservice . sfdx ( 'source:deploy' , tempDeployOptions ) ;
2743+ jobInfo . currentStatus = Object . assign ( jobInfo . currentStatus , this . vlocity . datapacksutils . formatSalesforceDeployResponse ( deployGeneratedLwcFolder ) ) ;
2744+ } catch ( err ) {
2745+ VlocityUtils . log ( err ) ;
2746+ jobInfo . errors . push ( "OmniScript or FlexCard Compilation Failed:\n" + JSON . stringify ( err , null , 2 ) ) ;
2747+ jobInfo . hasError = true ;
2748+ }
2749+
27142750 } else {
27152751 VlocityUtils . error ( 'Can\'t find compiled LWC components path. Skipping...' ) ;
27162752 }
0 commit comments