@sonisoft/now-sdk-ext-core 3.8.0 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -794,60 +794,60 @@ export class FlowManager {
794
794
  }
795
795
  const hasInputs = options.inputs && Object.keys(options.inputs).length > 0;
796
796
  const inputsChain = hasInputs ? `\n .withInputs(inputs)` : '';
797
- return `(function() {
798
- var __RESULT_MARKER = '${RESULT_MARKER}';
799
- try {
800
- var inputs = ${inputsJson};
801
-
802
- var result = sn_fd.FlowAPI.getRunner()
803
- .${type}('${scopedName}')
804
- .${modeMethod}()${optionalChain}${inputsChain}
805
- .run();
806
-
807
- var envelope = {
808
- __flowResult: true,
809
- success: true,
810
- flowObjectName: '' + result.getFlowObjectName(),
811
- flowObjectType: '' + result.getFlowObjectType(),
812
- contextId: result.getContextId() ? '' + result.getContextId() : null,
813
- executionDate: result.getDate() ? '' + result.getDate() : null,
814
- domainId: result.getDomainId() ? '' + result.getDomainId() : null,
815
- outputs: null,
816
- debugOutput: '' + result.debug(),
817
- errorMessage: null
818
- };
819
-
820
- try {
821
- var rawOutputs = result.getOutputs();
822
- if (rawOutputs) {
823
- var outputObj = {};
824
- for (var key in rawOutputs) {
825
- if (rawOutputs.hasOwnProperty(key)) {
826
- outputObj[key] = '' + rawOutputs[key];
827
- }
828
- }
829
- envelope.outputs = outputObj;
830
- }
831
- } catch (outErr) {
832
- envelope.outputs = null;
833
- }
834
-
835
- gs.info(__RESULT_MARKER + JSON.stringify(envelope));
836
- } catch (ex) {
837
- var errorEnvelope = {
838
- __flowResult: true,
839
- success: false,
840
- flowObjectName: '${scopedName}',
841
- flowObjectType: '${type}',
842
- contextId: null,
843
- executionDate: null,
844
- domainId: null,
845
- outputs: null,
846
- debugOutput: '',
847
- errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
848
- };
849
- gs.info(__RESULT_MARKER + JSON.stringify(errorEnvelope));
850
- }
797
+ return `(function() {
798
+ var __RESULT_MARKER = '${RESULT_MARKER}';
799
+ try {
800
+ var inputs = ${inputsJson};
801
+
802
+ var result = sn_fd.FlowAPI.getRunner()
803
+ .${type}('${scopedName}')
804
+ .${modeMethod}()${optionalChain}${inputsChain}
805
+ .run();
806
+
807
+ var envelope = {
808
+ __flowResult: true,
809
+ success: true,
810
+ flowObjectName: '' + result.getFlowObjectName(),
811
+ flowObjectType: '' + result.getFlowObjectType(),
812
+ contextId: result.getContextId() ? '' + result.getContextId() : null,
813
+ executionDate: result.getDate() ? '' + result.getDate() : null,
814
+ domainId: result.getDomainId() ? '' + result.getDomainId() : null,
815
+ outputs: null,
816
+ debugOutput: '' + result.debug(),
817
+ errorMessage: null
818
+ };
819
+
820
+ try {
821
+ var rawOutputs = result.getOutputs();
822
+ if (rawOutputs) {
823
+ var outputObj = {};
824
+ for (var key in rawOutputs) {
825
+ if (rawOutputs.hasOwnProperty(key)) {
826
+ outputObj[key] = '' + rawOutputs[key];
827
+ }
828
+ }
829
+ envelope.outputs = outputObj;
830
+ }
831
+ } catch (outErr) {
832
+ envelope.outputs = null;
833
+ }
834
+
835
+ gs.info(__RESULT_MARKER + JSON.stringify(envelope));
836
+ } catch (ex) {
837
+ var errorEnvelope = {
838
+ __flowResult: true,
839
+ success: false,
840
+ flowObjectName: '${scopedName}',
841
+ flowObjectType: '${type}',
842
+ contextId: null,
843
+ executionDate: null,
844
+ domainId: null,
845
+ outputs: null,
846
+ debugOutput: '',
847
+ errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
848
+ };
849
+ gs.info(__RESULT_MARKER + JSON.stringify(errorEnvelope));
850
+ }
851
851
  })();`;
852
852
  }
853
853
  /** Serialize inputs for embedding in the generated script. */
@@ -960,149 +960,149 @@ export class FlowManager {
960
960
  /** Build script to query sys_flow_context status. */
961
961
  _buildContextStatusScript(contextId) {
962
962
  const escapedId = this._escapeForScript(contextId);
963
- return `(function() {
964
- var __RESULT_MARKER = '${RESULT_MARKER}';
965
- try {
966
- var gr = new GlideRecord('sys_flow_context');
967
- if (gr.get('${escapedId}')) {
968
- gs.info(__RESULT_MARKER + JSON.stringify({
969
- __flowResult: true,
970
- success: true,
971
- contextId: '${escapedId}',
972
- found: true,
973
- state: '' + gr.getValue('state'),
974
- name: '' + gr.getValue('name'),
975
- started: gr.getValue('started') ? '' + gr.getValue('started') : null,
976
- ended: gr.getValue('ended') ? '' + gr.getValue('ended') : null,
977
- errorMessage: null
978
- }));
979
- } else {
980
- gs.info(__RESULT_MARKER + JSON.stringify({
981
- __flowResult: true,
982
- success: true,
983
- contextId: '${escapedId}',
984
- found: false,
985
- state: null,
986
- name: null,
987
- started: null,
988
- ended: null,
989
- errorMessage: null
990
- }));
991
- }
992
- } catch (ex) {
993
- gs.info(__RESULT_MARKER + JSON.stringify({
994
- __flowResult: true,
995
- success: false,
996
- contextId: '${escapedId}',
997
- found: false,
998
- errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
999
- }));
1000
- }
963
+ return `(function() {
964
+ var __RESULT_MARKER = '${RESULT_MARKER}';
965
+ try {
966
+ var gr = new GlideRecord('sys_flow_context');
967
+ if (gr.get('${escapedId}')) {
968
+ gs.info(__RESULT_MARKER + JSON.stringify({
969
+ __flowResult: true,
970
+ success: true,
971
+ contextId: '${escapedId}',
972
+ found: true,
973
+ state: '' + gr.getValue('state'),
974
+ name: '' + gr.getValue('name'),
975
+ started: gr.getValue('started') ? '' + gr.getValue('started') : null,
976
+ ended: gr.getValue('ended') ? '' + gr.getValue('ended') : null,
977
+ errorMessage: null
978
+ }));
979
+ } else {
980
+ gs.info(__RESULT_MARKER + JSON.stringify({
981
+ __flowResult: true,
982
+ success: true,
983
+ contextId: '${escapedId}',
984
+ found: false,
985
+ state: null,
986
+ name: null,
987
+ started: null,
988
+ ended: null,
989
+ errorMessage: null
990
+ }));
991
+ }
992
+ } catch (ex) {
993
+ gs.info(__RESULT_MARKER + JSON.stringify({
994
+ __flowResult: true,
995
+ success: false,
996
+ contextId: '${escapedId}',
997
+ found: false,
998
+ errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
999
+ }));
1000
+ }
1001
1001
  })();`;
1002
1002
  }
1003
1003
  /** Build script to retrieve flow outputs via FlowAPI.getOutputs(). */
1004
1004
  _buildGetOutputsScript(contextId) {
1005
1005
  const escapedId = this._escapeForScript(contextId);
1006
- return `(function() {
1007
- var __RESULT_MARKER = '${RESULT_MARKER}';
1008
- try {
1009
- var outputs = sn_fd.FlowAPI.getOutputs('${escapedId}');
1010
- var outputObj = {};
1011
- if (outputs) {
1012
- for (var key in outputs) {
1013
- if (outputs.hasOwnProperty(key)) {
1014
- outputObj[key] = '' + outputs[key];
1015
- }
1016
- }
1017
- }
1018
- gs.info(__RESULT_MARKER + JSON.stringify({
1019
- __flowResult: true,
1020
- success: true,
1021
- contextId: '${escapedId}',
1022
- outputs: outputObj,
1023
- errorMessage: null
1024
- }));
1025
- } catch (ex) {
1026
- gs.info(__RESULT_MARKER + JSON.stringify({
1027
- __flowResult: true,
1028
- success: false,
1029
- contextId: '${escapedId}',
1030
- outputs: null,
1031
- errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1032
- }));
1033
- }
1006
+ return `(function() {
1007
+ var __RESULT_MARKER = '${RESULT_MARKER}';
1008
+ try {
1009
+ var outputs = sn_fd.FlowAPI.getOutputs('${escapedId}');
1010
+ var outputObj = {};
1011
+ if (outputs) {
1012
+ for (var key in outputs) {
1013
+ if (outputs.hasOwnProperty(key)) {
1014
+ outputObj[key] = '' + outputs[key];
1015
+ }
1016
+ }
1017
+ }
1018
+ gs.info(__RESULT_MARKER + JSON.stringify({
1019
+ __flowResult: true,
1020
+ success: true,
1021
+ contextId: '${escapedId}',
1022
+ outputs: outputObj,
1023
+ errorMessage: null
1024
+ }));
1025
+ } catch (ex) {
1026
+ gs.info(__RESULT_MARKER + JSON.stringify({
1027
+ __flowResult: true,
1028
+ success: false,
1029
+ contextId: '${escapedId}',
1030
+ outputs: null,
1031
+ errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1032
+ }));
1033
+ }
1034
1034
  })();`;
1035
1035
  }
1036
1036
  /** Build script to retrieve flow error via FlowAPI.getErrorMessage(). */
1037
1037
  _buildGetErrorScript(contextId) {
1038
1038
  const escapedId = this._escapeForScript(contextId);
1039
- return `(function() {
1040
- var __RESULT_MARKER = '${RESULT_MARKER}';
1041
- try {
1042
- var errorMsg = sn_fd.FlowAPI.getErrorMessage('${escapedId}');
1043
- gs.info(__RESULT_MARKER + JSON.stringify({
1044
- __flowResult: true,
1045
- success: true,
1046
- contextId: '${escapedId}',
1047
- flowErrorMessage: errorMsg ? '' + errorMsg : null,
1048
- errorMessage: null
1049
- }));
1050
- } catch (ex) {
1051
- gs.info(__RESULT_MARKER + JSON.stringify({
1052
- __flowResult: true,
1053
- success: false,
1054
- contextId: '${escapedId}',
1055
- flowErrorMessage: null,
1056
- errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1057
- }));
1058
- }
1039
+ return `(function() {
1040
+ var __RESULT_MARKER = '${RESULT_MARKER}';
1041
+ try {
1042
+ var errorMsg = sn_fd.FlowAPI.getErrorMessage('${escapedId}');
1043
+ gs.info(__RESULT_MARKER + JSON.stringify({
1044
+ __flowResult: true,
1045
+ success: true,
1046
+ contextId: '${escapedId}',
1047
+ flowErrorMessage: errorMsg ? '' + errorMsg : null,
1048
+ errorMessage: null
1049
+ }));
1050
+ } catch (ex) {
1051
+ gs.info(__RESULT_MARKER + JSON.stringify({
1052
+ __flowResult: true,
1053
+ success: false,
1054
+ contextId: '${escapedId}',
1055
+ flowErrorMessage: null,
1056
+ errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1057
+ }));
1058
+ }
1059
1059
  })();`;
1060
1060
  }
1061
1061
  /** Build script to cancel a flow via FlowAPI.cancel(). */
1062
1062
  _buildCancelScript(contextId, reason) {
1063
1063
  const escapedId = this._escapeForScript(contextId);
1064
1064
  const escapedReason = this._escapeForScript(reason);
1065
- return `(function() {
1066
- var __RESULT_MARKER = '${RESULT_MARKER}';
1067
- try {
1068
- sn_fd.FlowAPI.cancel('${escapedId}', '${escapedReason}');
1069
- gs.info(__RESULT_MARKER + JSON.stringify({
1070
- __flowResult: true,
1071
- success: true,
1072
- contextId: '${escapedId}',
1073
- errorMessage: null
1074
- }));
1075
- } catch (ex) {
1076
- gs.info(__RESULT_MARKER + JSON.stringify({
1077
- __flowResult: true,
1078
- success: false,
1079
- contextId: '${escapedId}',
1080
- errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1081
- }));
1082
- }
1065
+ return `(function() {
1066
+ var __RESULT_MARKER = '${RESULT_MARKER}';
1067
+ try {
1068
+ sn_fd.FlowAPI.cancel('${escapedId}', '${escapedReason}');
1069
+ gs.info(__RESULT_MARKER + JSON.stringify({
1070
+ __flowResult: true,
1071
+ success: true,
1072
+ contextId: '${escapedId}',
1073
+ errorMessage: null
1074
+ }));
1075
+ } catch (ex) {
1076
+ gs.info(__RESULT_MARKER + JSON.stringify({
1077
+ __flowResult: true,
1078
+ success: false,
1079
+ contextId: '${escapedId}',
1080
+ errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1081
+ }));
1082
+ }
1083
1083
  })();`;
1084
1084
  }
1085
1085
  /** Build script to publish a flow via FlowAPI.publish(). */
1086
1086
  _buildPublishScript(flowSysId) {
1087
1087
  const escapedId = this._escapeForScript(flowSysId);
1088
- return `(function() {
1089
- var __RESULT_MARKER = '${RESULT_MARKER}';
1090
- try {
1091
- sn_fd.FlowAPI.publish('${escapedId}');
1092
- gs.info(__RESULT_MARKER + JSON.stringify({
1093
- __flowResult: true,
1094
- success: true,
1095
- flowSysId: '${escapedId}',
1096
- errorMessage: null
1097
- }));
1098
- } catch (ex) {
1099
- gs.info(__RESULT_MARKER + JSON.stringify({
1100
- __flowResult: true,
1101
- success: false,
1102
- flowSysId: '${escapedId}',
1103
- errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1104
- }));
1105
- }
1088
+ return `(function() {
1089
+ var __RESULT_MARKER = '${RESULT_MARKER}';
1090
+ try {
1091
+ sn_fd.FlowAPI.publish('${escapedId}');
1092
+ gs.info(__RESULT_MARKER + JSON.stringify({
1093
+ __flowResult: true,
1094
+ success: true,
1095
+ flowSysId: '${escapedId}',
1096
+ errorMessage: null
1097
+ }));
1098
+ } catch (ex) {
1099
+ gs.info(__RESULT_MARKER + JSON.stringify({
1100
+ __flowResult: true,
1101
+ success: false,
1102
+ flowSysId: '${escapedId}',
1103
+ errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1104
+ }));
1105
+ }
1106
1106
  })();`;
1107
1107
  }
1108
1108
  /** Build script to send a message to a paused flow via FlowAPI.sendMessage(). */
@@ -1110,24 +1110,24 @@ export class FlowManager {
1110
1110
  const escapedId = this._escapeForScript(contextId);
1111
1111
  const escapedMessage = this._escapeForScript(message);
1112
1112
  const escapedPayload = this._escapeForScript(payload);
1113
- return `(function() {
1114
- var __RESULT_MARKER = '${RESULT_MARKER}';
1115
- try {
1116
- sn_fd.FlowAPI.sendMessage('${escapedId}', '${escapedMessage}', '${escapedPayload}');
1117
- gs.info(__RESULT_MARKER + JSON.stringify({
1118
- __flowResult: true,
1119
- success: true,
1120
- contextId: '${escapedId}',
1121
- errorMessage: null
1122
- }));
1123
- } catch (ex) {
1124
- gs.info(__RESULT_MARKER + JSON.stringify({
1125
- __flowResult: true,
1126
- success: false,
1127
- contextId: '${escapedId}',
1128
- errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1129
- }));
1130
- }
1113
+ return `(function() {
1114
+ var __RESULT_MARKER = '${RESULT_MARKER}';
1115
+ try {
1116
+ sn_fd.FlowAPI.sendMessage('${escapedId}', '${escapedMessage}', '${escapedPayload}');
1117
+ gs.info(__RESULT_MARKER + JSON.stringify({
1118
+ __flowResult: true,
1119
+ success: true,
1120
+ contextId: '${escapedId}',
1121
+ errorMessage: null
1122
+ }));
1123
+ } catch (ex) {
1124
+ gs.info(__RESULT_MARKER + JSON.stringify({
1125
+ __flowResult: true,
1126
+ success: false,
1127
+ contextId: '${escapedId}',
1128
+ errorMessage: '' + (ex.getMessage ? ex.getMessage() : ex)
1129
+ }));
1130
+ }
1131
1131
  })();`;
1132
1132
  }
1133
1133
  }