GildeRecord not working in widget server script

v-paulp
Tera Contributor

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.

 

 

 

7 REPLIES 7

Kieran Anson
Kilo Patron

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.

amaradiswamy
Kilo Sage

@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?

Hi @amaradiswamy 

Yes reviewtime actually stored the sys_id and I verified it through gs.log

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;
}
}