Answered by:
Custom Button JavaScript Url does not work

Question
-
I have a custom button to print pdf reports. There is a url for the report that works just fine. I now need to programatically detect a condition and call one or two versions of the report. I have added som javascript to my menuitem with a condition that works. The problem is the url is not opening the report. Can someone tell me what I am doing woring. Here is my menuitem:
<MenuSpacer />
<MenuItem JavaScript="
if(crmForm.all.mhcv1_localstotals01.DataValue > 0)
{alert('call the url');
Url='http://crmtstdb.mhc.trk/Reportserver?%2fMHC_MSCRM%2fSawSummary2&rs:ClearSession=true';}
else
{alert('test');}">
<Titles>
<Title LCID="1033" Text="Custom JavaScript" />
</Titles>
</MenuItem>
I also need to add pass params="1" to the url and am having trouble figuring out the syntax.
thanks much
jodiThursday, August 13, 2009 5:05 PM
Answers
-
The first thing I will recommend is not to use Pass Params. If the report url includes parameters the report is not expecting, an error will occur, which means you would have to create dummy parameters to handle those extra parameters. Since you are running this from the form, you can use crmForm.ObjectId and you only have to have one parameter in your report. Like this:
<MenuSpacer /> <MenuItem JavaScript=" if(crmForm.all.mhcv1_localstotals01.DataValue > 0) {alert('call the url'); Url='http://crmtstdb.mhc.trk/Reportserver?%2fMHC_MSCRM%2fSawSummary2&rs:ClearSession=true&rs:Commmand=Render&rs:Format=PDF&oId=' + crmForm.ObjectId; window.open(Url, '_blank', 'left=20,top=20,width=600,height=200,toolbar=0,status=0,resizable=1');} else {alert('test');}"> <Titles> <Title LCID="1033" Text="Custom JavaScript" /> </Titles> </MenuItem>
In my example, the parameter on the report is called oId. Also, I added the url params so report server will automatically render the report and serve it up as a pdf, to minimize clicking.- Edited by Richard M. Riddle Thursday, August 13, 2009 5:19 PM
- Proposed as answer by Andrii ButenkoMVP, Moderator Thursday, August 13, 2009 5:23 PM
- Marked as answer by Jim Glass Jr Thursday, August 13, 2009 5:40 PM
Thursday, August 13, 2009 5:15 PM
All replies
-
The first thing I will recommend is not to use Pass Params. If the report url includes parameters the report is not expecting, an error will occur, which means you would have to create dummy parameters to handle those extra parameters. Since you are running this from the form, you can use crmForm.ObjectId and you only have to have one parameter in your report. Like this:
<MenuSpacer /> <MenuItem JavaScript=" if(crmForm.all.mhcv1_localstotals01.DataValue > 0) {alert('call the url'); Url='http://crmtstdb.mhc.trk/Reportserver?%2fMHC_MSCRM%2fSawSummary2&rs:ClearSession=true&rs:Commmand=Render&rs:Format=PDF&oId=' + crmForm.ObjectId; window.open(Url, '_blank', 'left=20,top=20,width=600,height=200,toolbar=0,status=0,resizable=1');} else {alert('test');}"> <Titles> <Title LCID="1033" Text="Custom JavaScript" /> </Titles> </MenuItem>
In my example, the parameter on the report is called oId. Also, I added the url params so report server will automatically render the report and serve it up as a pdf, to minimize clicking.- Edited by Richard M. Riddle Thursday, August 13, 2009 5:19 PM
- Proposed as answer by Andrii ButenkoMVP, Moderator Thursday, August 13, 2009 5:23 PM
- Marked as answer by Jim Glass Jr Thursday, August 13, 2009 5:40 PM
Thursday, August 13, 2009 5:15 PM -
Jodi,
If you mean a second blank window opened that did not disappear when you saved the report, usually that's because the report server and the crm server are on different servers and only one is in Trusted Sites. By default, Internet Explorer will not open a site not in trusted sites in the same window as a site in trusted sites.Thursday, August 13, 2009 6:04 PM -
Richard,
Thanks for your quick response. Your answer did the trick. Passing the objectid makes much more sense. Thanks for the suggstions. I am a novice and there is no direction in house. I'm very grateful for this forum.
If anyone is interested the reason I needed two versions of my report is because I do not always want to display the second page. Placing the objects in a rectangle and conditionally hiding it works in reporting services until you render to pdf. So, I made two versions. Not the most efficeint, but it got the job done.
Thanks again for your help.Thursday, August 13, 2009 6:06 PM -
Richard,
For some reason the clear session is not working. Do you have any idea why? Here's my script:
<MenuItem JavaScript="if(crmForm.all.mhcv1_description.DataValue == 'See Attached')
{Url='http://crmtstdb.mhc.trk/Reportserver?%2fMHC_MSCRM%2fSawSummary2&rs:Commmand=Render&rs:Format=PDF&rs:ClearSession=true&id=' + crmForm.ObjectId; }
else
{Url='http://crmtstdb.mhc.trk/Reportserver?%2fMHC_MSCRM%2fSawSummary&rs:Commmand=Render&rs:Format=PDF&rs:ClearSession=true&id=' + crmForm.ObjectId; }window.open(Url,'_blank', 'toolbar=0,status=0,resizable=1'); ">
Thursday, August 27, 2009 3:22 PM -
I have run into this a couple times and been unable to figure out why ClearSession doesn't work sometimes. The only workaround I have found is to add another parameter to the report, I call mine RandomParam, and pass the current date and time.
Url='http://crmtstdb.mhc.trk/Reportserver?%2fMHC_MSCRM%2fSawSummary2&rs:Commmand=Render&rs:Format=PDF&rs:ClearSession=true&id=' + crmForm.ObjectId + '&RandomParam=' + new Date();
Thursday, August 27, 2009 3:35 PM -
Very clever. The time changes, so each report should be unique. I tried and it did not work. Must be something I did. I created the param on the report as a string. Is that the problem?Thursday, August 27, 2009 4:09 PM
-
A string parameter is correct. If you have access to the report server, recycle the reporting apppool and make sure the data is correct after that.
It sounds like you may have some caching turned on in your Reporting Services installation.Thursday, August 27, 2009 4:14 PM