Loading...
Loading...
Classification Test Solution Batch Prediction Page does not work when the Input table is a Database View. When training a Workflow Classification solution on a Database View and attempting to test the solution using the Batch Test page, selecting a few records and clicking on Run Test does not return any results. During debugging, it was found that the var outcomeArr solution.predictBatch(table, batch_encodedQuery, 0, 50, 1); inputs are correct, and no issues are observed on the glide API side. However, in the back-end, the localhost logs show an empty prediction (num_top_results0) when the input received by the ML Predictor is empty. Steps to Reproduce 1. Train a Workflow Classification solution using Database View 2. Test a prediction using Test Solution - Batch Test
A workaround is to test your predictions using the provided script below in the System Definition > Background - Scripts module. Please note the following instructions for using the below script: There are five "To Do" sections within the script that need to be updated with the specific items that you are testing. The most critical section is the "encodedQuery" variable. To obtain the necessary information for this variable, you will need to gather all required input fields from your solutions. This can be extracted from the "Single Test" Test Type. In the current version of the script, we used ISNOTEMPTY or ANYTHING to get a prediction. To generate the query, fill in all the required inputs, open the Network tab, and click "Run Test" In the Network tab, under the u_cluser_details_with_change request, click on "payload" to find the query. You can then copy and paste this query into the script and use it in Background - Scripts module. try { // Define the solution name // ToDO - Update this with the solution_name var solutionName = "ml_x_snc_global_global_incident_assignment"; // Fetch the solution var solutionFinder = new sn_ml.SolutionFinder(); var solution = solutionFinder.getSolution(solutionName); if (!solution) { throw new Error('Solution not found: ' + solutionName); } gs.info('Solution: ' + solution); // Query active solution var activeSolution = new GlideRecord("ml_solution"); activeSolution.addQuery("solution_name", solutionName); activeSolution.addQuery("active", "true"); activeSolution.query(); var inputFieldsArray = []; var isPresent = false; if (activeSolution.next()) { isPresent = true; gs.info("Active Solution sys_id: " + activeSolution.getValue("sys_id")); var inputFields = activeSolution.getValue('input_fields'); if (!inputFields) { throw new Error('Input fields not found for solution: ' + solutionName); } gs.info("Input Fields: " + inputFields); inputFieldsArray = inputFields.split(","); gs.info("Input Fields Array: " + JSON.stringify(inputFieldsArray)); } else { throw new Error('Active solution not found for solution name: ' + solutionName); } // Fetch solution version var options = { top_n: 10 }; var solution = sn_ml.ClassificationSolutionStore.get(solutionName); if (!solution) { throw new Error('Solution not found in ClassificationSolutionStore: ' + solutionName); } gs.info('Solution Name: ' + solution); var solutionVersion = solution.getActiveVersion(); if (!solutionVersion) { throw new Error('Active version not found for solution: ' + solutionName); } // Define input table and query // ToDO - Update this with the input table/view used by the solution var table = "u_incident_details_with_change"; // ToDO - Update this with the encoded query to be used for prediction // ToDO - get the encoded query used in BatchPrediction Test Soltion Page, can use the same query here var encodedQuery = "chg_assignment_groupISNOTEMPTY^chg_backout_planISNOTEMPTY^chg_u_code_changeANYTHING^chg_typeANYTHING^inc_descriptionISNOTEMPTY^inc_short_descriptionISNOTEMPTY"; // ToDO - Update this with the limit of records to be fetched for prediction. Default is 1. if 0 all records // satisfying the query will be fetched for predictions var limit = 1; var gr = new GlideRecordSecure(table); // Add encoded query conditionally if (encodedQuery) { gr.addEncodedQuery(encodedQuery); } // Add limit conditionally if (limit > 0) { gr.setLimit(limit); } gr.query(); // Predictions if conditions are met if (isPresent && inputFieldsArray.length >= 1) { gs.info("--- Inside Predict ---"); while (gr.next()) { var input = {}; inputFieldsArray.forEach(function(columnName) { try { var columnNames = columnName.split('.'); if (columnNames.length > 1) { var firstTableFieldName = columnNames[0]; var element = gr.getElement(firstTableFieldName); if (!element) { input[columnName] = gr.getValue(columnName); throw new Error('Element not found or the Element is empty for field: ' + firstTableFieldName); } if (element.getED().getInternalType() == 'reference') { var referenceSysId = gr.getValue(firstTableFieldName); if (!referenceSysId) { input[columnName] = gr.getValue(columnName); throw new Error('Reference sys_id not found or the Reference sys_id is empty for field: ' + firstTableFieldName); } var referenceTable = element.getED().getReference(); var referenceGR = new GlideRecord(referenceTable); if (referenceGR.get(referenceSysId)) { var referenceFieldName = columnNames[1]; var referenceFieldValue = referenceGR.getValue(referenceFieldName); input[columnName] = referenceFieldValue; } else { input[columnName] = gr.getValue(columnName); gs.info("No record found for reference Sys ID: " + referenceSysId); } } else { input[columnName] = gr.getValue(columnName); } } else { input[columnName] = gr.getValue(columnName); } } catch (e) { gs.error('Error processing column ' + columnName + ': ' + e.message); } }); gs.info("---- Input ----"); gs.info(JSON.stringify(input, null, 2)); var inputArray = [input]; // Predictions gs.info("-----Predictions----"); gs.info(solutionVersion.predict(inputArray, options)); } } else { gs.info('No active solution or input fields found.'); } } catch (e) { gs.error('Error: ' + e.message); }
PRB1864265
Click on a version to see all relevant bugs
ServiceNow Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.