cancel
Showing results for 
Search instead for 
Did you mean: 

Date range in design Studio

Former Member
0 Kudos

Hi All,

I am having a requirement to have date range in design studio and my data Source is BW query.

Below is the code I am using but I am getting following error.

Value '04/02/2017-05/30/2017' is not valid for variable Invoice Clearing Date or does not exist

Code I am using:

var varange =DATEFIELD_1.getDate();

var varange1 =DATEFIELD_2.getDate();

var external_date1 = Convert.subString(varange, 4,6) +"/" + Convert.subString(varange, 6,8) + "/" + Convert.subString(varange, 0,4);

var external_date2 = Convert.subString(varange1, 4,6) +"/" + Convert.subString(varange1, 6,8) + "/" + Convert.subString(varange1, 0,4);

var range= external_date1 + "-"+external_date2; DS_2.setVariableValueExt("ZVAR_INCD", range);

Please help me if I am missing anything.

Thanks,

Guna

Accepted Solutions (0)

Answers (4)

Answers (4)

Martin-Pankraz
Active Contributor
0 Kudos

Hi Guna,

Mustafa pointed you in the right direction. You can reuse your provided coding using the substring method to create the US date format from the given internal format that the datefield provides. You might want to consider creating a script to deal with other countries. Here are some hints from me:

As long as you are sure your users have the same setting only, you are fine. The european format you could indentify by checking for dots instead of slashes. Unfortunately our british friends can have slashes and also swap month and date. So consider this MM/DD/YYYY vs. DD/MM/YYYY. Now you cannot know what it actually is. To check for sure you would need to put more effort like reading the browser's language setting or creating a web service on ABAP backend to provide the user's assigned language.

You can stay away from such issues by avoiding BEx variables or sticking to the SAP standard prompt like Mustafa suggested.

Kind regards

Martin

former_member184594
Active Contributor
0 Kudos

You can also use it like this

DS_1.setFilter("0CALDAY",{"low":external_date1 ,"high":external_date2 });

Former Member
0 Kudos

Hi Mustafa,

Thank you very much for your response.

I am trying to use the code you have send, I am now seeing any change in Data. I have users from different geographies.

Ex: I am running this from US and my user setting is MM/DD/YYYY.

1. My BW variable is range.

Now Kindly help how this can be achieved. I tried to Capture the data input to a Test input box and it shows as 20170101 - 20170101.

Kindly advise.

Thanks,

Guna

MustafaBensan
Active Contributor
0 Kudos

Hi Guna,

This is the problem with using setVariableValueExt() because it requires the date to be formatted in the user's locale. Is there a reason why you simply don't use the Variable Prompt Dialogue to allow the user to enter the desired date range?

Alternatively, you could just use the setFilter() method with the internal date format.

Regards,

Mustafa.

MustafaBensan
Active Contributor
0 Kudos

Hi Guna,

There are three points you should check:

1) Ensure that the BEx Variable is defined as a range variable;

2) Since you are using setVariableValueExt(), the date format must be in the user's locale. Make sure that you are using the correct date format. Check that the user locale format is in fact MM/DD/YYYY rather than another format;

3) Try placing a space between the dash separating the dates in the range by changing your code to:

var range= external_date1 + " - " + external_date2; 
DS_2.setVariableValueExt("ZVAR_INCD", range);

Regards,

Mustafa.