How to pass parameters from Workspace UI Action to g_modal UI page and update a table from it?

JK18
Tera Contributor

Hello Everyone,

 

I`m struggling to recreate/enrich functionality from Service Operations Workspace Agent Assist:
ServiceNow provides 'Attach' action to attach knowledge article to incident`s additional comments. The action (screenshot 1)  which can be found in cxs_ui_action_config table. It`s not editable, and cannot be copied via Insert and Stay. 


The requested functionality is to make the action ask whether to add link to knowledge article to additional comments or worknotes depending on its relevancy to end user. 


For this purpose I created an UI Page to pop-up via UI Action button. The Workspace Client Script of the UI Action goes as follows: 

 

 

function onClick(g_form) {
var recordID = g_form.getUniqueValue();
g_modal.showFrame({  
        url: '/ui_page.do?sys_id=d19a307fc31ed2107925f6edd4013140&sysparm_rec='+ recordID,
        title: 'Attach Knowledge Article',
        size: 'lg',
        height: 250
    });
}

 

 

 


And it pops the UI Page up nicely. (screenshot 2) 

The html code of my UI Page:

 

 

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

    <g:evaluate>
    var choices = new GlideRecord('kb_knowledge');
choices.addQuery('active', true);
choices.query();
choices;
</g:evaluate>

<head>
    <title> Select Knowledge Article </title> <style>
    .container {
        margin: 20 px;
    }
    .dropdown {
        margin - bottom: 20 px;
    }
    .buttons {
        margin - top: 20 px;
    } </style>
    </head>
    <body>
    <div class = "container" >
    <h1> Select Knowledge Article </h1>
    <div class = "dropdown" >
    <label for = "knowledge_article" style = "margin-right:20px;"> Knowledge Article: </label>
    <select id = "kb_article">
    <option value = "" selected = "selected"> --Knowledge Article-- </option>
<j:while test = "${choices.next()}">
    <option value = "${choices.sys_id}"> ${choices.short_description} </option>
    </j:while>
    </select>
    </div>
   
    <div class = "buttons" style="margin-top:30px">
    <button id = "to_comments" class = "btn btn-default" onclick = "addToComments()" style = "margin-right:10px;"> Add to comments </button>                  
<button id = "to_work_notes" class = "btn btn-primary" onclick = "addToWorknotes()"> Add to work notes </button>
</div>
</div>
<div>
    </body>
    </j:jelly>

 

This displays a list of currently active knowledge articles and presents two buttons to pick my choice.

Client Script of UI Page is:

 

function addToComments() {
    var ga = new GlideAjax('KnowledgeArticleAjax');
    ga.addParam('sysparm_name', 'addJournalEntry');
    ga.addParam('par_name', 'incident');
    ga.addParam('par_element', 'comments');
    ga.addParam('par_elementid', 'd30ec3f2c35112107925f6edd4013118');
    ga.addParam('par_value', 'SI ADDED');

}

function addToWorknotes() {
    var ga = new GlideAjax('KnowledgeArticleAjax');
    ga.addParam('sysparm_name', 'addJournalEntry');
    ga.addParam('par_name', 'incident');
    ga.addParam('par_element', 'comments');
    ga.addParam('par_elementid', 'd30ec3f2c35112107925f6edd4013118');
    ga.addParam('par_value', 'SI ADDED');
}

 

 

The idea is to run a Script Include (for now with hardcoded values, to check, whether this can be triggered at all, but it doesn`t seem to)


Script Include created:
Name: KnowledgeArticleAjax

Script: 

 

 

 

var KnowledgeArticleAjax = Class.create();
KnowledgeArticleAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    addJournalEntry: function() {
        console.log('SI RUN');
        var pn = this.getParameter('par_name');
        var pe = this.getParameter('par_element');
        var pei = this.getParameter('par_elementid');
        var pv = this.getParameter('par_value');
        var journalGr = new GlideRecord('sys_journal_field');
        journalGr.initialize();
        journalGr.element = pe;
        journalGr.element_id = pei;
        journalGr.name = pn;
        journalGr.value = pv;
        journalGr.insert();
    }
});

 

 

My issues: 
1. I can`t pass record id to UI page 
2. I can`t create a record in 'sys_journal_field' table once I click buttons on UI Page.
 
Do you have any ideas what I am doing wrong here script-wise or approach-wise?
Thank you in advance for any guidance as there is so little knowledge available on the subject.
0 REPLIES 0