snow-flow 3.6.18 → 3.6.20

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.
@@ -799,12 +799,15 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
799
799
  * Create Catalog UI Policy with Actions
800
800
  * Creates records in 2 tables: sys_ui_policy and catalog_ui_policy_action
801
801
  *
802
- * ✅ CORRECTED STRUCTURE (v3.6.18):
802
+ * ✅ FINAL CORRECT STRUCTURE (v3.6.20):
803
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)
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)
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
+ * - visible/mandatory/disabled use "ignore" as default, not false or empty
809
+ * - Reference fields are set directly, not via setValue() for reliability
810
+ * - Enhanced verification ensures all critical fields are populated
808
811
  */
809
812
  async createCatalogUIPolicy(args) {
810
813
  try {
@@ -1034,50 +1037,115 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
1034
1037
  // Actions structure in ServiceNow:
1035
1038
  // - catalog_ui_policy_action.catalog_variable -> "IO:" + variable_sys_id (required format)
1036
1039
  // - catalog_ui_policy_action.ui_policy -> catalog_ui_policy.sys_id
1037
- const actionData = {
1038
- // Main connection: to the variable with required IO: prefix (if valid sys_id)
1039
- catalog_variable: catalogVariableWithPrefix
1040
- };
1041
- // CRITICAL FIX: ui_policy field expects the NAME (short_description), NOT the sys_id!
1042
- // ServiceNow uses the policy name as the reference value
1043
- if (args.short_description) {
1044
- actionData.ui_policy = args.short_description; // Use the policy NAME, not sys_id!
1045
- this.logger.info(`🔗 Linking action to policy by NAME: "${args.short_description}"`);
1040
+ // CRITICAL: Build action data according to ServiceNow's exact structure
1041
+ // catalog_ui_policy_action inherits from sys_ui_policy_action
1042
+ // We must set fields in the correct way for ServiceNow to accept them
1043
+ 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
1046
+ actionData.ui_policy = policyId;
1047
+ // catalog_item is a reference to sc_cat_item - use sys_id directly
1048
+ actionData.catalog_item = args.cat_item;
1049
+ // STEP 2: Set the catalog_variable with IO: prefix (STRING field, not reference)
1050
+ actionData.catalog_variable = catalogVariableWithPrefix;
1051
+ // STEP 3: Set action properties with correct values
1052
+ // ✅ CRITICAL: Use "ignore" instead of not setting or using false
1053
+ // This is how ServiceNow differentiates between "don't change" and "set to false"
1054
+ if (action.visible !== undefined) {
1055
+ actionData.visible = action.visible === true ? 'true' :
1056
+ action.visible === false ? 'false' : 'ignore';
1046
1057
  }
1047
1058
  else {
1048
- // Fallback if somehow we don't have the name
1049
- this.logger.error(`❌ CRITICAL: No policy name (short_description) available for linking!`);
1050
- actionData.ui_policy = policyId; // Use sys_id as last resort
1059
+ actionData.visible = 'ignore'; // Default to ignore if not specified
1051
1060
  }
1052
- // Voeg alleen GEDEFINIEERDE action properties toe
1053
1061
  if (action.mandatory !== undefined) {
1054
- actionData.mandatory = action.mandatory === true ? 'true' : action.mandatory === false ? 'false' : 'ignore';
1062
+ actionData.mandatory = action.mandatory === true ? 'true' :
1063
+ action.mandatory === false ? 'false' : 'ignore';
1055
1064
  }
1056
- if (action.visible !== undefined) {
1057
- actionData.visible = action.visible === false ? 'false' : action.visible === true ? 'true' : 'ignore';
1065
+ else {
1066
+ actionData.mandatory = 'ignore'; // Default to ignore if not specified
1058
1067
  }
1059
1068
  if (action.readonly !== undefined) {
1060
- actionData.disabled = action.readonly === true ? 'true' : action.readonly === false ? 'false' : 'ignore';
1069
+ actionData.disabled = action.readonly === true ? 'true' :
1070
+ action.readonly === false ? 'false' : 'ignore';
1061
1071
  }
1062
- if (action.value) {
1063
- actionData.value = action.value;
1072
+ else {
1073
+ actionData.disabled = 'ignore'; // Default to ignore if not specified
1074
+ }
1075
+ // STEP 4: Set optional value field
1076
+ if (action.value !== undefined && action.value !== null && action.value !== '') {
1077
+ actionData.value = String(action.value);
1064
1078
  }
1065
- // Basis metadata
1079
+ // STEP 5: Set other metadata
1066
1080
  actionData.order = (i + 1) * 100;
1067
1081
  actionData.active = true;
1068
- this.logger.info(`🎯 Attempting to create action ${i + 1}:`, actionData);
1082
+ this.logger.info(`🔗 Creating action with proper structure:`);
1083
+ this.logger.info(` - ui_policy (ref): ${policyId}`);
1084
+ this.logger.info(` - catalog_item (ref): ${args.cat_item}`);
1085
+ this.logger.info(` - catalog_variable: ${catalogVariableWithPrefix}`);
1086
+ this.logger.info(` - visible: ${actionData.visible}`);
1087
+ this.logger.info(` - mandatory: ${actionData.mandatory}`);
1088
+ this.logger.info(` - disabled: ${actionData.disabled}`);
1089
+ this.logger.info(`🎯 Attempting to create action ${i + 1} in catalog_ui_policy_action table...`);
1069
1090
  const actionResponse = await this.client.createRecord('catalog_ui_policy_action', actionData);
1070
1091
  if (actionResponse.success) {
1071
1092
  const createdActionId = actionResponse.data.sys_id;
1072
1093
  this.logger.info(`✅ Created action with sys_id: ${createdActionId}`);
1073
- // 🔍 VERIFICATION: Check if action was actually created
1074
- this.logger.info(`🔍 Verifying action ${i + 1} creation...`);
1094
+ // 🔍 VERIFICATION: Check if action was actually created AND fields are populated
1095
+ this.logger.info(`🔍 Verifying action ${i + 1} creation and field population...`);
1075
1096
  const actionVerification = await this.client.searchRecords('catalog_ui_policy_action', `sys_id=${createdActionId}`, 1);
1076
1097
  if (!actionVerification.success || actionVerification.data.result.length === 0) {
1077
1098
  this.logger.error('❌ ACTION VERIFICATION FAILED: Action not found after creation!');
1078
1099
  throw new Error(`Action creation verification failed - action ${i + 1} not found in database`);
1079
1100
  }
1080
- this.logger.info(`✅ Action ${i + 1} verified in database`);
1101
+ // NEW: Verify that critical fields are actually populated
1102
+ const createdAction = actionVerification.data.result[0];
1103
+ this.logger.info(`📋 Created action data:`, {
1104
+ sys_id: createdAction.sys_id,
1105
+ ui_policy: createdAction.ui_policy || '❌ EMPTY',
1106
+ catalog_variable: createdAction.catalog_variable || '❌ EMPTY',
1107
+ catalog_item: createdAction.catalog_item || '❌ EMPTY',
1108
+ visible: createdAction.visible,
1109
+ mandatory: createdAction.mandatory,
1110
+ disabled: createdAction.disabled
1111
+ });
1112
+ // ✅ ENHANCED VERIFICATION: Check if critical fields are populated correctly
1113
+ const uiPolicyValue = createdAction.ui_policy;
1114
+ const catalogVariableValue = createdAction.catalog_variable;
1115
+ const catalogItemValue = createdAction.catalog_item;
1116
+ // Check ui_policy reference
1117
+ if (!uiPolicyValue || uiPolicyValue === '' || uiPolicyValue === '{}') {
1118
+ 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!`);
1121
+ }
1122
+ // For reference fields, ServiceNow might return an object - extract the value
1123
+ const uiPolicySysId = typeof uiPolicyValue === 'object' && uiPolicyValue.value ?
1124
+ uiPolicyValue.value : uiPolicyValue;
1125
+ if (uiPolicySysId !== policyId) {
1126
+ this.logger.warn(`⚠️ ui_policy mismatch - Expected: ${policyId}, Got: ${uiPolicySysId}`);
1127
+ }
1128
+ // Check catalog_variable (should have IO: prefix)
1129
+ if (!catalogVariableValue || catalogVariableValue === '') {
1130
+ this.logger.error(`❌ CRITICAL: catalog_variable field is EMPTY for action ${i + 1}!`);
1131
+ this.logger.error(`❌ Expected: ${catalogVariableWithPrefix}, Got: ${catalogVariableValue}`);
1132
+ throw new Error(`Action ${i + 1} created but catalog_variable field is empty - action will not work!`);
1133
+ }
1134
+ if (!catalogVariableValue.startsWith('IO:')) {
1135
+ this.logger.warn(`⚠️ catalog_variable missing IO: prefix - Got: ${catalogVariableValue}`);
1136
+ }
1137
+ // Check catalog_item reference
1138
+ if (!catalogItemValue || catalogItemValue === '' || catalogItemValue === '{}') {
1139
+ this.logger.error(`❌ CRITICAL: catalog_item field is EMPTY for action ${i + 1}!`);
1140
+ this.logger.error(`❌ Expected: ${args.cat_item}, Got: ${catalogItemValue}`);
1141
+ throw new Error(`Action ${i + 1} created but catalog_item field is empty - action will not work!`);
1142
+ }
1143
+ const catalogItemSysId = typeof catalogItemValue === 'object' && catalogItemValue.value ?
1144
+ catalogItemValue.value : catalogItemValue;
1145
+ if (catalogItemSysId !== args.cat_item) {
1146
+ this.logger.warn(`⚠️ catalog_item mismatch - Expected: ${args.cat_item}, Got: ${catalogItemSysId}`);
1147
+ }
1148
+ this.logger.info(`✅ Action ${i + 1} verified in database with all fields populated`);
1081
1149
  createdActions.push({
1082
1150
  sys_id: createdActionId,
1083
1151
  variable: action.catalog_variable,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snow-flow",
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.",
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.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
7
7
  "bin": {