snow-flow 3.6.20 → 3.6.23

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.
@@ -36,7 +36,7 @@ function getDynamicVersion() {
36
36
  console.warn('Warning: Could not read version from package.json:', error);
37
37
  }
38
38
  // Fallback to hardcoded version
39
- return '3.4.4';
39
+ return '3.6.23';
40
40
  }
41
41
  // Export a constant that uses the dynamic version
42
42
  exports.VERSION = getDynamicVersion();
@@ -752,8 +752,8 @@ ${args.recurring_price && args.recurring_price !== '0' ? `šŸ”„ Recurring: $${arg
752
752
  tooltip: args.tooltip || ''
753
753
  };
754
754
  this.logger.info('šŸŽÆ Creating variable with payload:', variableData);
755
- // āœ… CORRECT TABLE NAME: Use sc_cat_item_option instead of item_option_new
756
- const response = await this.client.createRecord('sc_cat_item_option', variableData);
755
+ // āœ… FIXED TABLE NAME: Use item_option_new (the correct table for catalog variables)
756
+ const response = await this.client.createRecord('item_option_new', variableData);
757
757
  if (!response.success) {
758
758
  this.logger.error('āŒ Variable creation failed:', {
759
759
  error: response.error,
@@ -766,7 +766,7 @@ ${args.recurring_price && args.recurring_price !== '0' ? `šŸ”„ Recurring: $${arg
766
766
  this.logger.info(`āœ… Variable created with sys_id: ${createdSysId}`);
767
767
  // šŸ” VERIFICATION: Check if variable was actually created
768
768
  this.logger.info('šŸ” Verifying variable creation...');
769
- const verification = await this.client.searchRecords('sc_cat_item_option', `sys_id=${createdSysId}`, 1);
769
+ const verification = await this.client.searchRecords('item_option_new', `sys_id=${createdSysId}`, 1);
770
770
  if (!verification.success || verification.data.result.length === 0) {
771
771
  this.logger.error('āŒ VERIFICATION FAILED: Variable not found after creation!');
772
772
  throw new Error(`Variable creation verification failed - not found in database`);
@@ -797,16 +797,16 @@ ${args.help_text ? `ā“ Help: ${args.help_text}` : ''}
797
797
  }
798
798
  /**
799
799
  * Create Catalog UI Policy with Actions
800
- * Creates records in 2 tables: sys_ui_policy and catalog_ui_policy_action
800
+ * Creates records in 2 tables: catalog_ui_policy and catalog_ui_policy_action
801
801
  *
802
- * āœ… FINAL CORRECT STRUCTURE (v3.6.20):
803
- * - Main policy goes in sys_ui_policy table (NOT catalog_ui_policy!)
802
+ * āœ… CORRECTED STRUCTURE (v3.6.21):
803
+ * - Main policy goes in catalog_ui_policy table (NOT sys_ui_policy!)
804
804
  * - Actions go in catalog_ui_policy_action table (inherits from sys_ui_policy_action)
805
- * - Actions reference sys_ui_policy via ui_policy field (using policy sys_id directly)
805
+ * - Actions reference catalog_ui_policy via ui_policy field (using policy sys_id directly)
806
806
  * - Conditions use IO:sys_id format for catalog variables
807
807
  * - catalog_ui_policy_action.catalog_variable uses IO:sys_id format
808
808
  * - visible/mandatory/disabled use "ignore" as default, not false or empty
809
- * - Reference fields are set directly, not via setValue() for reliability
809
+ * - Reference fields are set directly for reliability
810
810
  * - Enhanced verification ensures all critical fields are populated
811
811
  */
812
812
  async createCatalogUIPolicy(args) {
@@ -981,24 +981,23 @@ ${args.help_text ? `ā“ Help: ${args.help_text}` : ''}
981
981
  conditionString = conditionParts.join('^');
982
982
  this.logger.info(`āœ… Built conditions string: "${conditionString}"`);
983
983
  }
984
- // āœ… CRITICAL FIX: Create in sys_ui_policy table, NOT catalog_ui_policy!
985
- // The actions reference sys_ui_policy, not catalog_ui_policy
984
+ // āœ… CRITICAL FIX: Create in catalog_ui_policy table!
985
+ // The actions reference catalog_ui_policy, NOT sys_ui_policy!
986
986
  const policyData = {
987
- // sys_ui_policy fields are different from catalog_ui_policy!
988
- name: args.short_description, // sys_ui_policy uses 'name' not 'short_description'
989
- table: 'sc_cat_item', // The table this policy applies to
990
- conditions: conditionString || args.condition || '', // Condition string
987
+ // catalog_ui_policy fields
988
+ short_description: args.short_description,
989
+ catalog_item: args.cat_item, // Reference to the catalog item
990
+ catalog_conditions: conditionString || args.condition || '', // Conditions as string
991
+ applies_catalog: true, // This is a catalog policy
991
992
  active: args.active !== false,
992
- on_load: args.on_load !== false, // Different field name in sys_ui_policy
993
+ applies_on: args.applies_on || 'true', // When to apply: 'true', 'false', or 'both'
993
994
  reverse_if_false: args.reverse_if_false !== false,
994
- // Link to the catalog item via a different field
995
- catalog_item: args.cat_item,
996
995
  // Optional script fields
997
996
  script_true: args.script_true || '',
998
997
  script_false: args.script_false || ''
999
998
  };
1000
- this.logger.info('šŸŽÆ Creating main policy in sys_ui_policy table with data:', policyData);
1001
- const policyResponse = await this.client.createRecord('sys_ui_policy', policyData);
999
+ this.logger.info('šŸŽÆ Creating main policy in catalog_ui_policy table with data:', policyData);
1000
+ const policyResponse = await this.client.createRecord('catalog_ui_policy', policyData);
1002
1001
  if (!policyResponse.success) {
1003
1002
  this.logger.error('āŒ Policy creation failed:', policyResponse.error);
1004
1003
  throw new Error(`Failed to create catalog UI policy: ${policyResponse.error}`);
@@ -1041,14 +1040,39 @@ ${args.help_text ? `ā“ Help: ${args.help_text}` : ''}
1041
1040
  // catalog_ui_policy_action inherits from sys_ui_policy_action
1042
1041
  // We must set fields in the correct way for ServiceNow to accept them
1043
1042
  const actionData = {};
1044
- // STEP 1: Set reference fields (MUST be set first for ServiceNow)
1045
- // āœ… ui_policy is a reference to sys_ui_policy - use sys_id directly
1043
+ // STEP 1: ENHANCED VERIFICATION - Verify policy exists before creating actions
1044
+ this.logger.info(`šŸ” ENHANCED DEBUG: Verifying policy ${policyId} exists before creating action...`);
1045
+ if (!policyId) {
1046
+ this.logger.error(`āŒ CRITICAL: No policyId available for action ${i + 1}!`);
1047
+ throw new Error(`Cannot create action without valid policy ID`);
1048
+ }
1049
+ // āœ… NEW: Test policy existence before action creation
1050
+ const policyExists = await this.client.searchRecords('catalog_ui_policy', `sys_id=${policyId}`, 1);
1051
+ if (!policyExists.success || policyExists.data.result.length === 0) {
1052
+ this.logger.error(`āŒ CRITICAL: Policy ${policyId} does not exist in catalog_ui_policy table!`);
1053
+ throw new Error(`Policy verification failed - cannot create action without valid policy`);
1054
+ }
1055
+ const existingPolicy = policyExists.data.result[0];
1056
+ this.logger.info(`āœ… Policy verification successful:`);
1057
+ this.logger.info(` - Policy sys_id: ${existingPolicy.sys_id}`);
1058
+ this.logger.info(` - Policy name: ${existingPolicy.short_description || 'N/A'}`);
1059
+ this.logger.info(` - Policy active: ${existingPolicy.active}`);
1060
+ // STEP 2: Set reference fields with enhanced validation
1061
+ // āœ… ui_policy is a reference to catalog_ui_policy - test multiple formats
1062
+ this.logger.info(`šŸ“ Setting ui_policy reference to: ${policyId}`);
1063
+ // Try setting the reference in the most explicit way possible
1046
1064
  actionData.ui_policy = policyId;
1047
1065
  // āœ… catalog_item is a reference to sc_cat_item - use sys_id directly
1066
+ if (!args.cat_item) {
1067
+ this.logger.error(`āŒ CRITICAL: No catalog item ID provided!`);
1068
+ throw new Error(`Cannot create action without catalog item ID`);
1069
+ }
1070
+ this.logger.info(`šŸ“ Setting catalog_item reference to: ${args.cat_item}`);
1048
1071
  actionData.catalog_item = args.cat_item;
1049
- // STEP 2: Set the catalog_variable with IO: prefix (STRING field, not reference)
1072
+ // STEP 3: Set the catalog_variable with IO: prefix (STRING field, not reference)
1073
+ this.logger.info(`šŸ“ Setting catalog_variable to: ${catalogVariableWithPrefix}`);
1050
1074
  actionData.catalog_variable = catalogVariableWithPrefix;
1051
- // STEP 3: Set action properties with correct values
1075
+ // STEP 4: Set action properties with correct values
1052
1076
  // āœ… CRITICAL: Use "ignore" instead of not setting or using false
1053
1077
  // This is how ServiceNow differentiates between "don't change" and "set to false"
1054
1078
  if (action.visible !== undefined) {
@@ -1072,20 +1096,22 @@ ${args.help_text ? `ā“ Help: ${args.help_text}` : ''}
1072
1096
  else {
1073
1097
  actionData.disabled = 'ignore'; // Default to ignore if not specified
1074
1098
  }
1075
- // STEP 4: Set optional value field
1099
+ // STEP 5: Set optional value field
1076
1100
  if (action.value !== undefined && action.value !== null && action.value !== '') {
1077
1101
  actionData.value = String(action.value);
1078
1102
  }
1079
- // STEP 5: Set other metadata
1103
+ // STEP 6: Set other metadata
1080
1104
  actionData.order = (i + 1) * 100;
1081
1105
  actionData.active = true;
1082
- this.logger.info(`šŸ”— Creating action with proper structure:`);
1083
- this.logger.info(` - ui_policy (ref): ${policyId}`);
1106
+ this.logger.info(`šŸ”— Creating action with VALIDATED structure:`);
1107
+ this.logger.info(` - ui_policy (ref): ${policyId} [VERIFIED EXISTS]`);
1084
1108
  this.logger.info(` - catalog_item (ref): ${args.cat_item}`);
1085
1109
  this.logger.info(` - catalog_variable: ${catalogVariableWithPrefix}`);
1086
1110
  this.logger.info(` - visible: ${actionData.visible}`);
1087
1111
  this.logger.info(` - mandatory: ${actionData.mandatory}`);
1088
1112
  this.logger.info(` - disabled: ${actionData.disabled}`);
1113
+ // āœ… ENHANCED DEBUG: Log complete action data being sent
1114
+ this.logger.info(`šŸ“‹ Complete action data being sent to ServiceNow:`, JSON.stringify(actionData, null, 2));
1089
1115
  this.logger.info(`šŸŽÆ Attempting to create action ${i + 1} in catalog_ui_policy_action table...`);
1090
1116
  const actionResponse = await this.client.createRecord('catalog_ui_policy_action', actionData);
1091
1117
  if (actionResponse.success) {
@@ -1113,18 +1139,55 @@ ${args.help_text ? `ā“ Help: ${args.help_text}` : ''}
1113
1139
  const uiPolicyValue = createdAction.ui_policy;
1114
1140
  const catalogVariableValue = createdAction.catalog_variable;
1115
1141
  const catalogItemValue = createdAction.catalog_item;
1116
- // Check ui_policy reference
1117
- if (!uiPolicyValue || uiPolicyValue === '' || uiPolicyValue === '{}') {
1142
+ // Log the raw response to understand what ServiceNow returns
1143
+ this.logger.info(`šŸ“‹ Raw action verification response:`, JSON.stringify(createdAction, null, 2));
1144
+ // Check ui_policy reference - ServiceNow might return it as an object
1145
+ let actualUiPolicyId = uiPolicyValue;
1146
+ if (typeof uiPolicyValue === 'object' && uiPolicyValue !== null) {
1147
+ actualUiPolicyId = uiPolicyValue.value || uiPolicyValue.sys_id || '';
1148
+ this.logger.info(`šŸ“ ui_policy returned as object: ${JSON.stringify(uiPolicyValue)}`);
1149
+ }
1150
+ if (!actualUiPolicyId || actualUiPolicyId === '' || actualUiPolicyId === '{}') {
1118
1151
  this.logger.error(`āŒ CRITICAL: ui_policy field is EMPTY for action ${i + 1}!`);
1119
- this.logger.error(`āŒ Expected: ${policyId}, Got: ${uiPolicyValue}`);
1120
- throw new Error(`Action ${i + 1} created but ui_policy field is empty - action will not work!`);
1152
+ this.logger.error(`āŒ Expected policy ID: ${policyId}`);
1153
+ this.logger.error(`āŒ Raw ui_policy value: ${JSON.stringify(uiPolicyValue)}`);
1154
+ this.logger.error(`āŒ Parsed ui_policy value: ${actualUiPolicyId}`);
1155
+ this.logger.error(`āŒ Action data sent:`, JSON.stringify(actionData, null, 2));
1156
+ this.logger.error(`āŒ Full action verification response:`, JSON.stringify(createdAction, null, 2));
1157
+ // āœ… ENHANCED ERROR: Try to understand ServiceNow's response pattern
1158
+ this.logger.error(`ā„¹ļø DIAGNOSTIC INFO:`);
1159
+ this.logger.error(` - Policy verified to exist: YES (${policyId})`);
1160
+ this.logger.error(` - Action created successfully: YES (${createdActionId})`);
1161
+ this.logger.error(` - ui_policy field type: ${typeof uiPolicyValue}`);
1162
+ this.logger.error(` - ui_policy field value length: ${String(uiPolicyValue || '').length}`);
1163
+ this.logger.error(` - All action fields:`, Object.keys(createdAction));
1164
+ // Check if it's a ServiceNow API timing issue
1165
+ this.logger.warn(`šŸ”„ ATTEMPTING SECONDARY VERIFICATION (possible timing issue)...`);
1166
+ // Wait a moment and try again
1167
+ await new Promise(resolve => setTimeout(resolve, 1000));
1168
+ const secondVerification = await this.client.searchRecords('catalog_ui_policy_action', `sys_id=${createdActionId}`, 1);
1169
+ if (secondVerification.success && secondVerification.data.result.length > 0) {
1170
+ const reCheckedAction = secondVerification.data.result[0];
1171
+ const reCheckedUiPolicy = reCheckedAction.ui_policy;
1172
+ this.logger.error(`šŸ”„ Secondary verification ui_policy: ${JSON.stringify(reCheckedUiPolicy)}`);
1173
+ if (reCheckedUiPolicy && reCheckedUiPolicy !== '' && reCheckedUiPolicy !== '{}') {
1174
+ this.logger.warn(`āš ļø This was a timing issue - ui_policy populated after delay`);
1175
+ // Continue with the re-checked value
1176
+ return; // Skip the error throwing
1177
+ }
1178
+ }
1179
+ throw new Error(`Action ${i + 1} created but ui_policy field is empty - action will not work! This may be a ServiceNow API or table structure issue.`);
1121
1180
  }
1122
1181
  // For reference fields, ServiceNow might return an object - extract the value
1123
1182
  const uiPolicySysId = typeof uiPolicyValue === 'object' && uiPolicyValue.value ?
1124
1183
  uiPolicyValue.value : uiPolicyValue;
1184
+ this.logger.info(`āœ… ui_policy field populated successfully: ${actualUiPolicyId}`);
1125
1185
  if (uiPolicySysId !== policyId) {
1126
1186
  this.logger.warn(`āš ļø ui_policy mismatch - Expected: ${policyId}, Got: ${uiPolicySysId}`);
1127
1187
  }
1188
+ else {
1189
+ this.logger.info(`āœ… ui_policy reference matches expected value`);
1190
+ }
1128
1191
  // Check catalog_variable (should have IO: prefix)
1129
1192
  if (!catalogVariableValue || catalogVariableValue === '') {
1130
1193
  this.logger.error(`āŒ CRITICAL: catalog_variable field is EMPTY for action ${i + 1}!`);
@@ -1166,27 +1229,27 @@ ${args.help_text ? `ā“ Help: ${args.help_text}` : ''}
1166
1229
  }
1167
1230
  }
1168
1231
  }
1169
- // šŸ” FINAL VERIFICATION: Policy creation in sys_ui_policy table
1170
- this.logger.info('šŸ” Final verification: Checking policy in sys_ui_policy table...');
1171
- const policyVerification = await this.client.searchRecords('sys_ui_policy', `sys_id=${policyId}`, 1);
1232
+ // šŸ” FINAL VERIFICATION: Policy creation in catalog_ui_policy table
1233
+ this.logger.info('šŸ” Final verification: Checking policy in catalog_ui_policy table...');
1234
+ const policyVerification = await this.client.searchRecords('catalog_ui_policy', `sys_id=${policyId}`, 1);
1172
1235
  if (!policyVerification.success || policyVerification.data.result.length === 0) {
1173
- this.logger.error('āŒ POLICY VERIFICATION FAILED: Policy not found in sys_ui_policy table!');
1174
- throw new Error(`Policy creation verification failed - policy not found in sys_ui_policy table`);
1236
+ this.logger.error('āŒ POLICY VERIFICATION FAILED: Policy not found in catalog_ui_policy table!');
1237
+ throw new Error(`Policy creation verification failed - policy not found in catalog_ui_policy table`);
1175
1238
  }
1176
- this.logger.info('āœ… Policy verified in sys_ui_policy table');
1239
+ this.logger.info('āœ… Policy verified in catalog_ui_policy table');
1177
1240
  // Build comprehensive response
1178
- let responseText = `āœ… UI Policy created successfully in sys_ui_policy table!
1241
+ let responseText = `āœ… Catalog UI Policy created successfully!
1179
1242
 
1180
1243
  šŸ“‹ **${args.short_description}**
1181
1244
  šŸ†” Policy sys_id: ${policyId}
1182
- šŸ“Š Table: sys_ui_policy (correct table for catalog UI policy actions)
1183
- šŸŽÆ Target Table: sc_cat_item
1245
+ šŸ“Š Table: catalog_ui_policy (correct table for catalog actions)
1246
+ šŸŽÆ Catalog Item: ${args.cat_item}
1184
1247
  šŸ”„ Active: ${args.active !== false ? 'Yes' : 'No'}
1185
- ⚔ On Load: ${args.on_load !== false ? 'Yes' : 'No'}
1248
+ ⚔ Applies On: ${args.applies_on || 'true'}
1186
1249
  šŸ” Reverse if False: ${args.reverse_if_false !== false ? 'Yes' : 'No'}
1187
1250
 
1188
1251
  šŸ” **Verification Results:**
1189
- āœ… Policy record created in sys_ui_policy table
1252
+ āœ… Policy record created in catalog_ui_policy table
1190
1253
  āœ… ${createdActions.length} actions created in catalog_ui_policy_action table`;
1191
1254
  if (conditionString) {
1192
1255
  responseText += `\n\nšŸ“ **Conditions:**\n${conditionString}`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "3.6.20",
4
- "description": "COMPLETE CATALOG UI POLICY FIX - v3.6.20 implements Snow-Flow's complete analysis: proper parent-child table inheritance (sys_ui_policy_action → catalog_ui_policy_action), direct assignment for references, 'ignore' values for visible/mandatory/disabled, enhanced verification, IO: prefix validation. Based on extensive ServiceNow structure analysis.",
3
+ "version": "3.6.23",
4
+ "description": "CATALOG VARIABLE TABLE FIX - v3.6.23 fixes critical issue: catalog variables now created in correct table 'item_option_new' instead of wrong table 'sc_cat_item_option'. This ensures variables are actually visible and functional in catalog items.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
7
7
  "bin": {