Need help on date fuction

JPSS
Tera Contributor

A task needs to be created on 7 th jan ,April,July,oct (Each Quarter).

 

How can i find the next trigger date  compared to today

 

 

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi @JPSS create a schedule job which runs daily and in condition field place this script

var gdt = new GlideDate(); //creates new date object
var m = gdt.getMonth();  //extracts the month
var d = gdt.getDayOfMonth();  //extracts the day
if((m == "4" || m == "7" || m == "10") & (d == "7")){
    answer = true;
}
HarishKM_0-1709879988839.png

 

Regards
Harish

View solution in original post

5 REPLIES 5

Trupti94
Tera Guru

You can create scheduled Job that will run on daily basis,  in scripting part you would need to write code for date validation , if date matches to your criteria then create task

Harish KM
Kilo Patron
Kilo Patron

Hi @JPSS create a schedule job which runs daily and in condition field place this script

var gdt = new GlideDate(); //creates new date object
var m = gdt.getMonth();  //extracts the month
var d = gdt.getDayOfMonth();  //extracts the day
if((m == "4" || m == "7" || m == "10") & (d == "7")){
    answer = true;
}
HarishKM_0-1709879988839.png

 

Regards
Harish

JPSS
Tera Contributor

Hi,

 

I need to capture the next trigger date in a variable. based on that variable the sytem has to create the task

Vishal Birajdar
Giga Sage

Hello @JPSS 

 

Assuming you are using scheduled job , you can try below approach:

 

1.Create a scheduled job which will run monthly on 7th and it will check if month is Jan,April,July and Oct

Use condition to achieve this...

 

VishalBirajdar_1-1709880063180.png

 

(function() {
    // 1=Jan,4=April,7=July,10=oct
    var gdt = new GlideDateTime();
    var getMonth = gdt.getMonth();  //get current month
    if (getMonth == 1 || getMonth == 4 || getMonth == 7 || getMonth == 10) {
        return true;
    }

})();

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates