You need to sign in to do that
Don't have an account?
zach
uncaught exception when performing sforceclient.init...
error:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js :: anonymous :: line 834" data: no]
Basically, I'm trying to return results from a query that I'm running from my local machine. When I comment out the have the sforceClient.init function the script runds but I get back undefined results for the firstname value that I'm trying to alert, so I'm just guessing the init() is what I'm missing. If this is wrong, please let me know. BTW, I've hard-coded a userid in there for now so I can get the report to run for a single user, but later it will be a real variable.
Here's the javascript I'm using:
script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript">
script src="http://sandbox.sforce.com/ajax/sforceExplorer/dhtmlXCommon.js" type="text/javascript">
script src="http://sandbox.sforce.com/ajax/sforceExplorer/dhtmlXTree.js" type="text/javascript">
script type="text/javascript">
//creating global variables
var globalUserId = 'user id';
function setUser(userId){
var userLogin = sforceClient.login('my username','my password');
//alert('userLogin= '+userLogin);
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
window.setTimeout(";", 1000);
if (globalUserId != ''){
globalUserId = userId;
}
loadPage();
}
function loadPage(){
//getting client information
var userSql = sforceClient.query("Select LastName, FirstName, Division, UserRoleId from User Where id = '"+globalUserId+"'");
if(userSql.size>0){
alert("records "+userSql.records[0]);
alert("firstname "+userSql.records[0].firstname);
}
//var roleSql = sforceClient.query("");
}
/script>
Error: uncaught exception: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js :: anonymous :: line 834" data: no]
Basically, I'm trying to return results from a query that I'm running from my local machine. When I comment out the have the sforceClient.init function the script runds but I get back undefined results for the firstname value that I'm trying to alert, so I'm just guessing the init() is what I'm missing. If this is wrong, please let me know. BTW, I've hard-coded a userid in there for now so I can get the report to run for a single user, but later it will be a real variable.
Here's the javascript I'm using:
script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript">
script src="http://sandbox.sforce.com/ajax/sforceExplorer/dhtmlXCommon.js" type="text/javascript">
script src="http://sandbox.sforce.com/ajax/sforceExplorer/dhtmlXTree.js" type="text/javascript">
script type="text/javascript">
//creating global variables
var globalUserId = 'user id';
function setUser(userId){
var userLogin = sforceClient.login('my username','my password');
//alert('userLogin= '+userLogin);
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
window.setTimeout(";", 1000);
if (globalUserId != ''){
globalUserId = userId;
}
loadPage();
}
function loadPage(){
//getting client information
var userSql = sforceClient.query("Select LastName, FirstName, Division, UserRoleId from User Where id = '"+globalUserId+"'");
if(userSql.size>0){
alert("records "+userSql.records[0]);
alert("firstname "+userSql.records[0].firstname);
}
//var roleSql = sforceClient.query("");
}
/script>
Message Edited by zach on 01-20-2006 10:37 AM
Message Edited by zach on 01-20-2006 10:38 AM
Message Edited by zach on 01-20-2006 10:39 AM
For running from the local machine, you should make your script tag
https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true
A full sample is shown below.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true;" type="text/javascript"></script> <script> function initPage() { //Initialize the connection to salesforce.com by setting the sessionid and the //soap endpoint in the init call sforceClient.useCookies = true; sforceClient.setLoginUrl("https://www.salesforce.com/services/Soap/u/7.0"); sforceClient.registerInitCallback(setup); sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true); } function setup() { //Setting small batch size for demo purposes sforceClient.setBatchSize(20); sforceClient.query("Select Id, LastName, FirstName, Email From Contact", processQueryResult); } function processQueryResult(qr) { if (qr.size > 0) { var td = document.createElement("table"); var tb = document.createElement("tbody"); td.appendChild(tb); for (var i=0;i<qr.records.length;i++) { tb.appendChild(makeRow(qr.records[i])); } document.body.appendChild(td); } else { var div = document.createElement("div"); div.appendChild(document.createTextNode("No records found.")); document.body.appendChild(div); } } function makeRow(bean) { var tr = document.createElement("tr"); tr.appendChild(makeCell(bean.get("id"))); tr.appendChild(makeCell(bean.get("FirstName"))); tr.appendChild(makeCell(bean.get("LastName"))); tr.appendChild(makeCell(bean.get("Email"))); return tr; } function makeCell(fieldValue) { var td = document.createElement("TD"); if (fieldValue == null) { td.appendChild(document.createTextNode(" ")); } else { td.appendChild(document.createTextNode(fieldValue)); } return td; } </script> </head> <body onload="initPage()"> </body> </html>
Actually, IE still doesn't work. It's giving me undefined values as before when I alert myQuery.results[0].firstname or .lastname or whatever I query. It doesn't work at all in Firefox though. In both cases a login box pops up automatically after the javascript is finished running. In IE I can log in but in Firefox, I can't put a cursor in the boxes.
If I leave the browser=true; in the linked .js file and comment out the sforceClient.init function, the queries run in both browsers and return the correct values when I alert userSql.records[0], but the individual values still come back as undefined (userSql.records[0].firstname). The code for this case is pasted below
Thanks,
-Zach
script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true;" type="text/javascript">
script src="http://sandbox.sforce.com/ajax/sforceExplorer/dhtmlXCommon.js" type="text/javascript">
script src="http://sandbox.sforce.com/ajax/sforceExplorer/dhtmlXTree.js" type="text/javascript">
script type="text/javascript">
//creating global variables
var globalUserId = 'userid of the person in the report';
function setUser(userId){
var userLogin = sforceClient.login('my username','mypassword');
alert('userLogin= '+userLogin);
//sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true);
//window.setTimeout(";", 10000000000);
if (globalUserId != ''){
globalUserId = userId;
}
loadPage();
}
function loadPage(){
//getting client information
var userSql = sforceClient.query("Select Id, LastName, FirstName, Division, UserRoleId from User Where id = '"+globalUserId+"'");
if(userSql.size>0){
alert("records "+userSql.records[0]);
alert("firstname "+userSql.records[0].firstname);
}
//var roleSql = sforceClient.query("");
}
/script>
body onload="setUser(globalUserId);">
Message Edited by zach on 01-20-2006 12:06 PM
Message Edited by zach on 01-20-2006 12:07 PM
Message Edited by zach on 01-20-2006 12:38 PM
Message Edited by zach on 01-20-2006 12:40 PM
Thanks,
-Zach
You code should read:
script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true;" type="text/javascript">
script src="http://sandbox.sforce.com/ajax/sforceExplorer/dhtmlXCommon.js" type="text/javascript">
script src="http://sandbox.sforce.com/ajax/sforceExplorer/dhtmlXTree.js" type="text/javascript">
script type="text/javascript">
//creating global variables
var globalUserId = 'userid of the person in the report';
function setUser(userId){
sforceClient.setLoginUrl("https://www.salesforce.com/services/Soap/u/7.0");
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", false);
var userLogin = sforceClient.login('my username','mypassword');
alert('userLogin= '+userLogin);
//window.setTimeout(";", 10000000000);
if (globalUserId != ''){
globalUserId = userId;
}
loadPage();
}
function loadPage(){
//getting client information
var userSql = sforceClient.query("Select Id, LastName, FirstName, Division, UserRoleId from User Where id = '"+globalUserId+"'");
if(userSql.size>0){
alert("records "+userSql.records[0]);
alert("firstname "+userSql.records[0].get("firstname"));
}
//var roleSql = sforceClient.query("");
}
script>
body onload="setUser(globalUserId);">