i plan to create a SP widget with Chatgpt integrate summaries the ticket and provide recommendation

chercm
Mega Sage

i plan to create a SP widget with Chatgpt integrate where the user enters the serial number of the laptop and it will pull out all the ticket and provide summaries the ticket and provide recommendation

 

<!-- Widget HTML -->

<div class="incident-widget">

  <h2>ChatGPT Incident Summary</h2>

  <div class="input-container">

    <label for="assetInput">Enter Impacted Asset:</label>

    <input type="text" id="assetInput" placeholder="Asset Name">

    <button onclick="fetchIncidentData()">Fetch Data</button>

  </div>

  <div id="summaryContainer"></div>

</div>

 

<!-- ChatGPT iframe -->

<iframe id="chatGPTFrame" src="https://your-chatgpt-url.com" width="100%" height="500px"></iframe>

 

 

CSS 

 

/* Widget Styles */

.incident-widget {

  padding: 20px;

  border: 1px solid #ccc;

  border-radius: 5px;

  margin-bottom: 20px;

}

 

.input-container {

  margin-top: 10px;

}

 

server script 

 

/ IncidentWidgetScriptInclude

var IncidentWidgetScriptInclude = Class.create();

 

IncidentWidgetScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  getIncidentData: function() {

    var assetName = this.getParameter('sysparm_asset');

    

    var incidentTable = new GlideRecord('incident');

    incidentTable.addQuery('asset', assetName);

    incidentTable.query();

 

    var result = [];

 

    while (incidentTable.next()) {

      var summary = incidentTable.getValue('short_description');

      var recommendation = incidentTable.getValue('recommendation_field');

 

      result.push({

        summary: summary,

        recommendation: recommendation

      });

    }

 

    return JSON.stringify(result);

  },

 

  type: 'IncidentWidgetScriptInclude'

});

 

Client  : 

 

/// Widget Client Script

function fetchIncidentData() {

  var assetName = document.getElementById('assetInput').value;

 

  // Use GlideAjax to call the server script

  var ga = new GlideAjax('IncidentWidgetScriptInclude');

  ga.addParam('sysparm_name', 'getIncidentData');

  ga.addParam('sysparm_asset', assetName);

  ga.getXMLAnswer(function(response) {

    var data = JSON.parse(response);

 

    // Process data and update the summary container

    var summaryContainer = document.getElementById('summaryContainer');

    summaryContainer.innerHTML = '<h3>Incident Summary:</h3>';

 

    data.forEach(incident => {

      var summary = incident.summary;

      var recommendation = incident.recommendation;

 

      // Display incident summary

      summaryContainer.innerHTML += `<p><strong>Summary:</strong> ${summary}</p>`;

      summaryContainer.innerHTML += `<p><strong>Recommendation:</strong> ${recommendation}</p>`;

    });

  });

}

 

var assetName = 'your_impacted_asset_name';

var incidentTable = new GlideRecord('incident');

incidentTable.addQuery('asset', assetName);

incidentTable.query();

 

while (incidentTable.next()) {

    // Process each incident record

    var summary = incidentTable.getValue('short_description');

    var recommendation = incidentTable.getValue('your_recommendation_field');

    

    // Add logic to compile summary and recommendation

}

 

      // Display incident summary

      summaryContainer.innerHTML += `<p><strong>Summary:</strong> ${summary}</p>`;

      summaryContainer.innerHTML += `<p><strong>Recommendation:</strong> ${recommendation}</p>`;

    });

 

 

 

7 REPLIES 7

DanielCordick
Mega Patron
Mega Patron

what is your question?

@DanielCordick  first time scripting does it make sense ?

May I suggest taking the chucks learn JavaScript on the now platform 

 

https://youtu.be/nK1aPdGyGak?si=oRUQjdiW0wPKji7e

 

If this is also your first time scripting, maybe take some Now learning courses on scripting, maybe service portal fundamentals

 

https://nowlearning.servicenow.com/lxp?id=learning_course_prev&course_id=ae383a8cdb5eff40de3cdb85ca9...

 

There are plenty of resource on nowLearning that would help you tremendously

 

@DanielCordick point noted .