GildeRecord not working in widget server script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2024 04:37 AM
Hi
All we have one requirement by clicking a button need to change the kb_knlowledge author from the portal.
And I have add below script but it is not working.
client Script
c.Review = function(des){
alert(des);
c.data.action1="get_value";
c.data.reviewtime1=des;
c.server.update();
}
Server script
if(input && input.action1=="get_value"){
console.log("input" + input.reviewtime1);
data.reviewtime=input.reviewtime1;
console.log(data.reviewtime);
var grupdate = new GlideRecord('kb_knowledge');
grupdate.addQuery('sys_id',data.reviewtime);
grupdate.query();
if(grupdate.next()){
/*var actualreviewdate = grupdate.u_review_date;
var gdt = new GlideDateTime(actualreviewdate);
gdt.addMonths(12);
grupdate.u_review_date=gdt;*/
console.log('test');
grupdate.author='9413981c1b445154f75a0e55cc4bcb39';
grupdate.update();
//data.time=knowledgeRecord.u_review_date;
}
}
Code is executing till console.log(data.reviewtime); line .
The glideRecord part not executing I check it from console.log.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2024 05:04 AM
You won't be able to use console.log in a server script, you should replace it with either gs.info or $sp.log to have the log information returned to the browser session.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2024 06:10 AM
@v-paulp , I guess the culprit is the below line
grupdate.addQuery('sys_id',data.reviewtime);
I guess you need to query with sysid of KB article instead of reviewtime. Are you storing the sys_id of KB article in data object?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2024 06:34 AM - edited ‎05-23-2024 06:37 AM
Yes reviewtime actually stored the sys_id and I verified it through gs.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2024 06:58 AM
got it.
try with below
if(input && input.action1=="get_value"){
data.reviewtime=input.reviewtime1;
var grupdate = new GlideRecord('kb_knowledge');
grupdate.addQuery('sys_id',String(data.reviewtime));
grupdate.query();
if(grupdate.next()){
/*var actualreviewdate = grupdate.u_review_date;
var gdt = new GlideDateTime(actualreviewdate);
gdt.addMonths(12);
grupdate.u_review_date=gdt;*/
grupdate.author='9413981c1b445154f75a0e55cc4bcb39';
grupdate.update();
//data.time=knowledgeRecord.u_review_date;
}
}