You need to sign in to do that
Don't have an account?
rock_chalk
Pass SOQL Variable in URL
Hello,
I'm trying to do something that seems like it should be fairly simple, but I'm not figuring it out.
I'm trying to do something that seems like it should be fairly simple, but I'm not figuring it out.
I'm passing variables in a URL on a page open to pre-populate fields. One of the fields I need to populate is Account, but the account isn't available from the page passing the variables.
The account is related to the object through it's parent object, so I need to look that up and pass it in the variable.
This is the SOQL that I think I need to use:
var result = sforce.connection.retrieve("Select Account_Link__c from DFDT_Project__c WHERE Id = {!DFDT_Task__c.Project_Link__c}");
And this is the URL in button that is opening the new page:
https://na5.salesforce.com/a0K/e?00N70000001rz59=Project
&CF00N70000001wnKD={!DFDT_Task__c.Name}
&CF00N70000001wC7M={!DFDT_Task__c.Project_Link__c}
&CF00N70000001wnKD={!DFDT_Task__c.Name}
&CF00N70000001wC7M={!DFDT_Task__c.Project_Link__c}
&CF00N70000001rE54 = result
I'm just not sure how to put this together so when I click the button to open the page the variable from the query is passed in the URL.
Any help would be greatly appreciated.
Let me know if this works,
Thanks so much for your help! That worked great. I did end up needing to pass account name, instead of the account id, so here is a slight variation on your code that made that work (I'm sure there is a much more elegant way to do this, but it gets the job done):
<html>
<head>
<title>Pass SOQL Variable in URL</title>
<script src="/soap/ajax/12.0/connection.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
<!--
function pInit() {
var url = "/a0K/e?00N70000001rz59=Project"; //start your URL variable
url += "&CF00N70000001wnKD={!DFDT_Task__c.Name}"; //append DFDT_Task__c.Name
url += "&CF00N70000001wC7M={!DFDT_Task__c.Project_Link__c}"; //append DFDT_Task__c.Project_Link__c
var sqlID = sforce.connection.query("SELECT Account_Link__c FROM DFDT_Project__c WHERE Name ='{!DFDT_Task__c.Project_Link__c}'");//soql query statement
if (sqlID.getBoolean("done") && sqlID.size!=0) { //if done and at least one result
var accID = sqlID.getArray("records"); //get an array of records
}
var account = accID[0].Account_Link__c; //isolate just account id
var sql = sforce.connection.query("Select Name from Account where Id ='" + account + "'"); //soql query statement
if (sql.getBoolean("done") && sql.size!=0) { //if done and at least one result
var records = sql.getArray("records"); //get an array of records
url += "&CF00N70000001rE54="+records[0].Name; //append Project Name
}
parent.location.href = url; //pass full URL to page (refresh)
}
//-->
</script>
</head>
<body onload="pInit()">
<div align="right">Error: Account Undefined for Project</div>
</body>
</html>
</html>
Thanks again for your help!
* Your first if statement checks if any projects were returned, but you still try to retrieve accID[0].Account_Link__c even if nothing was returned
* You're also setting parent.location.href even if no values were returned
* I don't think you need to use sql.getBoolean("done") - this is used for queryMore situations
I'm glad you managed to figure things out!