Dot walk value showing sysID in client script

chandan15
Tera Contributor

In a record producer, when a KB is selected, article text/Article body is need to be populate . So I write a Onchange client script to populate article body.

Here we need Author name along with article body, but I am it is getting Author sys_ID instead of name

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var cust = g_form.getReference('knowledge_piece', populate);
    function populate(cust) {
        g_form.setValue('knowledge_article', cust.author + "/n" + cust.text);
    }
}

 

If I am using "cust.author.getDisplayValue()" , I am getting error

If I am using "cust.author.toString()", still getting sys_ID

Anyone please help me how can I populate KB article Author name here !

1 ACCEPTED SOLUTION

HI @chandan15 

 

Try this

//Script Include:
var kbKnowledgeDetails = Class.create();
kbKnowledgeDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getKnowledge: function() {
        var responseArray = [];
        var grKK = new GlideRecord('kb_knowledge');
        grKK.get(this.getParameter('sysparm_record'));
        var responseObj = {};
        responseObj.authorName = grKK.author.name.toString();
        responseObj.text = grKK.text.toString();
        return JSON.stringify(responseObj);
    },
    type: 'kbKnowledgeDetails'
});

//OnChange Client script on "knowledge_piece"
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }	
    var gAjax = new GlideAjax('kbKnowledgeDetails');
    gAjax.addParam('sysparm_name', 'getKnowledge');
    gAjax.addParam('sysparm_record', newValue);
    gAjax.getXML(getKnowledge);

    function getKnowledge(response) {
        var ans = response.responseXML.documentElement.getAttribute("answer");
        var result = JSON.parse(ans);
        g_form.setValue('knowledge_article', result.authorName + '\n' + result.text);
    }
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Abhit

View solution in original post

11 REPLIES 11

Weird
Mega Sage

The author is a reference to a user in sys_user table?
Try adding name in your dot walk -> cust.author.name
Does that help?

If not, you could also just swap things around and use a GlideAjax script include instead.

ricker
Tera Guru

Chandan15,

Syntax for getDisplayValue() is incorrect.  Try it like this.

cust.getDisplayValue('author');

 

chandan15
Tera Contributor

Hi Ricker, thanks for responding,

I used sysntax "

g_form.setValue('knowledge_article', cust.getDisplayValue('author') );" , but still I am not getting name, sys ID neither

Abhit
Tera Guru

Hi @chandan15 ,

Update cust.author to cust.author.name in your code.

 

Abhit