AI Banner Display(CSM module)

SandeepKSingh
Kilo Sage

on "sn_customerservice_case" what I need is to  designed a display a message on a ServiceNow form, alerting users to check certain fields that have been predicted by AI for accuracy. 
OOB script include "CSMAIDisplayAjax" is there already. Can anyone help me out

3 ACCEPTED SOLUTIONS

Ravi Gaurav
Giga Sage

Hello,

Its OOB script we can use :-

 

function onLoad() {
    if (g_form.isNewRecord())
        return;

    var tableName = g_form.getTableName();
    var sysId = g_form.getUniqueValue();
    var ga = new GlideAjax('CSMAIDisplayAjax');
    ga.addParam('sysparm_name', 'getPredictionResults');
    ga.addParam('sysparm_sys_id', sysId);
    ga.addParam('sysparm_table_name', tableName);
    ga.getXML(handleResponse);

    function handleResponse(response) {
        var predictionsResults = response.responseXML.documentElement.getAttribute("answer");
        var displayedBanner = false;
        if (predictionsResults) {
            predictionsResults = JSON.parse(predictionsResults);
            var predictedfieldLabel = [];
            var predictedfield = [];
            for (var i = 0; i < predictionsResults.length; i++) {
                var prediction = predictionsResults[i];
                if (prediction.displayBanner == "true" && g_form.getValue(prediction.predictedField)) {
                    predictedfieldLabel.push(prediction.predictedFieldlabel);
                    predictedfield.push(prediction.predictedField);
                    displayedBanner = true;
                }
            }
            if (displayedBanner) {
                if (typeof GwtMessage === 'function') {
                    // for platform
                    var message = getMessage("Check fields predicted by AI for accuracy: {0}");
                    var labels = predictedfieldLabel.join(', ');
                    g_form.addInfoMessage(message.withValues([labels]));
                }
                else
                    g_form.addFormMessage('Check fields predicted by AI for accuracy: ', 'suggestion', {linksToFields : predictedfield});
            }
        }
    }
}
 

View solution in original post

Ravi Gaurav
Giga Sage

Can you confirm whether it worked or not ??

View solution in original post

Ravi Gaurav
Giga Sage

One More Easy way is below :-->

Create a Client Script: To display a message on the form, you can use a Client Script to execute the logic and display the message. The Client Script will call the Script Include method to fetch any prediction results and then use those results to display a message.

Here’s an example of a Client Script that could be used:

// Client Script: onLoad (function executeRule(current, previous /*null when async*/) { // Call the Script Include function to get predictions var gr = new GlideAjax('CSMAIDisplayAjax'); gr.addParam('sys_id', current.sys_id); gr.getXMLAnswer(function(response) { var result = response.responseXML.documentElement.getAttribute("answer"); if (result) { // Display message based on the result g_form.addInfoMessage('AI has predicted some fields for accuracy check: ' + result); } }); })(current, previous);
  • This script sends the sys_id of the current record to the Script Include and retrieves a response.
  • It then displays an info message on the form with the result.

     

    var CSMAIDisplayAjax = Class.create(); CSMAIDisplayAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, { getPredictedFields: function() { var sys_id = this.getParameter('sys_id'); // Example logic to retrieve predictions var message = this.getPredictions(sys_id); // Implement this function as needed return message; }, getPredictions: function(sys_id) { // Add logic to fetch and return predictions based on sys_id // Example: var predictions = 'Field1, Field2'; // Placeholder for actual predictions return predictions; } });
  1.  

View solution in original post

6 REPLIES 6

can you show a screenshot of it in action ?

Ravi Gaurav
Giga Sage

One More Easy way is below :-->

Create a Client Script: To display a message on the form, you can use a Client Script to execute the logic and display the message. The Client Script will call the Script Include method to fetch any prediction results and then use those results to display a message.

Here’s an example of a Client Script that could be used:

// Client Script: onLoad (function executeRule(current, previous /*null when async*/) { // Call the Script Include function to get predictions var gr = new GlideAjax('CSMAIDisplayAjax'); gr.addParam('sys_id', current.sys_id); gr.getXMLAnswer(function(response) { var result = response.responseXML.documentElement.getAttribute("answer"); if (result) { // Display message based on the result g_form.addInfoMessage('AI has predicted some fields for accuracy check: ' + result); } }); })(current, previous);
  • This script sends the sys_id of the current record to the Script Include and retrieves a response.
  • It then displays an info message on the form with the result.

     

    var CSMAIDisplayAjax = Class.create(); CSMAIDisplayAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, { getPredictedFields: function() { var sys_id = this.getParameter('sys_id'); // Example logic to retrieve predictions var message = this.getPredictions(sys_id); // Implement this function as needed return message; }, getPredictions: function(sys_id) { // Add logic to fetch and return predictions based on sys_id // Example: var predictions = 'Field1, Field2'; // Placeholder for actual predictions return predictions; } });
  1.