Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to search for records with specific date

devendranarun
Tera Guru

Hello All,

I am looking to search knowledge articles that are going to expire before 14/7/3/1 days from the current valid to date.

I have written my code in Workflow if activity;

answer = ifScript();
function ifScript() {
var a = "valid_toRELATIVEEE@dayofweek@ago@14";
var gr = new GlideRecord('kb_knowledge');
gr.addEncodedQuery(a);
gr.query();
if (gr.next()) {
if (a == 'true') {
gs.log('inside_if');
return 'yes';
}
else{
gs.log('inside_else');
return 'no';
}


The yes transition to send reminder notification and no transition checks for another if activity;


function ifScript() {
var a = "valid_toRELATIVEEE@dayofweek@ago@7";
var gr = new GlideRecord('kb_knowledge');
gr.addEncodedQuery(a);
gr.query();
if (gr.next()) {
if (a == 'true') {
gs.log('inside_if');
return 'yes';
}
else{
gs.log('inside_else');
return 'no';
}

Similarly for 3 and 1 day...

Result : inside_else gets printed.

Thanks,
Arun Devendran

5 REPLIES 5

Yes Florin,

That's correct!

it works fine in Scripts using addEncodedQuery.

Best Regards,
Arun Devendran