snow-flow 3.6.17 → 3.6.18

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.
@@ -797,12 +797,14 @@ ${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: catalog_ui_policy and catalog_ui_policy_action
800
+ * Creates records in 2 tables: sys_ui_policy and catalog_ui_policy_action
801
801
  *
802
- * BELANGRIJKE WIJZIGINGEN:
803
- * - Conditions worden NIET in een aparte tabel opgeslagen
804
- * - Conditions worden als string/script in catalog_conditions veld gezet
805
- * - catalog_ui_policy_condition tabel bestaat niet in ServiceNow
802
+ * CORRECTED STRUCTURE (v3.6.18):
803
+ * - Main policy goes in sys_ui_policy table (NOT catalog_ui_policy!)
804
+ * - Actions go in catalog_ui_policy_action table
805
+ * - Actions reference sys_ui_policy via ui_policy field (using policy name)
806
+ * - Conditions use IO:sys_id format for catalog variables
807
+ * - catalog_ui_policy_action.catalog_variable uses IO:sys_id format
806
808
  */
807
809
  async createCatalogUIPolicy(args) {
808
810
  try {
@@ -949,18 +951,25 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
949
951
  // Safely get condition value (avoid undefined concatenation)
950
952
  const conditionValue = condition.value || '';
951
953
  // Build the condition part based on operator type
954
+ // ✅ CRITICAL: Conditions must use IO:sys_id format for catalog variables!
955
+ // BUT only if we successfully resolved the variable to a sys_id
956
+ const isValidSysId = variableId && variableId.match(/^[a-f0-9]{32}$/);
957
+ const variableWithIOPrefix = isValidSysId ? `IO:${variableId}` : variableId;
958
+ if (!isValidSysId) {
959
+ this.logger.warn(`⚠️ Variable '${condition.catalog_variable}' could not be resolved to sys_id - condition may fail!`);
960
+ }
952
961
  let conditionPart = '';
953
962
  if (serviceNowOperator === 'ISEMPTY' || serviceNowOperator === 'ISNOTEMPTY') {
954
963
  // For empty/not empty checks, no value needed
955
- conditionPart = `${variableId}${serviceNowOperator}`;
964
+ conditionPart = `${variableWithIOPrefix}${serviceNowOperator}`;
956
965
  }
957
966
  else if (serviceNowOperator === 'LIKE' || serviceNowOperator === 'NOT LIKE') {
958
967
  // For LIKE operations, ensure value is wrapped properly
959
- conditionPart = `${variableId}${serviceNowOperator}${conditionValue}`;
968
+ conditionPart = `${variableWithIOPrefix}${serviceNowOperator}${conditionValue}`;
960
969
  }
961
970
  else {
962
971
  // Standard operations (=, !=, >, <, etc.)
963
- conditionPart = `${variableId}${serviceNowOperator}${conditionValue}`;
972
+ conditionPart = `${variableWithIOPrefix}${serviceNowOperator}${conditionValue}`;
964
973
  }
965
974
  this.logger.info(`🏗️ Built condition part: ${conditionPart} (from ${originalOperator}: '${conditionValue}')`);
966
975
  conditionParts.push(conditionPart);
@@ -969,21 +978,24 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
969
978
  conditionString = conditionParts.join('^');
970
979
  this.logger.info(`✅ Built conditions string: "${conditionString}"`);
971
980
  }
972
- // Step 1: Create main catalog UI policy record with embedded conditions
981
+ // CRITICAL FIX: Create in sys_ui_policy table, NOT catalog_ui_policy!
982
+ // The actions reference sys_ui_policy, not catalog_ui_policy
973
983
  const policyData = {
974
- catalog_item: args.cat_item, // Link naar het catalog item
975
- short_description: args.short_description,
976
- catalog_conditions: conditionString || args.condition || '', // Conditions as string
977
- applies_to: args.applies_to || 'item', // Correct veld: 'item', 'req_item', or 'task'
984
+ // sys_ui_policy fields are different from catalog_ui_policy!
985
+ name: args.short_description, // sys_ui_policy uses 'name' not 'short_description'
986
+ table: 'sc_cat_item', // The table this policy applies to
987
+ conditions: conditionString || args.condition || '', // Condition string
978
988
  active: args.active !== false,
979
- applies_on_load: args.on_load !== false,
989
+ on_load: args.on_load !== false, // Different field name in sys_ui_policy
980
990
  reverse_if_false: args.reverse_if_false !== false,
981
- // Optional script fields if needed
991
+ // Link to the catalog item via a different field
992
+ catalog_item: args.cat_item,
993
+ // Optional script fields
982
994
  script_true: args.script_true || '',
983
995
  script_false: args.script_false || ''
984
996
  };
985
- this.logger.info('🎯 Creating main policy with data:', policyData);
986
- const policyResponse = await this.client.createRecord('catalog_ui_policy', policyData);
997
+ this.logger.info('🎯 Creating main policy in sys_ui_policy table with data:', policyData);
998
+ const policyResponse = await this.client.createRecord('sys_ui_policy', policyData);
987
999
  if (!policyResponse.success) {
988
1000
  this.logger.error('❌ Policy creation failed:', policyResponse.error);
989
1001
  throw new Error(`Failed to create catalog UI policy: ${policyResponse.error}`);
@@ -1086,27 +1098,28 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
1086
1098
  }
1087
1099
  }
1088
1100
  }
1089
- // 🔍 FINAL VERIFICATION: Policy creation
1090
- this.logger.info('🔍 Final verification: Checking policy in database...');
1091
- const policyVerification = await this.client.searchRecords('catalog_ui_policy', `sys_id=${policyId}`, 1);
1101
+ // 🔍 FINAL VERIFICATION: Policy creation in sys_ui_policy table
1102
+ this.logger.info('🔍 Final verification: Checking policy in sys_ui_policy table...');
1103
+ const policyVerification = await this.client.searchRecords('sys_ui_policy', `sys_id=${policyId}`, 1);
1092
1104
  if (!policyVerification.success || policyVerification.data.result.length === 0) {
1093
- this.logger.error('❌ POLICY VERIFICATION FAILED: Policy not found after creation!');
1094
- throw new Error(`Policy creation verification failed - policy not found in database`);
1105
+ this.logger.error('❌ POLICY VERIFICATION FAILED: Policy not found in sys_ui_policy table!');
1106
+ throw new Error(`Policy creation verification failed - policy not found in sys_ui_policy table`);
1095
1107
  }
1096
- this.logger.info('✅ Policy verified in database');
1108
+ this.logger.info('✅ Policy verified in sys_ui_policy table');
1097
1109
  // Build comprehensive response
1098
- let responseText = `✅ Catalog UI Policy created successfully!
1110
+ let responseText = `✅ UI Policy created successfully in sys_ui_policy table!
1099
1111
 
1100
1112
  📋 **${args.short_description}**
1101
1113
  🆔 Policy sys_id: ${policyId}
1102
- 🎯 Applies to: ${args.applies_to || 'item'}
1114
+ 📊 Table: sys_ui_policy (correct table for catalog UI policy actions)
1115
+ 🎯 Target Table: sc_cat_item
1103
1116
  🔄 Active: ${args.active !== false ? 'Yes' : 'No'}
1104
1117
  ⚡ On Load: ${args.on_load !== false ? 'Yes' : 'No'}
1105
1118
  🔁 Reverse if False: ${args.reverse_if_false !== false ? 'Yes' : 'No'}
1106
1119
 
1107
1120
  🔍 **Verification Results:**
1108
- ✅ Policy record created and verified
1109
- ✅ ${createdActions.length} actions created and verified`;
1121
+ ✅ Policy record created in sys_ui_policy table
1122
+ ✅ ${createdActions.length} actions created in catalog_ui_policy_action table`;
1110
1123
  if (conditionString) {
1111
1124
  responseText += `\n\n📝 **Conditions:**\n${conditionString}`;
1112
1125
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "3.6.17",
4
- "description": "UI POLICY NAME FIX - v3.6.17 fixes critical issue where ui_policy field in catalog_ui_policy_action table expects the policy NAME (short_description) instead of sys_id. Actions will now properly link to policies using the policy name as the reference value, which is what ServiceNow actually expects.",
3
+ "version": "3.6.18",
4
+ "description": "FUNDAMENTAL TABLE FIX - v3.6.18 corrects critical table structure: policies now created in sys_ui_policy (NOT catalog_ui_policy), conditions use IO:sys_id format, actions properly link to sys_ui_policy. This matches ServiceNow's actual catalog UI policy structure where catalog_ui_policy_action references sys_ui_policy, not catalog_ui_policy.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
7
7
  "bin": {