cancel
Showing results for 
Search instead for 
Did you mean: 

Personas 2.0 current date + xx days

Former Member
0 Kudos

Hello experts,

I have a "valid from" and a "valid to" field in one of my transactions. Using Personas, I was able to successfully set the current date on the valid from field (set current date MM/dd/yyyy for US format).

Now on the valid to field, I'm trying to get personas to automatically calculate current date + 90 days. For example, valid from = 11/20/2015. Valid to should be 02/13/2016 (current date + 90 days). I tried a few times using the examples from this link, but no luck.

http://stackoverflow.com/questions/3818193/how-to-add-number-of-days-to-todays-date

I also tried searching the scn forums but could not find anything.

Any suggestions?

Thanks,

Srini

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Perhaps you could show us the code that you've tried?

Remember you're going to need to first convert from a string to a Javascript date, then do the addition using the method in the stack overflow article you mentioned, and finally convert back. You'll do all this in a "Calculate in Javascript" action.

Former Member
0 Kudos

Hi Steve,

This is what I have inside my script:

args.date = new Date()

args.daystoadd = 90

args.date1 = args.date.setDate(date.getDate() + args.daystoadd)

paste value date1

I have no idea about javascripting. So I'm not entirely sure about my syntax.

I keep getting a javascript error on the 3rd step.

Srini

Former Member
0 Kudos

This code works for me:

var now = new Date(); 
now.setDate(now.getDate() + 90); 
args.then = now.getDate() + "." +
                  (now.getMonth()+1) + "." +
                   now.getFullYear();

You can then paste "then" into a field using a "Paste Value" action. The last line simply turns the date value in the "now" variable into something in SAP's date format. You may want to change that according to your intended use.

Hope that helps.

Steve.

Former Member
0 Kudos

Hi Steve,

I tried copying your code into my script. But I'm still getting an error. This is what I have done:

I keep getting an error on the second step.... date.setDate(date.getDate() + 90).

Also, on the first step I tried both var date = new Date() and args.date = new Date() to see if that made any difference. Keep getting the same error message.

I have very limited javascript knowledge, so I apologize in advance if I'm doing something stupid!

Srini

Former Member
0 Kudos

You need to put all the JavaScript into one action, not in separate actions.

Former Member
0 Kudos

That worked perfectly! Thank you so much Steve!

Answers (0)