none
URL Action with JavaScript and SSAS Parameter

    Question

  • Hi guys,

    i am facing the following problem:
    i have an URL-Action on my report that opens a new window usgin Javascript:void(window.open(....))
    this works fine so far
    when i add Parameters from SSAS, i have the problem that the values in SSAS are usually formated as [<Dim>].[<Hierarchy>].&[<Key>]
    the problem is the '&' because this is also the delimiter used by SSRS to seperate parameters like
    ...report.rdl&Param1=a&Param2=b and so on
    with the SSAS parameter this would look like
    ...report.rdl&Param1=[<Dim>].[<Hierarchy>].&[<Key>]
    which does not work because '&' is interpreted as delimiter betwenn SSRS Parameters and the report does not expect a parameer [<Key>]

    by replacing '&' by '%26' i am able to open the report again
    but window.open() reverts '%26' back to '&' and i cannot open the report anymore

    anyone faced this problem before?
    is it possible to tell the window.open function not to convert '%26' back to '&'?

    greets,
    gerhard
    - www.pmOne.com -
    Monday, May 04, 2009 11:27 AM

Answers

  • Hi Gerhard,

     

    Please use the method “escape” to replace the character “&” with %xx encoding in the URL.

     

    The escape method returns a string value (in Unicode format) that contains the contents of [the argument]. All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding, where xx is equivalent to the hexadecimal number representing the character. For example, a space is returned as "%20."
    Edge Core Javascript Guide: The escape and unescape functions let you encode and decode strings. The escape function returns the hexadecimal encoding of an argument in the ISO Latin character set. The unescape function returns the ASCII string for the specified hexadecimal encoding value

     

    Here is the sample:

    ="javascript:void(window.open('http://localhost/ReportServer?/AdventureWorks Sample Reports/SingelParameterAnalysis&DateFiscalYear=[Date].[Fiscal Year].' + escape('&') + '[2002]'))"

     

    If you have any more questions, please feel free to ask.

     

    Thanks,

    Jin

    Wednesday, May 06, 2009 7:39 AM
    Moderator

All replies

  • no ideas?
    - www.pmOne.com -
    Tuesday, May 05, 2009 9:36 AM
  • Hi Gerhard,

     

    Please use the method “escape” to replace the character “&” with %xx encoding in the URL.

     

    The escape method returns a string value (in Unicode format) that contains the contents of [the argument]. All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding, where xx is equivalent to the hexadecimal number representing the character. For example, a space is returned as "%20."
    Edge Core Javascript Guide: The escape and unescape functions let you encode and decode strings. The escape function returns the hexadecimal encoding of an argument in the ISO Latin character set. The unescape function returns the ASCII string for the specified hexadecimal encoding value

     

    Here is the sample:

    ="javascript:void(window.open('http://localhost/ReportServer?/AdventureWorks Sample Reports/SingelParameterAnalysis&DateFiscalYear=[Date].[Fiscal Year].' + escape('&') + '[2002]'))"

     

    If you have any more questions, please feel free to ask.

     

    Thanks,

    Jin

    Wednesday, May 06, 2009 7:39 AM
    Moderator
  • Hi Jin,

    thanks for your reply
    using escape('&') works just fine!

    greets,
    gerhard
    - www.pmOne.com -
    Wednesday, May 06, 2009 8:21 AM
  • I have a question.  How do you encode the script when the parameters being passed are selected at runtime?

    I've tried:

    ="javascript:void(window.open('"& Globals!ReportServerUrl & "?%2fHeidtmanReports%2fPOSub&rs:Command=Render

    &Division='+escape('"+Parameters!Division.Value+"')+'&Units='+escape('"+Parameters!Units.Value+"')'&CustName="+Fields!Name.Value+

    "','_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=yes,copyhistory=no'))"

    But I get "Error on Page" in the status window.

    The actual script that is sent is:

    Javascrip:void(window.open(‘http://localhost/reportServer?%2fHeidtmanReports%2fPOSub&rs:Command=Render&Division=’escape(‘%5BOrganization%5D.%5BDivision%5D.%5Ball%5D’)+

    ’&Units=’escape(‘Net%20Ton%20Ton%20-%20%5BUnits%5D.%5BFactor%5D.&%5B2.E3%5D’)’&CustName…

     

     

    Thursday, May 07, 2009 1:18 PM
  • Hi,

    this is the code i use:
    ="Javascrip:void(window.open('http://localhost/reportServer?%2fHeidtmanReports%2fPOSub&rs:Command=Render" &
    "&Param1=" & Replace(Parameters!Param1.Value, "&", "' + escape('&') + '") &
    "&Param2=" & Replace(Parameters!Param2.Value, "&", "' + escape('&') + '")

    i replace "&" of the Parameter by "' + escape('&') + '"  
    the other &'s stay untouched

    greets,
    gerhard
    - www.pmOne.com -
    Thursday, May 07, 2009 4:08 PM
  • I've tried the Replace(Parameter!whatever,"&",%26) and some other escape() scenerios. 

    I think it's going to work.  I only have to figure out how to change a filed value for Cutomer Name that comes across as FORD MOTOR COMPANY to [Cust].[Name].&[FORD MOTOR CO]

    • Edited by JohnDMP Thursday, May 07, 2009 5:04 PM
    Thursday, May 07, 2009 4:59 PM
  • Hi,

    could have something to do with the ** you hve in your customername
    maybe you have to escape or URL-Encode them

    by adding the assembly System.web to your report and using 
    "&Param1=" & Replace(System.Web.HttpUtility.UrlEncode(Parameters!Param1.Value), "%26", "' + escape('&') + '") &

    UrlEncode replaces the & by %26 so you now have to replace %26 instead of the old &

    greets,
    gerhard

    - www.pmOne.com -
    Thursday, May 07, 2009 5:07 PM
  • I edited my comment after you saw it.  I was confused.  Two of the parameters I am passing are report parameters in both reports.  The third parameter is a Field in the calling report.  Therefore it is NOT in the MDX format.  It needs to be [Cust].[Name].&[FORD] while it comes across just as FORD.  I'm not sure how to get the field data into MDX format.  It would be easy to write a custom code segment but I'm not sure if that would work inside the javascript call.

    It doesn't work:

    =

    "javascript:void(window.open('"& Globals!ReportServerUrl & "?%2fHeidtmanReports%2fPOSub&rs:Command=Render&Division="+Replace(Parameters!Division.Value,"&","' + escape('&') + '")& "&CustName="+Replace(CustMDX(Fields!Name.Value),"&","' + escape ('&') + '")&"&Units="+Replace(Parameters!Units.Value,"&","' + escape('&') + '")&

    Thursday, May 07, 2009 5:12 PM
  • UrlEncode is a predefined function of System.Web so you do not have to write any code
    also the function is not called within javascript, it is just used to populate the javascript

    to get the connection between MDX-format and your Parameter try something like
    ="[Cust].[Name].&[" & Parameters!Customer.Value & "]"
    of course the resulting MDX has to be correct so you have to ensure that the Parameter Value holds the Key of your MDX-member
    - www.pmOne.com -
    • Proposed as answer by JohnDMP Thursday, May 07, 2009 6:02 PM
    Thursday, May 07, 2009 5:19 PM
  • HA!


    =

    "javascript:void(window.open('"& Globals!ReportServerUrl & "?%2fHeidtmanReports%2fPOSub&rs:Command=Render&Division="+Replace(Parameters!Division.Value,"&","' + escape('&') + '")& "&CustName=[Cust].[Name].' + escape('&') + '" & "["+Fields!Name.Value + "]&Units="+ReplaceParameters!Units.Value,"&","' + escape('&') + '")&"','_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=yes,copyhistory=no,height=500,width=700,left=100,top=300'))"



    THANKS FOR POINTING THE WAY!!!!

    Thursday, May 07, 2009 5:38 PM