snow-flow 3.6.19 → 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,39 +1037,56 @@ ${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
- // ✅ 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 }
1041
- const actionData = {
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
1048
- };
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}`);
1053
- // Voeg alleen GEDEFINIEERDE action properties toe
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';
1057
+ }
1058
+ else {
1059
+ actionData.visible = 'ignore'; // Default to ignore if not specified
1060
+ }
1054
1061
  if (action.mandatory !== undefined) {
1055
- actionData.mandatory = action.mandatory === true ? 'true' : action.mandatory === false ? 'false' : 'ignore';
1062
+ actionData.mandatory = action.mandatory === true ? 'true' :
1063
+ action.mandatory === false ? 'false' : 'ignore';
1056
1064
  }
1057
- if (action.visible !== undefined) {
1058
- actionData.visible = action.visible === false ? 'false' : action.visible === true ? 'true' : 'ignore';
1065
+ else {
1066
+ actionData.mandatory = 'ignore'; // Default to ignore if not specified
1059
1067
  }
1060
1068
  if (action.readonly !== undefined) {
1061
- actionData.disabled = action.readonly === true ? 'true' : action.readonly === false ? 'false' : 'ignore';
1069
+ actionData.disabled = action.readonly === true ? 'true' :
1070
+ action.readonly === false ? 'false' : 'ignore';
1071
+ }
1072
+ else {
1073
+ actionData.disabled = 'ignore'; // Default to ignore if not specified
1062
1074
  }
1063
- if (action.value) {
1064
- actionData.value = action.value;
1075
+ // STEP 4: Set optional value field
1076
+ if (action.value !== undefined && action.value !== null && action.value !== '') {
1077
+ actionData.value = String(action.value);
1065
1078
  }
1066
- // Basis metadata
1079
+ // STEP 5: Set other metadata
1067
1080
  actionData.order = (i + 1) * 100;
1068
1081
  actionData.active = true;
1069
- 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...`);
1070
1090
  const actionResponse = await this.client.createRecord('catalog_ui_policy_action', actionData);
1071
1091
  if (actionResponse.success) {
1072
1092
  const createdActionId = actionResponse.data.sys_id;
@@ -1089,19 +1109,42 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
1089
1109
  mandatory: createdAction.mandatory,
1090
1110
  disabled: createdAction.disabled
1091
1111
  });
1092
- // Check if critical fields are populated
1093
- if (!createdAction.ui_policy || createdAction.ui_policy === '') {
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 === '{}') {
1094
1118
  this.logger.error(`❌ CRITICAL: ui_policy field is EMPTY for action ${i + 1}!`);
1119
+ this.logger.error(`❌ Expected: ${policyId}, Got: ${uiPolicyValue}`);
1095
1120
  throw new Error(`Action ${i + 1} created but ui_policy field is empty - action will not work!`);
1096
1121
  }
1097
- if (!createdAction.catalog_variable || createdAction.catalog_variable === '') {
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 === '') {
1098
1130
  this.logger.error(`❌ CRITICAL: catalog_variable field is EMPTY for action ${i + 1}!`);
1131
+ this.logger.error(`❌ Expected: ${catalogVariableWithPrefix}, Got: ${catalogVariableValue}`);
1099
1132
  throw new Error(`Action ${i + 1} created but catalog_variable field is empty - action will not work!`);
1100
1133
  }
1101
- if (!createdAction.catalog_item || createdAction.catalog_item === '') {
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 === '{}') {
1102
1139
  this.logger.error(`❌ CRITICAL: catalog_item field is EMPTY for action ${i + 1}!`);
1140
+ this.logger.error(`❌ Expected: ${args.cat_item}, Got: ${catalogItemValue}`);
1103
1141
  throw new Error(`Action ${i + 1} created but catalog_item field is empty - action will not work!`);
1104
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
+ }
1105
1148
  this.logger.info(`✅ Action ${i + 1} verified in database with all fields populated`);
1106
1149
  createdActions.push({
1107
1150
  sys_id: createdActionId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snow-flow",
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.",
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": {