Set date to 1st day of next month based on other field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2021 11:24 PM
Hi,
I have 2 date/time fields (say, A & b) and need to set value on 1 field based on other.
So, whatever date/time value user selects manually in field A, then field B should be auto populated with 1st day of next month.
For eg, if user selects value of A as 4th april,2021 23:00:00, then value of B should be 1st May,2021 00:00:00.
1st will be constant for every value of A, only the month will change depending on month selected in A. Time will also remain constant as 00:00:00AM
Can someone help me with this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2021 11:55 PM
Hi
1.) Write onChange client script call script include via GlideAjax() by passing A field as parameter
2.) In Script include get the A field month as
var month = new GlideDateTime(A field parameter);
var getMonthValue = month.getMonth() //you'll get a numeric value
Add +1 to that getMonthValue and use this "addMonths(after incrementing month value)" to add months value and pass that to client script.
Also follow this link
Date/Time scripts
Please mark my answer as helpful, if applicable
Best Regards,
Sai Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 12:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 12:21 AM
can you try this
var date = new GlideDateTime(accountingDate);
var month = date.addMonthsLocalTime(1);
var day = date.getDayOfMonth();
var firstOfMonth = new GlideDateTime(date)
firstOfMonth.addDaysLocalTime( -1 * (day-1));
Please mark my answer as helpful/correct, if applicable
Best Regards,
Sai Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 01:08 AM
var PopulateReversalDate = Class.create();
PopulateReversalDate.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
setDate : function(){
var accountingDate = this.getParameter('sysparm_accounting');
var date = new GlideDateTime(accountingDate);
var getMonth = date.addMonthsLocalTime(1);
var day = date.getDayOfMonthLocalTime();
var firstOfMonth = new GlideDateTime(date);
var reversalDate = firstOfMonth.addDaysLocalTime(-1*(day - 1));
gs.addInfoMessage("reversal date "+reversalDate);
return reversalDate;
},
type: 'PopulateReversalDate'
});
This is my script include, but 'reversal date' is coming as undefined