-
1. Re: Text variable for previous month's output date?
lithodora Oct 14, 2013 2:33 PM (in response to Jay-KeepOnKeepinOn)What is the reporting date? Do you need the date of the last day of the previous month or is the date you need in the report?
-
2. Re: Text variable for previous month's output date?
Jay-KeepOnKeepinOn Oct 14, 2013 4:14 PM (in response to lithodora)Hi, and thank you. I need the full month name and full year. For example, the reports that are going out now need to say "September 2013".
-
3. Re: Text variable for previous month's output date?
lithodora Oct 14, 2013 4:40 PM (in response to Jay-KeepOnKeepinOn)var td = new Date();
var lastMonth = new Date(td.getFullYear(),td.getMonth()-1,td.getDate())
var y = lastMonth.getFullYear();
var m = lastMonth.getMonth();
var month=new Array();
month[0]="Jan.";
month[1]="Feb.";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="Aug.";
month[8]="Sept.";
month[9]="Oct.";
month[10]="Nov.";
month[11]="Dec.";
var m = month[lastMonth.getMonth()];
var reportdate = m + ", " + y;
reportdate;
You will need to expand the abbreviations but the reportdate now contains what you asked for... if you do not need the coma then just remove it from that 2nd to last line.
-
4. Re: Text variable for previous month's output date?
lithodora Oct 14, 2013 4:45 PM (in response to lithodora)Actually that will not work....
It would not give you the correct year.
var x = new Date();
with(x)
{
setDate(1);
setMonth(getMonth()-1);
}
var month=new Array();
month[0]="Jan.";
month[1]="Feb.";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="Aug.";
month[8]="Sept.";
month[9]="Oct.";
month[10]="Nov.";
month[11]="Dec.";
var y = x.getFullYear();
var m = month[x.getMonth()];
var lastmonth = m + " " + y;
lastmonth;
That will do it and give you the previous year if you are in Jan.
-
5. Re: Text variable for previous month's output date?
Jay-KeepOnKeepinOn Oct 14, 2013 5:06 PM (in response to lithodora)Thank you. Do I save this in the scripts folder as a .jsx? Or is there a way to load custom text variables that I'm unaware of?
-
6. Re: Text variable for previous month's output date?
lithodora Oct 14, 2013 8:50 PM (in response to Jay-KeepOnKeepinOn)This will simply give you the text you want. You will need to put that text where you want it to go.
Yes you will need to have it as a .jsx but if you run it currently nothing will happen that you can see. It needs to actually do something with the lastmonth content.... like set the contents of a text frame to it.
-
7. Re: Text variable for previous month's output date?
Jay-KeepOnKeepinOn Oct 15, 2013 11:07 AM (in response to lithodora)Ok, thank you very much! This next step seems to be a bit over my head so I'll do some research. Cheers!
-
8. Re: Text variable for previous month's output date?
lithodora Oct 15, 2013 12:28 PM (in response to Jay-KeepOnKeepinOn)You simply need to set the contents of a text frame with the variable.
There are many ways to do this, but if you put some odd thing in the template like XXXXXXXX then you can use a search/replace.
var x = new Date();
with(x)
{
setDate(1);
setMonth(getMonth()-1);
}
var month=new Array();
month[0]="Jan.";
month[1]="Feb.";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="Aug.";
month[8]="Sept.";
month[9]="Oct.";
month[10]="Nov.";
month[11]="Dec.";
var y = x.getFullYear();
var m = month[x.getMonth()];
var lastmonth = m + " " + y;
var myDocument = app.activeDocument;
//Clear the find/change text preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = false;
//Search the document for the string "XXXXXXXX" and change it to "text".
app.findTextPreferences.findWhat = "XXXXXXXX";
app.changeTextPreferences.changeTo = lastmonth;
myDocument.changeText();
//Clear the find/change text preferences after the search.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
This you would save and run when you have the document open.
Reading the Scripting Guide is a good thing to do regardless of if this works for you this time.
Be sure to mark this as answered it that works for you.
-
9. Re: Text variable for previous month's output date?
Jay-KeepOnKeepinOn Oct 16, 2013 6:41 AM (in response to lithodora)Thank you again!

