Skip to main content
buddycafe
Known Participant
May 31, 2016
Question

Field to display today's date (mm/dd/yyyy) +15 days.

  • May 31, 2016
  • 4 replies
  • 973 views

Good morning,

I thought i nailed this one but it's doing something strange. My script is wrong but i'm learning as I go...

I added a script that auto-populates today's date and adds + 15 days to the date. When I Preview the field, it works find. However when I tab over to another field and add a value (doesn't matter what the other fields are), the initial date field keeps adding more days. Example, if the next two fields were simple check boxes (not tied to the date field in any way) and I were to check the boxes back and forth, the date field keeps jumping to a higher date.

var myDate = util.scand("mm/dd/yyyy", this.getField("GLOBAL__POSTING_DATE_15").valueAsString) ;

myDate.setDate(myDate.getDate() + 15);

event.value = util.printd("mm/dd/yyyy", myDate)

Is there a way to keep the date displayed and not get updated unless the user manually changes the date and only then does it add 15 days to that new date?

Thanks,

Edgar Arreguin

This topic has been closed for replies.

4 replies

buddycafe
buddycafeAuthor
Known Participant
May 31, 2016

Thanks everyone. I was able to make it work using George's suggestion. See link..

Add x days to x date

Only difference is that the original date (auto imported by our UI interface) is hidden.

Defaulted the value of 15 to the second field and made it hidden as well.

Inspiring
May 31, 2016

In what field did you add this script?

Is there any script that is updating the "GLOBAL__POSTING_DATE_15"?

Do you have a field with today's date?

If so, I would have places the code in the "on blur" action and use the value of today's date field for the base date for adjustment. That way the "GLOBAL__POSTING_DATE_15" would only be updated as the today's date field is changed.

buddycafe
buddycafeAuthor
Known Participant
May 31, 2016

I have a single field where I inserted the script. Field name titled "GLOBAL__POSTING_DATE_15". From the script, the date auto populates mm/dd/yyy and adds +15 days.

Bare with me as i'm still learning. I'm not familiar with "on blur"action but assuming you meant adding it to the actions tab as opposed to the Calculate tab, I can give that a shot.

-Ed

try67
Community Expert
Community Expert
May 31, 2016

You can't do it like that. You've created a circular calculation. Each time you take the value of the field and add 15 days to it... You need to use some other event to trigger the calculation, or use the current date in your script, instead of the value that's already in the field.

buddycafe
buddycafeAuthor
Known Participant
May 31, 2016

Maybe a hidden field would prevent this?

try67
Community Expert
Community Expert
May 31, 2016

Where did you place this code?

buddycafe
buddycafeAuthor
Known Participant
May 31, 2016

Custom calculation script in the Calculate tab.