@@ -420,48 +420,54 @@ OmniScript.prototype.onActivateError = async function (dataPackData) {
420420 var currentOmniScriptId = dataPackData . dataPacks [ 0 ] . VlocityDataPackRecords [ 0 ] . VlocityRecordSalesforceId ;
421421
422422 if ( currentOmniScriptId && omniScriptDataPack [ this . osFieldMap ( `${ defaultNS } IsReusable__c` ) ] ) {
423+ var searchKey = `${ omniScriptDataPack [ this . osFieldMap ( `${ defaultNS } Type__c` ) ] } |${ omniScriptDataPack [ this . osFieldMap ( `${ defaultNS } SubType__c` ) ] } |${ omniScriptDataPack [ this . osFieldMap ( `${ defaultNS } Language__c` ) ] } ` ;
423424
424- if ( ! this . vlocity . sfdxUsername && ! this . vlocity . oauthConnection ) {
425- VlocityUtils . log ( 'Skipping Individual Activation because using SFDX Authentication is required' ) ;
426- } else {
427- var searchKey = `${ omniScriptDataPack [ this . osFieldMap ( `${ defaultNS } Type__c` ) ] } |${ omniScriptDataPack [ this . osFieldMap ( `${ defaultNS } SubType__c` ) ] } |${ omniScriptDataPack [ this . osFieldMap ( `${ defaultNS } Language__c` ) ] } ` ;
425+ VlocityUtils . verbose ( 'Handling Reusable OmniScript Activation Directly' , searchKey )
426+
427+ var resultOfActivate = await this . vlocity . datapacksutils . activateOmniScript ( currentOmniScriptId ) ;
428428
429- VlocityUtils . verbose ( 'Handling Reusable OmniScript Activation Directly' , searchKey )
430-
431- var resultOfActivate = await this . vlocity . datapacksutils . jsRemote ( `${ this . vlocity . namespace } .EmbeddingBusinessProcessController` , 'activateScript' , [ currentOmniScriptId , 1 ] , `${ this . vlocity . namespace } __embeddingbusinessprocesspage` ) ;
429+ try {
430+ if ( typeof resultOfActivate == "string" ) {
431+ resultOfActivate = JSON . parse ( resultOfActivate ) ;
432+ }
433+ } catch ( e ) {
434+ throw resultOfActivate ;
435+ }
432436
433- if ( resultOfActivate && resultOfActivate [ 0 ] . statusCode >= 300 ) {
434- VlocityUtils . error ( 'Error Activating OmniScript' , resultOfActivate [ 0 ] . message ) ;
437+ if ( resultOfActivate . errorCode != "INVOKE-200" ) {
438+ VlocityUtils . error ( 'Error Activating OmniScript' , resultOfActivate . error ) ;
435439
436- onActivateErrorResult . ActivationStatus = 'Error' ;
437- onActivateErrorResult . message = resultOfActivate [ 0 ] . message ;
440+ onActivateErrorResult . ActivationStatus = 'Error' ;
441+ onActivateErrorResult . message = resultOfActivate . error ;
438442
439- return onActivateErrorResult ;
440- }
443+ return onActivateErrorResult ;
444+ }
441445
442- 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` ) ) ;
446+ 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` ) ) ;
447+
448+ for ( var i = 0 ; i < reusableOmnis . records . length ; i ++ ) {
443449
444- for ( var i = 0 ; i < reusableOmnis . records . length ; i ++ ) {
445-
446- 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` ) ;
450+ var activationResult = await this . vlocity . datapacksutils . activateOmniScript ( reusableOmnis . records [ i ] [ this . osFieldMap ( `${ this . vlocity . namespacePrefix } OmniScriptId__c` ) ] ) ;
447451
448- if ( activationResult && activationResult instanceof Array ) {
449- activationResult = activationResult [ 0 ] ;
450- } else if ( activationResult && typeof ( activationResult ) === 'string' ) {
452+ try {
453+ if ( typeof activationResult == "string" ) {
451454 activationResult = JSON . parse ( activationResult ) ;
452455 }
453-
454- if ( activationResult . statusCode < 400 ) {
455- onActivateErrorResult . ActivationStatus = 'Success' ;
456- } else {
457- onActivateErrorResult . ActivationStatus = 'Error' ;
458- onActivateErrorResult . message = activationResult . message ;
459- break ;
460- }
456+ } catch ( e ) {
457+ throw activationResult ;
461458 }
462459
463- return onActivateErrorResult ;
460+ if ( activationResult . errorCode == "INVOKE-200" ) {
461+ onActivateErrorResult . ActivationStatus = 'Success' ;
462+ } else {
463+ onActivateErrorResult . ActivationStatus = 'Error' ;
464+ onActivateErrorResult . message = activationResult . error ;
465+ break ;
466+ }
464467 }
468+
469+ return onActivateErrorResult ;
470+
465471 }
466472
467473 return null ;
0 commit comments