- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 09:58 AM - edited 01-02-2023 09:59 AM
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 !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 05:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 10:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 12:40 PM
Chandan15,
Syntax for getDisplayValue() is incorrect. Try it like this.
cust.getDisplayValue('author');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 10:53 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 11:27 PM