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

OlaN
Giga Sage
Giga Sage

Hi,

Two things.
Your if statement will never be true since you are checking:

if (a == 'true') {

And you are setting the variable to:

var a = "valid_toRELATIVEEE@dayofweek@ago@7";

So these will never match...

 

Secondly, there is no query that looks like "RELATIVEEE"

Replace it with "RELATIVEGT" or "RELATIVELT" depending on if you want it to check for "greater then" or "less then".

 

Hello Olan,

Thanks for your reply.

I have changed the approach of this entire requirement.

I have written my logic in my scheduled job itself which will check for articles that are 14/7/3/1 days prior to valid date.

var a = "valid_toRELATIVEEE@dayofweek@ago@7";

And initiated the Workflow which is responsible for Pending Retirement and the Publishes/retires based on approval.

I have used "RELATIVEEE" in my query. This seem to be working fine for me.

Referred from Servicenow docs;

https://docs.servicenow.com/bundle/rome-platform-user-interface/page/use/common-ui-elements/reference/r_OpAvailableFiltersQueries.html

 

Ah great. Have never used that one.
I was checking what alternatives there was from a list query, there it seems not possible to make a "RELATIVEEE" query.

Another tip, if you are thinking of making a scheduled job, I could really recommend that you use Flow designer instead. It has all capabilities of a scheduled job, but will require less coding.

Just a generic comment on the "RELATIVEEE".

It seems the filter operator has been removed in Orlando.

Please see KB0823423

You can still use it in the script and it's actually working.