Need daily run schedule Job script to update the variable value based on start date and end date

vinnus
Tera Contributor

based on user date selection survey needs to trigger 

 

if user selected start date is today then value2 needs to update 'Yes'

if the user selects end date is yesterday the valu2 needs to update 'NO'

 

please find variables details in screenshot

vinnus_0-1714387891724.png

 

  

2 ACCEPTED SOLUTIONS

Community Alums
Not applicable

Hi @vinnus ,

You can use below script for your problem

 

 

 

var currentDate = new GlideDateTime();
var yesterdaydate = new GlideDateTime();
yesterdaydate.addDays(-1);
var gr = new GlideRecord('x_jj_dfit_dfit_system_variables'); // You can use any table as per your requirment
gr.addQuery('sys_id', '87b1682a0a0a2c3e75af785bd9073d70'); // You can give any query as per your requirment
gr.quer();
if(gr.next()){
	if(gr.start_date == currentDate){ // Please give backend name of start date 
		gr.value_two = 'Yes'; // Set the value of value_two to true
	}if(gr.endDate == yesterdaydate){
              gr.value_two = 'No'; // Set the value of value_two to NO
         }else{
              gs.print('Wait ');
         }
}

 

 

 

SarthakKashya2_0-1714388971467.png

 

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

 

Thanks and Regards 

Sarthak

 

View solution in original post

Community Alums
Not applicable

Hi @vinnus ,

I did small mistake I wrote wrong speeling of gr.query() please correct that and it will work

 

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

 

Thanks and Regards 

Sarthak

View solution in original post

4 REPLIES 4

vinnus
Tera Contributor

Table: x_jj_dfit_dfit_system_variables

Community Alums
Not applicable

Hi @vinnus ,

You can use below script for your problem

 

 

 

var currentDate = new GlideDateTime();
var yesterdaydate = new GlideDateTime();
yesterdaydate.addDays(-1);
var gr = new GlideRecord('x_jj_dfit_dfit_system_variables'); // You can use any table as per your requirment
gr.addQuery('sys_id', '87b1682a0a0a2c3e75af785bd9073d70'); // You can give any query as per your requirment
gr.quer();
if(gr.next()){
	if(gr.start_date == currentDate){ // Please give backend name of start date 
		gr.value_two = 'Yes'; // Set the value of value_two to true
	}if(gr.endDate == yesterdaydate){
              gr.value_two = 'No'; // Set the value of value_two to NO
         }else{
              gs.print('Wait ');
         }
}

 

 

 

SarthakKashya2_0-1714388971467.png

 

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

 

Thanks and Regards 

Sarthak

 

Not working

Community Alums
Not applicable

Hi @vinnus ,

I did small mistake I wrote wrong speeling of gr.query() please correct that and it will work

 

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

 

Thanks and Regards 

Sarthak