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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Could be a nice project!

 

Though like @DanielCordick , what is your question? Is something not working? Do you need help with some part? Did you achieve something working already? And where on the portal are you going to place this, what is your idea exactly?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

@Mark Roethof  i plan to place it on as a a widget on the service portal not sure whether it will work as it is generated using chatgpt

So without any scripting knowledge you are asking chatgpt to create a script for you to use and you don't know what it does and even if it works at all? Wouldn't it be better to start on some easier tasks learning how to script? Maybe create scripts yourself and have chatgpt validate it, or optimize it? 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark