The CreatorCon Call for Content is officially open! Get started here.

ChrisSteinke2
ServiceNow Employee
ServiceNow Employee

Hey folks. We've seen how to build assistive Agents using the Skill Kit, but how do we operationalize them? Its great to have a message popup on screen, but what if you want to update a field, create a record or kick off an Agent every morning at 7am? In this latest video, I take things down a notch for a bit more relaxed take on harvesting value from AI. 

 

In this video I show a number of different Skill Kit use cases:

1) How to output data into a field.

2) How to create a new record. 

3) How to use JSON to return multiple data points and advanced parsing

4) How to embed a Skill into a Flow so you can use it anywhere.

 

 

Scripts: Here you can find the code used in each example

 

To make a 'clean' message popup appear based on the Skill Output, use this code between the try and catch in the UI Action:

 

try {
    var response = sn_one_extend.OneExtendUtil.execute(request) || {};
    var skillResponse = ((response["capabilities"] || {})[capabilityId] || {})["response"];
    var cleanedoutput = JSON.parse(skillResponse.replace('Info Message', '')).model_output.trim();
    gs.addInfoMessage((cleanedoutput));
 } catch(e) {
 
To clean up text to insert into a field, use this code: 
 
try {
    var response = sn_one_extend.OneExtendUtil.execute(request) || {};
    var skillResponse = ((response["capabilities"] || {})[capabilityId] || {})["response"];
    var cleanedoutput = JSON.parse(skillResponse.replace('Info Message', '')).model_output.trim();
    current.test_plan = new Date().toLocaleString() + '\n\n' + ((cleanedoutput)) + '\n\n' + '*** Test Plan generated by NowLLM ***';
    current.update();
} catch(e) {
 
To create a new record, insert fields and create a hyperlink message to the user, use this code: 
 
try {
    var response = sn_one_extend.OneExtendUtil.execute(request) || {};
    var skillResponse = ((response["capabilities"] || {})[capabilityId] || {})["response"];
    // cleaning
    var cleanedoutput = JSON.parse(skillResponse.replace('Info Message', '')).model_output.replace(/\n/g, '').replace(/\\"/g,'"').trim();
    // starting the new record creation
    var newArticle = new GlideRecord('kb_knowledge');
    newArticle.initialize();
    // setting the fields in the new record
    newArticle.short_description = ('Policy QnA: ' + current.short_description);
    newArticle.text = ((cleanedoutput));
    newArticle.kb_knowledge_base = current.kb_knowledge_base;
    newArticle.topic = current.topic;
    newArticle.valid_to = gs.daysAgo(-365);
    // insert the record and get the sys_id
    var articleSysID = newArticle.insert();
    // create a response message and URL
    // get instance URL
    var instanceurl = gs.getProperty('glide.servlet.uri');
    // create the link
    var mylink = instanceurl + 'kb_knowledge.do?sys_id=' + articleSysID;
    // display the link on screen
    gs.addInfoMessage('Your new KB Article of question and answer pairs is now available. <a href="' + mylink + '">Click here</a> to open.');

} catch(e) {
 
To create a Script step in an Action to parse a complex JSON with two elements, use this code:
 
(function execute(inputs, outputs) {
var outerJSON = JSON.parse(inputs.jsonResponse);
var innerJSON = JSON.parse(outerJSON.model_output);
outputs.recommendation = innerJSON.recommendation;
outputs.score = innerJSON.score;
})(inputs, outputs);
 
 
Here is the UI Action code that can be used to extract multiple elements from a JSON:
try {
    //triggers the Skill with capabilities and config identified above
    var response = sn_one_extend.OneExtendUtil.execute(request) || {};
    var skillResponse = ((response["capabilities"] || {})[capabilityId] || {})["response"];
    // cleans the output and parses the outer object, so we can access the JSON array generated in the model response
    var cleanedoutput = JSON.parse(skillResponse.replace('Info Message', ''));
    var myJSON = JSON.parse(cleanedoutput.model_output);
    // sets the fields on the record and saves
    current.u_resolution_quality_score = myJSON.score;
    current.u_resolution_notes_recommendation = myJSON.recommendation;
    current.update();

}
 catch(e) {
 
 
 
Version history
Last update:
‎04-10-2025 04:28 AM
Updated by:
Contributors