snow-flow 3.6.12 β†’ 3.6.14

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.
@@ -724,23 +724,53 @@ ${args.recurring_price && args.recurring_price !== '0' ? `πŸ”„ Recurring: $${arg
724
724
  */
725
725
  async createCatalogVariable(args) {
726
726
  try {
727
- this.logger.info('Creating catalog variable...');
727
+ this.logger.info('Creating catalog variable...', { name: args.name, cat_item: args.cat_item });
728
+ // Add ESSENTIAL missing fields that might be required
728
729
  const variableData = {
730
+ // Required fields
729
731
  cat_item: args.cat_item,
730
732
  name: args.name,
731
733
  question_text: args.question_text,
732
- type: args.type,
734
+ type: args.type || '1', // Default to string type
735
+ // Essential fields that were missing
736
+ active: true, // βœ… CRITICAL: Must be active
733
737
  order: args.order || 100,
734
738
  mandatory: args.mandatory || false,
739
+ // Display settings
740
+ display_type: args.display_type || 'normal',
741
+ // Values
735
742
  default_value: args.default_value || '',
736
743
  help_text: args.help_text || '',
744
+ // References and choices
737
745
  reference: args.reference || '',
738
- choice_table: args.choice_table || ''
746
+ choice_table: args.choice_table || '',
747
+ // Security fields (might be required)
748
+ write_roles: args.write_roles || '',
749
+ read_roles: args.read_roles || '',
750
+ // Additional fields
751
+ example_text: args.example_text || '',
752
+ tooltip: args.tooltip || ''
739
753
  };
754
+ this.logger.info('🎯 Creating variable with payload:', variableData);
740
755
  const response = await this.client.createRecord('item_option_new', variableData);
741
756
  if (!response.success) {
757
+ this.logger.error('❌ Variable creation failed:', {
758
+ error: response.error,
759
+ payload: variableData,
760
+ status: response.status
761
+ });
742
762
  throw new Error(`Failed to create catalog variable: ${response.error}`);
743
763
  }
764
+ const createdSysId = response.data.sys_id;
765
+ this.logger.info(`βœ… Variable created with sys_id: ${createdSysId}`);
766
+ // πŸ” VERIFICATION: Check if variable was actually created
767
+ this.logger.info('πŸ” Verifying variable creation...');
768
+ const verification = await this.client.searchRecords('item_option_new', `sys_id=${createdSysId}`, 1);
769
+ if (!verification.success || verification.data.result.length === 0) {
770
+ this.logger.error('❌ VERIFICATION FAILED: Variable not found after creation!');
771
+ throw new Error(`Variable creation verification failed - not found in database`);
772
+ }
773
+ this.logger.info('βœ… Variable verified in database');
744
774
  return {
745
775
  content: [{
746
776
  type: 'text',
@@ -792,7 +822,14 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
792
822
  };
793
823
  // Build condition string from conditions array
794
824
  let conditionString = '';
825
+ this.logger.info('Checking conditions parameter:', {
826
+ hasConditions: !!args.conditions,
827
+ isArray: Array.isArray(args.conditions),
828
+ length: args.conditions ? args.conditions.length : 0,
829
+ conditionsData: args.conditions
830
+ });
795
831
  if (args.conditions && Array.isArray(args.conditions)) {
832
+ this.logger.info(`🎯 Building conditions string from ${args.conditions.length} conditions...`);
796
833
  const conditionParts = [];
797
834
  for (const condition of args.conditions) {
798
835
  // Resolve variable name to sys_id
@@ -840,8 +877,9 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
840
877
  }
841
878
  conditionParts.push(conditionPart);
842
879
  }
843
- // Join all conditions
844
- conditionString = conditionParts.join('');
880
+ // Join all conditions with ^ separator (ServiceNow query format)
881
+ conditionString = conditionParts.join('^');
882
+ this.logger.info(`βœ… Built conditions string: "${conditionString}"`);
845
883
  }
846
884
  // Step 1: Create main catalog UI policy record with embedded conditions
847
885
  const policyData = {
@@ -856,59 +894,103 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
856
894
  script_true: args.script_true || '',
857
895
  script_false: args.script_false || ''
858
896
  };
897
+ this.logger.info('🎯 Creating main policy with data:', policyData);
859
898
  const policyResponse = await this.client.createRecord('catalog_ui_policy', policyData);
860
899
  if (!policyResponse.success) {
900
+ this.logger.error('❌ Policy creation failed:', policyResponse.error);
861
901
  throw new Error(`Failed to create catalog UI policy: ${policyResponse.error}`);
862
902
  }
863
903
  const policyId = policyResponse.data.sys_id;
864
- this.logger.info(`Created main policy with sys_id: ${policyId}`);
904
+ this.logger.info(`βœ… Created main policy with sys_id: ${policyId}`);
865
905
  const createdActions = [];
866
906
  // Step 2: Create action records (dit werkt wel met aparte tabel)
907
+ this.logger.info('Checking actions parameter:', {
908
+ hasActions: !!args.actions,
909
+ isArray: Array.isArray(args.actions),
910
+ length: args.actions ? args.actions.length : 0,
911
+ actionsData: args.actions
912
+ });
867
913
  if (args.actions && Array.isArray(args.actions)) {
868
- this.logger.info(`Creating ${args.actions.length} action records...`);
914
+ this.logger.info(`🎯 Starting to create ${args.actions.length} action records...`);
869
915
  for (let i = 0; i < args.actions.length; i++) {
870
916
  const action = args.actions[i];
871
917
  // Resolve variable name to sys_id
918
+ this.logger.info(`πŸ” Resolving variable: ${action.catalog_variable} for catalog item: ${args.cat_item}`);
872
919
  const variableId = await resolveVariableId(action.catalog_variable, args.cat_item);
920
+ this.logger.info(`βœ… Resolved to variable ID: ${variableId}`);
873
921
  // Actions structuur in ServiceNow:
874
922
  // - catalog_ui_policy_action.catalog_variable -> item_option_new (variable)
875
923
  // - item_option_new.cat_item -> sc_cat_item (catalog item)
876
924
  // - catalog_ui_policy.catalog_item -> sc_cat_item (catalog item)
877
925
  // Mogelijk is er toch een ui_policy veld, maar het lijkt niet verplicht
926
+ // MINIMAAL: Probeer eerst alleen de essentiΓ«le velden
878
927
  const actionData = {
879
- // Primaire koppeling: naar de variable
880
- catalog_variable: variableId, // Verplicht: koppeling naar variable
881
- // Mogelijk ook een policy koppeling (als het veld bestaat)
882
- ui_policy: policyId, // Probeer dit ook, kan optioneel zijn
883
- // Action settings - gebruik strings zoals ServiceNow verwacht
884
- mandatory: action.mandatory === true ? 'true' : action.mandatory === false ? 'false' : 'ignore',
885
- visible: action.visible === false ? 'false' : action.visible === true ? 'true' : 'ignore',
886
- disabled: action.readonly === true ? 'true' : action.readonly === false ? 'false' : 'ignore',
887
- // Waarde velden (voor set_value acties)
888
- value: action.value || '',
889
- // Metadata
890
- order: (i + 1) * 100,
891
- active: true
928
+ // Hoofdkoppeling: naar de variable (dit MOET kloppen)
929
+ catalog_variable: variableId
892
930
  };
893
- this.logger.info(`Attempting to create action ${i + 1}:`, actionData);
931
+ // NIET: catalog_ui_policy - deze veld bestaat NIET (volgens error log)
932
+ // Probeer alleen ui_policy en policy als alternatief
933
+ if (policyId) {
934
+ // Probeer ui_policy (dit is waarschijnlijk correct)
935
+ actionData.ui_policy = policyId;
936
+ }
937
+ // Voeg alleen GEDEFINIEERDE action properties toe
938
+ if (action.mandatory !== undefined) {
939
+ actionData.mandatory = action.mandatory === true ? 'true' : action.mandatory === false ? 'false' : 'ignore';
940
+ }
941
+ if (action.visible !== undefined) {
942
+ actionData.visible = action.visible === false ? 'false' : action.visible === true ? 'true' : 'ignore';
943
+ }
944
+ if (action.readonly !== undefined) {
945
+ actionData.disabled = action.readonly === true ? 'true' : action.readonly === false ? 'false' : 'ignore';
946
+ }
947
+ if (action.value) {
948
+ actionData.value = action.value;
949
+ }
950
+ // Basis metadata
951
+ actionData.order = (i + 1) * 100;
952
+ actionData.active = true;
953
+ this.logger.info(`🎯 Attempting to create action ${i + 1}:`, actionData);
894
954
  const actionResponse = await this.client.createRecord('catalog_ui_policy_action', actionData);
895
955
  if (actionResponse.success) {
956
+ const createdActionId = actionResponse.data.sys_id;
957
+ this.logger.info(`βœ… Created action with sys_id: ${createdActionId}`);
958
+ // πŸ” VERIFICATION: Check if action was actually created
959
+ this.logger.info(`πŸ” Verifying action ${i + 1} creation...`);
960
+ const actionVerification = await this.client.searchRecords('catalog_ui_policy_action', `sys_id=${createdActionId}`, 1);
961
+ if (!actionVerification.success || actionVerification.data.result.length === 0) {
962
+ this.logger.error('❌ ACTION VERIFICATION FAILED: Action not found after creation!');
963
+ throw new Error(`Action creation verification failed - action ${i + 1} not found in database`);
964
+ }
965
+ this.logger.info(`βœ… Action ${i + 1} verified in database`);
896
966
  createdActions.push({
897
- sys_id: actionResponse.data.sys_id,
967
+ sys_id: createdActionId,
898
968
  variable: action.catalog_variable,
899
969
  details: this.formatActionDetails(action)
900
970
  });
901
- this.logger.info(`βœ… Created action: ${action.type || 'default'} for ${action.catalog_variable}`);
902
971
  }
903
972
  else {
904
973
  const errorMsg = `❌ Failed to create action ${i + 1}: ${actionResponse.error || 'Unknown error'}`;
905
974
  this.logger.error(errorMsg);
906
- this.logger.error('Action data was:', actionData);
975
+ this.logger.error('❌ Action data was:', actionData);
976
+ this.logger.error('❌ Response details:', {
977
+ status: actionResponse.status,
978
+ headers: actionResponse.headers,
979
+ data: actionResponse.data
980
+ });
907
981
  // BELANGRIJK: Gooi een error zodat de gebruiker weet dat het faalt!
908
982
  throw new Error(errorMsg);
909
983
  }
910
984
  }
911
985
  }
986
+ // πŸ” FINAL VERIFICATION: Policy creation
987
+ this.logger.info('πŸ” Final verification: Checking policy in database...');
988
+ const policyVerification = await this.client.searchRecords('catalog_ui_policy', `sys_id=${policyId}`, 1);
989
+ if (!policyVerification.success || policyVerification.data.result.length === 0) {
990
+ this.logger.error('❌ POLICY VERIFICATION FAILED: Policy not found after creation!');
991
+ throw new Error(`Policy creation verification failed - policy not found in database`);
992
+ }
993
+ this.logger.info('βœ… Policy verified in database');
912
994
  // Build comprehensive response
913
995
  let responseText = `βœ… Catalog UI Policy created successfully!
914
996
 
@@ -917,7 +999,11 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
917
999
  🎯 Applies to: ${args.applies_to || 'item'}
918
1000
  πŸ”„ Active: ${args.active !== false ? 'Yes' : 'No'}
919
1001
  ⚑ On Load: ${args.on_load !== false ? 'Yes' : 'No'}
920
- πŸ” Reverse if False: ${args.reverse_if_false !== false ? 'Yes' : 'No'}`;
1002
+ πŸ” Reverse if False: ${args.reverse_if_false !== false ? 'Yes' : 'No'}
1003
+
1004
+ πŸ” **Verification Results:**
1005
+ βœ… Policy record created and verified
1006
+ βœ… ${createdActions.length} actions created and verified`;
921
1007
  if (conditionString) {
922
1008
  responseText += `\n\nπŸ“ **Conditions:**\n${conditionString}`;
923
1009
  }
@@ -940,27 +1026,6 @@ ${args.help_text ? `❓ Help: ${args.help_text}` : ''}
940
1026
  throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Failed to create catalog UI policy: ${error}`);
941
1027
  }
942
1028
  }
943
- /**
944
- * Helper function to determine action type based on provided fields
945
- * Note: ServiceNow might not use 'type' field, actions are determined by field values
946
- */
947
- determineActionType(action) {
948
- // ServiceNow bepaalt het type waarschijnlijk op basis van de velden zelf
949
- // Dit is alleen voor logging/display
950
- if (action.value !== undefined && action.value !== '') {
951
- return 'set_value';
952
- }
953
- if (action.mandatory === true) {
954
- return 'set_mandatory';
955
- }
956
- if (action.visible === false) {
957
- return 'set_hidden';
958
- }
959
- if (action.readonly === true) {
960
- return 'set_readonly';
961
- }
962
- return 'default';
963
- }
964
1029
  /**
965
1030
  * Helper function to format action details for display
966
1031
  */
@@ -1148,10 +1213,36 @@ ${args.special_instructions ? `πŸ“ Instructions: ${args.special_instructions}`
1148
1213
  */
1149
1214
  async getCatalogItemDetails(args) {
1150
1215
  try {
1151
- this.logger.info('Getting catalog item details...');
1152
- const itemResponse = await this.client.getRecord('sc_cat_item', args.sys_id);
1216
+ this.logger.info('Getting catalog item details...', { sys_id: args.sys_id });
1217
+ // πŸ” DEBUGGING: Try different methods to find the item
1218
+ this.logger.info('πŸ” Step 1: Trying getRecord method...');
1219
+ let itemResponse = await this.client.getRecord('sc_cat_item', args.sys_id);
1153
1220
  if (!itemResponse.success) {
1154
- throw new Error('Catalog item not found');
1221
+ this.logger.warn('❌ getRecord failed, trying searchRecords as fallback...');
1222
+ this.logger.warn('getRecord error:', itemResponse.error);
1223
+ // Fallback: try searchRecords method
1224
+ itemResponse = await this.client.searchRecords('sc_cat_item', `sys_id=${args.sys_id}`, 1);
1225
+ if (!itemResponse.success || itemResponse.data.result.length === 0) {
1226
+ this.logger.error('❌ Both getRecord and searchRecords failed');
1227
+ this.logger.error('searchRecords error:', itemResponse.error);
1228
+ // Final fallback: try to query with different parameters
1229
+ const queryResponse = await this.client.queryTable('sc_cat_item', `sys_id=${args.sys_id}`, 1);
1230
+ if (queryResponse.success && queryResponse.data.result.length > 0) {
1231
+ this.logger.info('βœ… Found item using queryTable fallback');
1232
+ itemResponse = { success: true, data: queryResponse.data.result[0] };
1233
+ }
1234
+ else {
1235
+ this.logger.error('❌ All methods failed to find catalog item');
1236
+ throw new Error(`Catalog item not found with sys_id: ${args.sys_id}. Tried getRecord, searchRecords, and queryTable.`);
1237
+ }
1238
+ }
1239
+ else {
1240
+ this.logger.info('βœ… Found item using searchRecords fallback');
1241
+ itemResponse = { success: true, data: itemResponse.data.result[0] };
1242
+ }
1243
+ }
1244
+ else {
1245
+ this.logger.info('βœ… Found item using getRecord');
1155
1246
  }
1156
1247
  const item = itemResponse.data;
1157
1248
  let details = `πŸ›οΈ **${item.name}**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "3.6.12",
4
- "description": "COMPLETE UI POLICY FIX - v3.6.12 fixes both policy and actions. Policy uses catalog_item + applies_to fields. Actions link to catalog_variable. Conditions stored as query string. Based on actual ServiceNow table structure.",
3
+ "version": "3.6.14",
4
+ "description": "COMPREHENSIVE CATALOG FIXES - v3.6.14 fixes ALL catalog tools based on user feedback. snow_create_catalog_variable: added missing essential fields (active, display_type, security). snow_get_catalog_item_details: 3-method fallback system. snow_create_catalog_ui_policy: verification after creation. All tools now have extensive debugging and verification.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
7
7
  "bin": {