cancel
Showing results for 
Search instead for 
Did you mean: 

How to set Query value in WAD w. parameters

Former Member
0 Kudos

Hi

Is it possible to set the queryname in the dataprovider using javascript.

My scenario is that I want to fetch the queryname from the URL with the following javascript

I have the script:

function GetPara( name )

{

name = name.replace(/[\[]/,"
\[").replace(/[\]]/,"
\]");

var regexS = "[
?&]"name"=([^&#]*)";

var regex = new RegExp( regexS );

var results = regex.exec( window.location.href );

if( results == null )

return "";

else

return results[1];

}

And then I want to implement something like the following in the template

//First dataprovider (TAB_A_DP) initialization

<bi:QUERY_VIEW_DATA_PROVIDER name="TAB_A_DP" >

<bi:INITIAL_STATE type="CHOICE" value="QUERY" >

<bi:QUERY value="SCRIPT_FUNCTION">

<bi:SCRIPT_FUNCTION value="GetPara('TAB1')" />

</bi:QUERY>

</bi:INITIAL_STATE>

</bi:QUERY_VIEW_DATA_PROVIDER>

//SEcond dataprovider (TAB_B_DP) initialization

<bi:QUERY_VIEW_DATA_PROVIDER name="TAB_B_DP" >

<bi:INITIAL_STATE type="CHOICE" value="QUERY" >

<bi:QUERY value="SCRIPT_FUNCTION">

<bi:SCRIPT_FUNCTION value="GetPara('TAB2')" />

</bi:QUERY>

</bi:INITIAL_STATE>

</bi:QUERY_VIEW_DATA_PROVIDER>

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

in this way it won't work, but you can use the "script" web item. Then enter you command (SET_DATA_PROVIDER_PARAMETERS) using the wizard into the script item. This results in a javascript funtion you can call as you like.

regards,

Leo

Former Member
0 Kudos

Hi Leo

Thank you for the answer. But what I'm looking for is a dynamic way to change the default query for an dataprovider in a template based on a URL.

Normally I can use the query parameter, but my template contains more than one dataprovider due to the use of tabs. So eg. if I have a url like 'mysite.com?webtemplate=wt&query=query1&tab2=query2' then I want my first dataprovider to use query1 and my second dataprovider to set it query = query2.

/John

Former Member
0 Kudos

within the script web item, real javascript is generated. You can modify it and extend it to apply to multiple dataprovider.

Or, do you want to change the way the web template is called? I'm not sure, I think you can save the the web template with empty dataproviders. This forces the web template to take new DPs. And as well: http://help.sap.com/saphelp_nw04/helpdata/en/76/80a1393e3a6942e10000000a11402f/frameset.htm

hope it helps,

Leo

Former Member
0 Kudos

Hi Leo

Sorry I haven't explained my goal very well.

I want to create a dynamic webtemplate w. two tabs. One tab showing data from one dataprovider and the other tab showing data from another dataprovider.

My problem is that it's easy enough to set the dataprovider to a specific query but as I have several reports which should use this template then instead of coping the template and change the query name I want a generic way to set the queryname (e.g. in the url) so I only have one template and not a template per report pair.

In short I want to set the Initial State dynamic.

<bi:QUERY_VIEW_DATA_PROVIDER name="TAB_A_DP" >

<bi:INITIAL_STATE type="CHOICE" value="QUERY" >

<bi:QUERY value="dynamic" text="dynamic" />

</bi:INITIAL_STATE>

</bi:QUERY_VIEW_DATA_PROVIDER>

When I only have one dp I can leave it empty and set the query by typing ?query=<queryname> but what if I have several dataproviders with different queries?

/John

Edited by: John Dolph on Aug 26, 2009 3:22 PM

Former Member
0 Kudos

the code for the web items is executed on the server. There's no way changing it at runtime. Except you're using the command wizzard.

hmm, you can set some dummy infoprovider containing no data. Then, when the web template is loaded client side, you can use javascrpt (the scipt web item code) to call the command for changing the dataprovider. With some javascript, it should be possible to evaluate your URL. This with you can parse your own custom parameter.

Would this be possible?

Former Member
0 Kudos

Hi Leo

The best solution I have come up with is to make som links which looks like tabs and then using javascript I put in the correct link. This is not optimal as the users have to enter the selection every time they click on a new tab.

Lets just hope that in the future SAP implement a feature on the DP item where you can set a parameter as it apparently is possible to implement (as the have hardcoded the query parameter).

Thank you for all your help

Answers (1)

Answers (1)

Former Member
0 Kudos

wrong message

Edited by: John Dolph on Aug 24, 2009 2:21 PM