Copy link to clipboard
Copied
I would like to have my fiscal year and budget year fields auto-populate based on the date the document is opened. My fiscal year runs from July through June.
Therefore...
If I open the document between July 1, 2018 and June 30, 2019 = FY 18-19 = BY 19
If I open the document between July 1, 2019 and June 30, 2020 = FY 19-20 = BY 20
etc.
I would like for the fiscal years and budget years scripts not be "hard wired", i.e. that the script be able to live on without having to adapt it.
My feeble attempt thus far for budget year:
Created document level scripts that return today's date as two hidden fields: mm and yyyy
I am trying to create a calculation in the budget year field that if the mm field falls between 07 and 12, then returns yyyy+1 field. If mm falls between 01 and 06, it returns yyyy.
I know there must be a much better way but this is my current idea.
Your help is greatly appreciated!
Copy link to clipboard
Copied
Your way is fine, and probably the only way possible. If it's not working please post your code.
There's no need to write the values to fields, though. You can keep it saved in a variable in your code and just write out the final result to the Fiscal Year field.
Copy link to clipboard
Copied
In case it can help someone else, here is the script I added to the calculation script of the field I wanted populated. Let me know if there is an easier way of doing this:
// Get the value of the month and year
var v1 = util.printd("mm",new Date())
var v2 = util.printd("yyyy",new Date())
var v3 = Number(util.printd("yyyy",new Date()))+1
//Set this field's value based on values above
if(v1<=06){
event.value = v2;
}else{
event.value = v3
}