snow-flow 3.6.16 → 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:
|
|
800
|
+
* Creates records in 2 tables: sys_ui_policy and catalog_ui_policy_action
|
|
801
801
|
*
|
|
802
|
-
*
|
|
803
|
-
* -
|
|
804
|
-
* -
|
|
805
|
-
* -
|
|
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 = `${
|
|
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 = `${
|
|
968
|
+
conditionPart = `${variableWithIOPrefix}${serviceNowOperator}${conditionValue}`;
|
|
960
969
|
}
|
|
961
970
|
else {
|
|
962
971
|
// Standard operations (=, !=, >, <, etc.)
|
|
963
|
-
conditionPart = `${
|
|
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
|
-
//
|
|
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
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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('
|
|
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}`);
|
|
@@ -1026,11 +1038,16 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
|
|
|
1026
1038
|
// ✅ Main connection: to the variable with required IO: prefix (if valid sys_id)
|
|
1027
1039
|
catalog_variable: catalogVariableWithPrefix
|
|
1028
1040
|
};
|
|
1029
|
-
//
|
|
1030
|
-
//
|
|
1031
|
-
if (
|
|
1032
|
-
//
|
|
1033
|
-
|
|
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}"`);
|
|
1046
|
+
}
|
|
1047
|
+
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
|
|
1034
1051
|
}
|
|
1035
1052
|
// Voeg alleen GEDEFINIEERDE action properties toe
|
|
1036
1053
|
if (action.mandatory !== undefined) {
|
|
@@ -1081,27 +1098,28 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
|
|
|
1081
1098
|
}
|
|
1082
1099
|
}
|
|
1083
1100
|
}
|
|
1084
|
-
// 🔍 FINAL VERIFICATION: Policy creation
|
|
1085
|
-
this.logger.info('🔍 Final verification: Checking policy in
|
|
1086
|
-
const policyVerification = await this.client.searchRecords('
|
|
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);
|
|
1087
1104
|
if (!policyVerification.success || policyVerification.data.result.length === 0) {
|
|
1088
|
-
this.logger.error('❌ POLICY VERIFICATION FAILED: Policy not found
|
|
1089
|
-
throw new Error(`Policy creation verification failed - policy not found in
|
|
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`);
|
|
1090
1107
|
}
|
|
1091
|
-
this.logger.info('✅ Policy verified in
|
|
1108
|
+
this.logger.info('✅ Policy verified in sys_ui_policy table');
|
|
1092
1109
|
// Build comprehensive response
|
|
1093
|
-
let responseText = `✅
|
|
1110
|
+
let responseText = `✅ UI Policy created successfully in sys_ui_policy table!
|
|
1094
1111
|
|
|
1095
1112
|
📋 **${args.short_description}**
|
|
1096
1113
|
🆔 Policy sys_id: ${policyId}
|
|
1097
|
-
|
|
1114
|
+
📊 Table: sys_ui_policy (correct table for catalog UI policy actions)
|
|
1115
|
+
🎯 Target Table: sc_cat_item
|
|
1098
1116
|
🔄 Active: ${args.active !== false ? 'Yes' : 'No'}
|
|
1099
1117
|
⚡ On Load: ${args.on_load !== false ? 'Yes' : 'No'}
|
|
1100
1118
|
🔁 Reverse if False: ${args.reverse_if_false !== false ? 'Yes' : 'No'}
|
|
1101
1119
|
|
|
1102
1120
|
🔍 **Verification Results:**
|
|
1103
|
-
✅ Policy record created
|
|
1104
|
-
✅ ${createdActions.length} actions created
|
|
1121
|
+
✅ Policy record created in sys_ui_policy table
|
|
1122
|
+
✅ ${createdActions.length} actions created in catalog_ui_policy_action table`;
|
|
1105
1123
|
if (conditionString) {
|
|
1106
1124
|
responseText += `\n\n📝 **Conditions:**\n${conditionString}`;
|
|
1107
1125
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snow-flow",
|
|
3
|
-
"version": "3.6.
|
|
4
|
-
"description": "
|
|
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": {
|