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

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

chandan15
Tera Contributor

Hi Abhit, I have already tried this, still not getting any value

Hi @chandan15  -

 

Create a "script include" and pass the value from there to the client script. with this, you should be able to achieve it.

 

Abhit 

chandan15
Tera Contributor

Thanks Abhit, It is working in record producer, but in portal getting error, even after UI type is "All"

Client script:

 

    var kbNumber = g_form.getReference('knowledge_piece');
    var dept = kbNumber.author.toString();
    var ga = new GlideAjax('UserInfoData');
    ga.addParam('sysparm_name', 'In');
    ga.addParam('sysparm_query', dept);
    ga.getXML(response);

    function response(response) {
        var res = response.responseXML.documentElement.getAttribute("answer");
        var answer = JSON.parse(res);
        g_form.setValue("knowledge_article", answer.name);
		
	}

 

 

Hi @chandan15  - Can you share the code here

chandan15
Tera Contributor

Script include:

var UserInfoData = Class.create();
UserInfoData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
In:function(){
var dept = this.getParameter('sysparm_query');
var gr = new GlideRecord ('sys_user');
gr.addQuery('sys_id' , dept);
gr.query();
if(gr.next()){
	var obj ={};
	obj.value = gr.getValue('phone');
	obj.cost = gr.getValue('cost_center');
	obj.name = gr.getValue('name');	

	var data =    JSON.stringify(obj);
	return data;
}
	

},

    type: 'UserInfoData'
});