You need to sign in to do that
Don't have an account?
Miss Amy
Pull in Contact fields using S-Control
I have a custom object tracking professional services engagements based on accounts. I have added a field to select the contact for the engagement from the contacts associated with the account. I would like to add an S-Control to pull in the phone number and email address but the following code is not bringing back anything.
<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/js/dojo/0.4.1/dojo.js"></script>
<script>
dojo.addOnLoad(init);
function init() {
var callback = {
onSuccess : displayResult,
onFailure : displayError
};
sforce.connection.query("SELECT Name, Phone, Email FROM Contact where ID = '{!Contact.Id}', callback);
}
function displayResult(result) {
var it = new sforce.QueryResultIterator(result);
var html = [];
while(it.hasNext()) {
var record = it.next();
html.push("Name = " + record.Name + "<br>");
html.push("Phone = " + record.Phone + "<br>");
html.push("Email = " + record.Email + "<br>");
html.push("<hr>");
html.push("<br>");
}
document.getElementById("output-div").innerHTML = html.join("");
}
function displayError(error) {
document.getElementById("output-div").innerHTML =
"oops something went wrong ... " + error;
}
</script>
</head>
<body>
<div id="output-div"></div>
</body>
</html><html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/js/dojo/0.4.1/dojo.js"></script>
<script>
dojo.addOnLoad(init);
function init() {
var callback = {
onSuccess : displayResult,
onFailure : displayError
};
sforce.connection.query("SELECT Name, Phone, Email FROM Contact where ID = '{!Contact.Id}', callback);
}
function displayResult(result) {
var it = new sforce.QueryResultIterator(result);
var html = [];
while(it.hasNext()) {
var record = it.next();
html.push("Name = " + record.Name + "<br>");
html.push("Phone = " + record.Phone + "<br>");
html.push("Email = " + record.Email + "<br>");
html.push("<hr>");
html.push("<br>");
}
document.getElementById("output-div").innerHTML = html.join("");
}
function displayError(error) {
document.getElementById("output-div").innerHTML =
"oops something went wrong ... " + error;
}
</script>
</head>
<body>
<div id="output-div"></div>
</body>
</html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/js/dojo/0.4.1/dojo.js"></script>
<script>
dojo.addOnLoad(init);
function init() {
var callback = {
onSuccess : displayResult,
onFailure : displayError
};
sforce.connection.query("SELECT Name, Phone, Email FROM Contact where ID = '{!Contact.Id}', callback);
}
function displayResult(result) {
var it = new sforce.QueryResultIterator(result);
var html = [];
while(it.hasNext()) {
var record = it.next();
html.push("Name = " + record.Name + "<br>");
html.push("Phone = " + record.Phone + "<br>");
html.push("Email = " + record.Email + "<br>");
html.push("<hr>");
html.push("<br>");
}
document.getElementById("output-div").innerHTML = html.join("");
}
function displayError(error) {
document.getElementById("output-div").innerHTML =
"oops something went wrong ... " + error;
}
</script>
</head>
<body>
<div id="output-div"></div>
</body>
</html><html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/js/dojo/0.4.1/dojo.js"></script>
<script>
dojo.addOnLoad(init);
function init() {
var callback = {
onSuccess : displayResult,
onFailure : displayError
};
sforce.connection.query("SELECT Name, Phone, Email FROM Contact where ID = '{!Contact.Id}', callback);
}
function displayResult(result) {
var it = new sforce.QueryResultIterator(result);
var html = [];
while(it.hasNext()) {
var record = it.next();
html.push("Name = " + record.Name + "<br>");
html.push("Phone = " + record.Phone + "<br>");
html.push("Email = " + record.Email + "<br>");
html.push("<hr>");
html.push("<br>");
}
document.getElementById("output-div").innerHTML = html.join("");
}
function displayError(error) {
document.getElementById("output-div").innerHTML =
"oops something went wrong ... " + error;
}
</script>
</head>
<body>
<div id="output-div"></div>
</body>
</html>
Do I need to display the contact ID on the page? If so how would i associate it with the contact?
Any help or suggestions are greatly appreciated.
Thanks!
Amy
The only error i see in the code is the unterminated string in the query. You are missing a double quote after the merge field '{!Contact.Id}'
Putting that in, i've tested and it works fine.
Regards
"); html.push("Street = " + record.Street 1 + "
"); html.push("City = " + record.City 1 + "
"); html.push("State/Province = " + record.State/Province 1 + "
"); html.push("Zip/Postal Code = " + record.Zip/Postal Code 1 + "
"); html.push("Country = " + record.Country 1 + "
"); html.push("Phone (1) = " + record.Phone (1) + "
"); html.push("Phone (2) = " + record.Phone (2) + "
"); html.push("
"); html.push("
"); } document.getElementById("output-div").innerHTML = html.join(""); } function displayError(error) { document.getElementById("output-div").innerHTML = "oops something went wrong ... " + error; } </script>
var contactId = "{!Contact.Id}";
var result = sforce.connection.query("Select Name, Phone, Email from Contact where ContactId = '" + contactId + "' limit 10");