function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
wt35wt35 

Global Variables in Javascript

Hi Community 

 

I have an apex:commandButton that links to a JS function to open a new window.

The issue is that the link of the window that is referenced in the JS Function contains Global Variables, they do not merge as it is not VF Code. Can anybody suggest a solution?

 

My button:

 

<apex:commandButton value="MyButton" onclick="keyAccountData();return false;"/>

 

 

JS Function:

 

function keyAccountData() {
window.open('https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId={!$Api.Session_ID}&ServerUrl={!$Api.Partner_Server_URL_250}&Id={!Account.Id}&DefaultPDF=1&DS7=3&LG4=1&LG3=2&OFN={!Account.Name}___OnePager_Onboard___{!NOW()}&TemplateId=a17Q0000001IguN&ReportId=00OQ0000000ThTh,00OQ0000000ThTX','Conga','height=175, width=300');
}

 

Or is it better to initialize the link in my controller?

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
ministe_2003ministe_2003

At the moment, merge fields won't merge if the script is in a static resource.  I don't know if there's any way around that (maybe using remoting?) but perhaps someone who's better at JS than me can help you with that.  Having the script on the page will definitely work though, if there's no other solution.

All Answers

ministe_2003ministe_2003

The global variables should merge if you're in a VF page, even though javascript.  Do you find that when you click the button a window opens and the URL shows non-merged literal text, or does the window not open at all?  Try using Internet Explorer's Javsacript debugger to inspect the content of the link before you send the user there.  Or have the button spit out the link in an alert() function so you can see exactly what the link is stored as.  I just copied your link into a VF page of mine and it worked

wt35wt35

Hi Ministe

 

Thanks for the feedback.

 

I forgot to point out that that my function is in a Static Resource and not directly in a <script> tag.

To answer your question, yes a new window does open up but with non-merged literal text.

Also I only tested with Firefox.

 

So I will do the following tests later in the day:

 

 - Try with the function inside the VF Page in a <script> tag

 - Try with different browsers.

 - Try IE's JS Debugger as you suggested

 

 

ministe_2003ministe_2003

At the moment, merge fields won't merge if the script is in a static resource.  I don't know if there's any way around that (maybe using remoting?) but perhaps someone who's better at JS than me can help you with that.  Having the script on the page will definitely work though, if there's no other solution.

This was selected as the best answer
wt35wt35

Yes I'm pretty sure there must be a way or another of including this in a Static Resource.

I am running out of time so I included it directly in the VF page and it does work

Thanks for your inputs