Fill field in SSRS with javascript - javascript

I have an SSRS report with a function that detect url of report (the report shows tvo different value, dependending on url)
I use:
="javascript: var name=document.URL; var n=name.indexOf('hsbportalen.se'); if(n > 0) { void window.open('http://www.google.com',800,800,'_blank')} else { void window.open('http://www.msn.com',800,800,'_blank')}"
But what I want now, is how can I set a value in a textfield (Textbox42) with a JavaScript dependign on url.

What you'll find is that SSRS does not support JavaScript, period. The only functions that you can pass through SSRS are those that your web-browser can interpret outside of a script file. From what I've found, this is a very limited set of commands.
For instance, you can use Window.Open('') and void() and a few others. I've never been able to get an If statement and certainly not a parse() to work through SSRS.
I've had to do this a couple of times and, if you're in the same boat I was, you'll find the easiest way is to do one of the following:
Option 1: Going from one SSRS Report to Another, Pull data from URL
Go to the source of the current URL and reconstruct the URL you are receiving. For instance, you can use the "Go to URL" action to create a custom URL to a Report that will drop the breadcrumbs and use the Report Server rs & rc parameters. Basically, to make this work, whatever variable you want to parse out of the URL would first be created as a parameter of the appropriate type in your target report and then you would pass that value through the URL to that report.
Scenario 2: Coming from an external website, Pull data from URL
I've had to do this too, but it's a bit more involved. What you need is an intermediate webpage. One that Opens and Closes immediately, and all it basically does is redirect you to where you want the user to go. To accomplish this, follow these steps:
First, create a parameter in the report you want to read the URL. The parameter should be of the appropriate type to store the data to be read from the URL (i.e., URL_Data)
Second, create an intermediate webpage that will lie where the URL is pointing. You can construct the page to open with a message like "Loading..." or "Please wait..." (just in case the user sees it).
Third, in the script of the intermediate page, have it parse the data from the URL that you are trying to capture. Then, incorporate that data into a custom URL that points to the desired SSRS report and includes the URL data as the parameter.
See here and here for more information on how to generate custom URLs that can incorporate parameter values.
http://SSRS_Server/reportserver/Pages/ReportViewer.aspx?/directory/Sample_Report&URL_Data=URL_Snippet
Finally, finish off your JavaScript on the intermediate webpage to open the SSRS URL in a new window and close the current page.
Now, you can use the values of that parameter wherever you want.

Related

Load a template page via GET request with data from the previous page?

I want to load a new template page with data inserted via the previous call.
I have a list of items generated and they link to the general item page but without php all is lost.
I was thinking about using a href="page.html#itemid" then finding the item by querying the url.
Is this overthinking it? Any easier ways to do it?
I am assuming that on the current page, you have used AJAX to load all the data you need to display on the new template page, correct?
I can think of multiple ways to do this. It just depends on the nature of your data:
Have a popup instead:
You could have the new template page be a popup (instead of a real, separate page). Grey out the main page's content (via a darker, half transparent overlay) and then have this new popup div display the data you want. This is typically used on sites that want you to sign up for their newsletter, etc.
Pass the data via URL:
If you have very small amounts of data and it isn't sensitive data, you can just pass it through the parameters. Let's say page.html is the new page template you want to populate the data with. Then just have the link on the current page be page.html?itemid=123&param2=Hi or something like that. Then, on page.html, make sure you have JS to read the parameters from the URL and display the data.
Pass the data via cookie:
Otherwise, you might just want to use JS cookies. Especially if you have a medium or larger amount of data. Store the data loaded from AJAX into cookies. If you are expecting the user to open multiple page.html templates at the same time, you might want to use an identifier and pass it to each one, such as page.html?itemid=1 and page.html?itemid=2 etc. Then have that page.html's JS look up the appropriate cookie based on the URL's parameter id.
Do be careful and use best practices if handling sensitive data.

SSRS jump to URL appends report server address to wanted URL

I'm trying to create a link from a report I'm writing to a web page I've also written. The idea being that whoever is viewing the report can find the record they're interested in, then click on that entry and it will take them to the page relating to that record.
I've tried using
javascript:void(window.open('"+Fields!URL.Value.ToString()+"', '_blank'))
URL obviously being the datasource field that contains my URL. The link is clickable and does open a new tab and attempt to load a page. But the page has my report servers domain at the beginning of it (i.e. server/Reports/Pages/MyURL).
Obviously that page doesn't exist so the page doesn't (resource does not exist). Is there a way to stop window.open appending the report server to the beginning of MyURL, or is there another, better, method that I should be using instead?

Acrobat Javascript: passing a UTM parameter from URL into a PDF button

I have a PDF that has a button with field name ctaButton.
ctaButton currently has a url pointing to https://mywebsite.com.
I want to host the PDF on my server at https://mywebsite.com/hosted.pdf.
And when I send someone a link to the PDF, I want to attach a UTM_term parameter ?utm_term=customer1 and then have the PDF read this parameter and update the ctaButton url to https://mywebsite.com/?utm_term=customer1.
I've been messing around with the Javascript actions in Acrobat for a couple of hours trying to make this happen. Any help greatly appreciated.
You can get the full url to the document using...
var myURL = this.url;
"this" in Acrobat JavaScript is the document context.
I did hours of research and came to this conclusion – Javascript in Acrobat is like trying to code in 1985 AND browsers will not execute whatever code you come up with.
So I used this workaround:
When I send the PDF to someone, I send it as a link with a base64
encoded stringified JSON package that contains a bunch of tracking
data but importantly, the name of the file to access as well as utm
parameters specific to the recipient
The link hits a server handler (NodeJS) that extracts the encoded
JSON package, and uses the data in the package to serve up an HTML
redirect page pointing to the right PDF file
Importantly, the HTML page also saves the JSON package to the
browser's localStorage . . . this comes in handy in subsequent
steps
The PDF file opens in browser (it doesn't have to, could be opened on
desktop) and the call to action link has a link to a get request
handler
The get request handler serves up ANOTHER redirect page
This second redirect page accesses the browser's local storage, looks
for the utm parameters I set for that user, and then redirects to the
sale page, with nice utm parameters attached
So to sum up, you don't add the utm parameters to the call to action link in the PDF (because that would make the world too easy to live in) and instead you do all these acrobatics (no pun intended) to attach utm parameters in the link clicks (via JSON strings saved in localStorage) during the process (i.e. when user opens email to extract file via link, and then when user clicks call to action in the PDF).
Any questions or clarifications please let me know in the comments and I will do my best to address.
Caveats
Only works if user uses same browser in all steps (i.e. if Susan opens the email in Safari, saves the PDF, then clicks the call to action in the PDF, and the link opens in Chrome, utm parameters will not be passed).
Assumes browser is modern and has localStorage
UPDATE: I came across another solution. It's a bit more convoluted. Diagram below.
Porky.io is a Javascript extension for Adobe Indesign. So flow is:
send Porky.io the customer data you need (e.g. utm's for links)
Porky.io generates PDF from a template you provide with the customer data you provided
Listen for a new file save from Porky
Do something with the file (e.g. email it to customer)
I believe you need to run an instance of Windows somewhere in the cloud (e.g. on Azure) to run Indesign with the Porky.io. Unless you want to rely on your laptop.
My project's not big enough yet to warrant setting this up . . . but good alternative if I need to make my current solution more robust.

Change the URL using javascript only while not redirecting the webpage?

I am working on a free domain service provider and it appends its own brand name to my URL on the browser address bar. I want to prevent that by re-writing the URL to give the user a better look and feel. How do I do that using only Javascript (no add-on libraries)?
window.history.pushState(null,'title','/something');
First argument is data, you don't need that.
Second one is the new page title.
Third one is the url. However you cannot completely change it, it will still be relative to the domain.

How do I get Google search query string inside my content script?

I'm trying to build a Chrome extension and clearly I'm a n00b.
I want to display some links on the right side of Google's result page, based on the query the user has searched.
But I'm just not able to get hold of the user query string!. I cannot depend on parsing URL since, the URL remains the same even though the user has made a second search. Let me clarify with a use case:
User enters a search query "testing time" via omnibox and clicks on
enter. URL has now become
"https://www.google.co.in/search?q=testing+time"
Now from within the results page, user changes the query to "testing again" and clicks on enter. The URL will remain what it was earlier, "https://www.google.co.in/search?q=testing+time".
How then shall I get hold of the query string?
For the case 2 mentioned by you, you should see #q=testing+again at the end of the URL.
You can get it via
location.hash.split("=").pop(); //you might have to unescape it
OR alternatively you can read the new query from the text box itself. (I would prefer this method)
document.getElementsByName("q")[0].value

Categories