How to add months instead of adding days to the date field

Bala13
Kilo Guru

Hi,

We have a Business Application form and there is a Next assessment date field avaiable on the form.

When the application is certified and date populated on the certified field, then Next assessment date should populate.

Like, if the certified date is on today 08-04-2022, then next assessment date should populate 6 months after date which is 08-10-2022.

Can any one help me how can i populate the next assesment date from now to 6 months after date?

I have tried to add an after bussiness rule with addDays APi, but how can i do it after 6 months from today?

PLease help me with this requirement

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	
	
    var ed = new GlideDateTime(current.certified);
    ed.addDays(60);
	gs.addInfoMessage("Test1"+ed);	
	
var grBusinessApp = new GlideRecord("cmdb_ci_business_app");
grBusinessApp.addQuery("sys_id", current.id);
grBusinessApp.query();
if (grBusinessApp.next()) {
   grBusinessApp.next_assessment_date = ed;
gs.addInfoMessage("Test2"+ed);	
   grBusinessApp.update();
}


})(current, previous);

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

there is function to add months -> addMonthsUTC()

(function executeRule(current, previous /*null when async*/) {

    // Add your code here

    var ed = new GlideDateTime(current.certified);
    
    ed.addMonthsUTC(6);
    
    gs.addInfoMessage("Test1"+ed);    

    var grBusinessApp = new GlideRecord("cmdb_ci_business_app");
    grBusinessApp.addQuery("sys_id", current.id);
    grBusinessApp.query();
    if (grBusinessApp.next()) {
        grBusinessApp.next_assessment_date = ed;
        gs.addInfoMessage("Test2"+ed);    
        grBusinessApp.update();
    }


})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

there is function to add months -> addMonthsUTC()

(function executeRule(current, previous /*null when async*/) {

    // Add your code here

    var ed = new GlideDateTime(current.certified);
    
    ed.addMonthsUTC(6);
    
    gs.addInfoMessage("Test1"+ed);    

    var grBusinessApp = new GlideRecord("cmdb_ci_business_app");
    grBusinessApp.addQuery("sys_id", current.id);
    grBusinessApp.query();
    if (grBusinessApp.next()) {
        grBusinessApp.next_assessment_date = ed;
        gs.addInfoMessage("Test2"+ed);    
        grBusinessApp.update();
    }


})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Bala 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader