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.

have to fetch the articles which is going to retire in one month based on valid to field

priyanka Ganta
Tera Contributor

Articles from Knowledge table

2 REPLIES 2

Sarthak Kashyap
Mega Sage

Hi @priyanka Ganta ,

 

I tried your problem in my PDI and it works for me please check below script 

var now = new GlideDateTime();
var oneMonthAhead = new GlideDateTime();
oneMonthAhead.addMonthsUTC(1);

var targetDate = oneMonthAhead.getLocalDate().toString(); // YYYY-MM-DD
gs.print("targetDate = " + targetDate);

var gr = new GlideRecord('kb_knowledge');
gr.addQuery('valid_to', 'ON', targetDate);
gr.query();
while (gr.next()) {
    gs.print(gr.number + ' - ' + gr.short_description + ' (Valid To: ' + gr.valid_to + ')');
}

SarthakKashyap_0-1764264489285.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

 

soumyadeep10
Giga Guru

Hello @priyanka Ganta ,

Please use the below code to do so:

var today = new GlideDate();
var addOneMonth = new GlideDate(today);
addOneMonth.addMonthsUTC(1); // adding 1 month

var knowledge = new GlideRecord('kb_knowledge');
knowledge.addQuery('valid_to', addOneMonth);
knowledge.query();
while (knowledge.next()) {
	gs.print(knowledge.number + ' will expire in 1 month');
}

If this answer helped you, please accept it as solution and mark it helpful. Thank you.

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.