snow-flow 3.6.17 → 3.6.19

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}`);
@@ -1022,21 +1034,22 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
1022
1034
  // Actions structure in ServiceNow:
1023
1035
  // - catalog_ui_policy_action.catalog_variable -> "IO:" + variable_sys_id (required format)
1024
1036
  // - catalog_ui_policy_action.ui_policy -> catalog_ui_policy.sys_id
1037
+ // ✅ CRITICAL FIX: Reference fields MUST be objects or sys_ids, not names!
1038
+ // ServiceNow reference fields expect either:
1039
+ // 1. Just the sys_id as a string
1040
+ // 2. An object with { value: sys_id, link: url }
1025
1041
  const actionData = {
1026
- // ✅ Main connection: to the variable with required IO: prefix (if valid sys_id)
1027
- catalog_variable: catalogVariableWithPrefix
1042
+ // ✅ catalog_variable uses IO:sys_id format (this is a STRING field, not a reference)
1043
+ catalog_variable: catalogVariableWithPrefix,
1044
+ // ✅ ui_policy is a REFERENCE field - use the sys_id directly!
1045
+ ui_policy: policyId, // Use the policy sys_id from sys_ui_policy
1046
+ // ✅ catalog_item is also a REFERENCE field - use the sys_id
1047
+ catalog_item: args.cat_item // The catalog item sys_id
1028
1048
  };
1029
- // CRITICAL FIX: ui_policy field expects the NAME (short_description), NOT the sys_id!
1030
- // ServiceNow uses the policy name as the reference value
1031
- if (args.short_description) {
1032
- actionData.ui_policy = args.short_description; // ✅ Use the policy NAME, not sys_id!
1033
- this.logger.info(`🔗 Linking action to policy by NAME: "${args.short_description}"`);
1034
- }
1035
- else {
1036
- // Fallback if somehow we don't have the name
1037
- this.logger.error(`❌ CRITICAL: No policy name (short_description) available for linking!`);
1038
- actionData.ui_policy = policyId; // Use sys_id as last resort
1039
- }
1049
+ this.logger.info(`🔗 Linking action to:`);
1050
+ this.logger.info(` - Policy: ${policyId} (sys_ui_policy sys_id)`);
1051
+ this.logger.info(` - Variable: ${catalogVariableWithPrefix} (with IO: prefix)`);
1052
+ this.logger.info(` - Catalog Item: ${args.cat_item}`);
1040
1053
  // Voeg alleen GEDEFINIEERDE action properties toe
1041
1054
  if (action.mandatory !== undefined) {
1042
1055
  actionData.mandatory = action.mandatory === true ? 'true' : action.mandatory === false ? 'false' : 'ignore';
@@ -1058,14 +1071,38 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
1058
1071
  if (actionResponse.success) {
1059
1072
  const createdActionId = actionResponse.data.sys_id;
1060
1073
  this.logger.info(`✅ Created action with sys_id: ${createdActionId}`);
1061
- // 🔍 VERIFICATION: Check if action was actually created
1062
- this.logger.info(`🔍 Verifying action ${i + 1} creation...`);
1074
+ // 🔍 VERIFICATION: Check if action was actually created AND fields are populated
1075
+ this.logger.info(`🔍 Verifying action ${i + 1} creation and field population...`);
1063
1076
  const actionVerification = await this.client.searchRecords('catalog_ui_policy_action', `sys_id=${createdActionId}`, 1);
1064
1077
  if (!actionVerification.success || actionVerification.data.result.length === 0) {
1065
1078
  this.logger.error('❌ ACTION VERIFICATION FAILED: Action not found after creation!');
1066
1079
  throw new Error(`Action creation verification failed - action ${i + 1} not found in database`);
1067
1080
  }
1068
- this.logger.info(`✅ Action ${i + 1} verified in database`);
1081
+ // NEW: Verify that critical fields are actually populated
1082
+ const createdAction = actionVerification.data.result[0];
1083
+ this.logger.info(`📋 Created action data:`, {
1084
+ sys_id: createdAction.sys_id,
1085
+ ui_policy: createdAction.ui_policy || '❌ EMPTY',
1086
+ catalog_variable: createdAction.catalog_variable || '❌ EMPTY',
1087
+ catalog_item: createdAction.catalog_item || '❌ EMPTY',
1088
+ visible: createdAction.visible,
1089
+ mandatory: createdAction.mandatory,
1090
+ disabled: createdAction.disabled
1091
+ });
1092
+ // Check if critical fields are populated
1093
+ if (!createdAction.ui_policy || createdAction.ui_policy === '') {
1094
+ this.logger.error(`❌ CRITICAL: ui_policy field is EMPTY for action ${i + 1}!`);
1095
+ throw new Error(`Action ${i + 1} created but ui_policy field is empty - action will not work!`);
1096
+ }
1097
+ if (!createdAction.catalog_variable || createdAction.catalog_variable === '') {
1098
+ this.logger.error(`❌ CRITICAL: catalog_variable field is EMPTY for action ${i + 1}!`);
1099
+ throw new Error(`Action ${i + 1} created but catalog_variable field is empty - action will not work!`);
1100
+ }
1101
+ if (!createdAction.catalog_item || createdAction.catalog_item === '') {
1102
+ this.logger.error(`❌ CRITICAL: catalog_item field is EMPTY for action ${i + 1}!`);
1103
+ throw new Error(`Action ${i + 1} created but catalog_item field is empty - action will not work!`);
1104
+ }
1105
+ this.logger.info(`✅ Action ${i + 1} verified in database with all fields populated`);
1069
1106
  createdActions.push({
1070
1107
  sys_id: createdActionId,
1071
1108
  variable: action.catalog_variable,
@@ -1086,27 +1123,28 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
1086
1123
  }
1087
1124
  }
1088
1125
  }
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);
1126
+ // 🔍 FINAL VERIFICATION: Policy creation in sys_ui_policy table
1127
+ this.logger.info('🔍 Final verification: Checking policy in sys_ui_policy table...');
1128
+ const policyVerification = await this.client.searchRecords('sys_ui_policy', `sys_id=${policyId}`, 1);
1092
1129
  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`);
1130
+ this.logger.error('❌ POLICY VERIFICATION FAILED: Policy not found in sys_ui_policy table!');
1131
+ throw new Error(`Policy creation verification failed - policy not found in sys_ui_policy table`);
1095
1132
  }
1096
- this.logger.info('✅ Policy verified in database');
1133
+ this.logger.info('✅ Policy verified in sys_ui_policy table');
1097
1134
  // Build comprehensive response
1098
- let responseText = `✅ Catalog UI Policy created successfully!
1135
+ let responseText = `✅ UI Policy created successfully in sys_ui_policy table!
1099
1136
 
1100
1137
  📋 **${args.short_description}**
1101
1138
  🆔 Policy sys_id: ${policyId}
1102
- 🎯 Applies to: ${args.applies_to || 'item'}
1139
+ 📊 Table: sys_ui_policy (correct table for catalog UI policy actions)
1140
+ 🎯 Target Table: sc_cat_item
1103
1141
  🔄 Active: ${args.active !== false ? 'Yes' : 'No'}
1104
1142
  ⚡ On Load: ${args.on_load !== false ? 'Yes' : 'No'}
1105
1143
  🔁 Reverse if False: ${args.reverse_if_false !== false ? 'Yes' : 'No'}
1106
1144
 
1107
1145
  🔍 **Verification Results:**
1108
- ✅ Policy record created and verified
1109
- ✅ ${createdActions.length} actions created and verified`;
1146
+ ✅ Policy record created in sys_ui_policy table
1147
+ ✅ ${createdActions.length} actions created in catalog_ui_policy_action table`;
1110
1148
  if (conditionString) {
1111
1149
  responseText += `\n\n📝 **Conditions:**\n${conditionString}`;
1112
1150
  }
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.19",
4
+ "description": "CRITICAL REFERENCE FIELD FIX - v3.6.19 fixes empty action fields by using sys_ids directly for reference fields (ui_policy, catalog_item) instead of names/objects. Added comprehensive verification to ensure all critical fields are populated. Actions now correctly link to sys_ui_policy with actual sys_id values, not empty strings.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
7
7
  "bin": {