Copy link to clipboard
Copied
I am running a javascript (inserted below) to create custom text variables to create a 'next month' and 'next issue' variable for a magazine I work on.
For reasons unknown to me, it stops running correctly intermittently and when I open a template with the text variables on it reverts to showing the current month, not month + 1.
If i run the script before each template or document I open it seems to work okay, but this almost makes it pointless to have the script and leaves room for errors to be missed.
If anyone knows what could be going wrong, I'd appreciate any help or advice.
Many thanks,
Tom
Try to return your months like this:
if(month < 11){
return Months[month+1];
}
else{
return Months[0];
}
Best
Sunil
Copy link to clipboard
Copied
Try to use at the end of both of your function:
Copy link to clipboard
Copied
Hi Sunil,
Thanks very much for your reply.
I am trying to run the script in order to put the next month in as the date of creation of the pages is always 1 month before publication, except in our dual month issues for which I have created the "months" 'January-February' and 'October-November'.
Will removing the +1 not just make it show the current month, unless you mean to remove the +1 and then shift all the months back by one?
Many thanks,
Tom
Copy link to clipboard
Copied
Correct. getMonth returns a number from 0 to 11, so '0' corresponds with "January" and a "+1" should return "February". However, to prevent an error in Dcember, you still need to add another "January/Februari" at the end.
Can you verify if the open/save etc. events actually fire when needed? All it needs is a line
alert ('addVariables is run')
inside that function. You also may need to copy the function four times, with a different alert each time, for each of your 4 event handlers. That way you can hopefully pin-point the problem.
Copy link to clipboard
Copied
Thank you very much for yout response!
However, you lost me in the second paragraph. Which open/save events do you mean?
Where do insert the line 'alert ('addVariables is run')'?
And do you mean that in the script I need to follow each bit of script with the line 'alert ('addVariables is run')'?
Apologies for my ignorance - scripting is very new to me.
Many thanks,
Tom
Copy link to clipboard
Copied
Try to return your months like this:
if(month < 11){
return Months[month+1];
}
else{
return Months[0];
}
Best
Sunil
Copy link to clipboard
Copied
@Sunil Yadav I'm trying to get the month 13 month forwards.
I tried the following, but failed and now I stumbled across your answer, so I hope you might have an idéa.
return Months[month+2];
Copy link to clipboard
Copied
Hi @Buster15A9,
To have your range of month/s, first you need to make the mapping array.
Anyway, if you elaborate your query, then i might give a better idea or solution if I have.
Sunil
Copy link to clipboard
Copied
Im using the same script as above. But I just realized that adding 1 month is the same as adding 13.. doh
Copy link to clipboard
Copied
@Buster15A9 , There are total 12 months only in real world. So this mapping array also OP has created upto 12 only. OP also has trouble getting first month after 12th month. I am assuming that you know about Array, so to get first element from an array you need to pass index as zero like wise if you need 12th element from that array you need to pass index 11(that means length-1). So When it comes to 13th element, which is nothing but 1st element, this is the reason I put this codition of returning. Because OP as made total 11 elements only instead of 12 elements.
Please elaborate your concern...!!!
Best
Sunil