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
Naomi HarmonNaomi Harmon 

setContentInnerHTML include javascript variable

I have a beautiful button created on my Contact object that shows a popup and uses sforce.connect.query to get an associated Opportunity. Everything is working perfectly, except for me trying to display the Opportunity's name in the popup. How can I access and display my javascript variable "name" from my box.setContentInnerHTML(...) ? Here is my code:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

var records = sforce.connection.query("SELECT Id, Name FROM Opportunity Where Contact__r.Id = '{!Contact.Id}' AND App_Opp_For__c ='Manna' AND IsClosed=false ORDER BY CreatedDate");

var oppRec = records.getArray('records')[0];

 var oppId = oppRec.Id;
 url = `${oppId}`;

 var oppName = oppRec.Name;
 var name = `${oppName}`;

 var box = new SimpleDialog("hersh"+Math.random(), true); 
	parent.box = box; 
	box.setTitle("Manna Application"); 
	box.createDialog(); 
	box.setWidth(350); 
	box.setContentInnerHTML("<p align='center'><img src='https://c.cs21.content.force.com/servlet/servlet.ImageServer?id=015q00000007FVD&oid=00Dq0000000CSTt&lastMod=1521667670000' style='margin:0 5px;'/></p></br><p align='center'>{!Contact.FirstName} already has a Manna Opportunity open.</br></p><p align='center'><br /><button class='btn' onclick='window.parent.box.hide(); window.open(url);'>Go To Opp</button>&nbsp;<button class='btn' onclick='window.parent.box.hide(); window.open(url);'>New Manna App</button></p>"); 
	box.setupDefaultButtons(); 
	box.show();
Best Answer chosen by Naomi Harmon
Alain CabonAlain Cabon
Simple solution (non tested) but there is perhaps a problem when it is used. 

The concatenation sign for string in Javascript is just the sign "+" (or there is a function concat)
var box = new SimpleDialog("hersh"+Math.random(), true); 
	parent.box = box; 
	box.setTitle("Manna Application"); 
	box.createDialog(); 
	box.setWidth(350); 
	box.setContentInnerHTML("<p align='center'><img src='https://c.cs21.content.force.com/servlet/servlet.ImageServer?id=015q00000007FVD&oid=00Dq0000000CSTt&lastMod=1521667670000' style='margin:0 5px;'/></p></br><p align='center'>{!Contact.FirstName} already has a Manna Opportunity open." + oppName  + "</br></p><p align='center'><br /><button class='btn' onclick='window.parent.box.hide(); window.open(url);'>Go To Opp</button>&nbsp;<button class='btn' onclick='window.parent.box.hide(); window.open(url);'>New Manna App</button></p>"); 
	box.setupDefaultButtons(); 
	box.show();

 

All Answers

Alain CabonAlain Cabon
Simple solution (non tested) but there is perhaps a problem when it is used. 

The concatenation sign for string in Javascript is just the sign "+" (or there is a function concat)
var box = new SimpleDialog("hersh"+Math.random(), true); 
	parent.box = box; 
	box.setTitle("Manna Application"); 
	box.createDialog(); 
	box.setWidth(350); 
	box.setContentInnerHTML("<p align='center'><img src='https://c.cs21.content.force.com/servlet/servlet.ImageServer?id=015q00000007FVD&oid=00Dq0000000CSTt&lastMod=1521667670000' style='margin:0 5px;'/></p></br><p align='center'>{!Contact.FirstName} already has a Manna Opportunity open." + oppName  + "</br></p><p align='center'><br /><button class='btn' onclick='window.parent.box.hide(); window.open(url);'>Go To Opp</button>&nbsp;<button class='btn' onclick='window.parent.box.hide(); window.open(url);'>New Manna App</button></p>"); 
	box.setupDefaultButtons(); 
	box.show();

 
This was selected as the best answer
Alain CabonAlain Cabon
Hi, 

Did it work? 
Naomi HarmonNaomi Harmon
Thanks, Alain! Yes, that worked! I was putting my quotes in the wrong place to start, but I copied your exact syntax and it worked.
Alain CabonAlain Cabon
Hello Naomi,

Big thanks for your feedback.

(that is always valuable to confirm a solution when it is difficult to reproduce exactly the case).

Alain