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
Peter van HeckPeter van Heck 

Override New Button and pass data

Trying to override the "New System" button (on a custom object called Location) I get an error: Invalid Data
with this Custom S-Control:
 
<html>
<head>
<script src="/soap/ajax/8.0/connection.js"></script>
<script>
function pInit() {
 var url = parent.location.href; //URL accessing sControl
 url += "&CF00N80000002ZueH= {!Location__c.Account__c}";
 url += "&nooverride=1"; //
 parent.location.href = url; //pass full URL to page (refresh)
}
</script>
</head>
<body onload="pInit()">
</body>
</html>
 
 
when I change:
 url += "&CF00N80000002ZueH= {!Location__c.Account__c}";
into:
 url += "&CF00N80000002ZueH= Jansen";
it works.
 
Can anyone tell me what might be wrong?
 
Peter
HL-DevHL-Dev
Change:
Code:
url += "&CF00N80000002ZueH= {!Location__c.Account__c}";

to:
Code:
url += "&CF00N80000002ZueH=" + "{!Location__c.Account__c}";

 
When referencing merge fields, make sure you're enclosing them with double/single quotes.
Greg HGreg H

Is the {!Location__c.Account__c} merge field the Account name or some other text value? My guess is that there my be a problem with special characters (spaces, etc) being included in the URL. If this is the case then you can use the SUBSTITUTE() function to replace the special characters when you insert the merge field.
-greg

Peter van HeckPeter van Heck
It is not working:
Code:
<html>
<head>
<script src="/soap/ajax/8.0/connection.js"></script>
<script>
function pInit() {
 var url = parent.location.href;
 url += "&CF00N80000002ZueH=" + "{!Location__c.Account__c}";
// url += "&CF00N80000002ZueH=" + "Jansen";
 url += "&nooverride=1";
 parent.location.href = url;
}
</script>
</head>
<body onload="pInit()">
</body>
</html>

 
 
when I change to:
Code:
// url += "&CF00N80000002ZueH=" + "{!Location__c.Account__c}";
 url += "&CF00N80000002ZueH=" + "Jansen";

 
it works, which actually is exactly the same data as far as I know.
 
Any other suggestions?
Peter van HeckPeter van Heck

{!Location__c.Account__c} is indeed the (Master-Detail) Account Name.

Some Account names have spaces, so I tested this

Code:
<html>
<head>
<script src="/soap/ajax/8.0/connection.js"></script>
<script>
function pInit() {
 var url = parent.location.href;
 url += "&CF00N80000002ZueH=" + "{!SUBSTITUTE(Location__c.Account__c, " ","")}"; url += "&nooverride=1";
 parent.location.href = url;
}
</script>
</head>
<body onload="pInit()">
</body>
</html>


 but I get the same error, while this:

Code:
url += "&CF00N80000002ZueH=" + "Peter van Heck";

works fine.
 



Message Edited by Peter van Heck on 09-24-2008 10:34 AM
Force2b_MikeForce2b_Mike
I had some similar difficulties a couple of weeks ago writing button overrides.

My recommendation is to copy the resulting URL string from the browser address bar for the two code variations and then compare them to see the difference. If I had to make a guess, it could be that  {!Location__c.Account__c} is not being retrieved. If this is for a related list item, you may be able to work around the problem by creating a new button, but not overriding the 'New' button. Using the Page Layout editor, assign this button to the Related List removing the default [New] button. That worked for me.

Mike
Peter van HeckPeter van Heck
Thnx for you reply Michael.,
 
> If I had to make a guess, it could be that  {!Location__c.Account__c}
> is not being retrieved
 
Exactly, I also already posted this question
 
I do not know how to work around this problem by creating a new
button or any other way since I need to pass the data stored in
{!Location__c.Account__c}
 
I already tested various options with text and formula fields but
I can not get it work unfortunately :(
 
Peter
HL-DevHL-Dev
I remember about a year ago, I was having problems accessing certain field values via their merge fields but was able to get them using API calls. If you can access your Account__c field within Location__c via the API (either query or ideally retrieve calls), give that a shot. Also, if you're using FireFox, I'd recommend getting FireBug if you don't already have it, so you can see troubleshoot the errors. 
CaptainObviousCaptainObvious

Try this:

Code:
function pInit() {
 //alert('{!Location__c.Account__c}');
 var url = parent.location.href;
 url += "&CF00N80000002ZueH=" + encodeURIComponent('{!Location__c.Account__c}');
 url += "&nooverride=1";
 parent.location.href = url;
}

If it still doesn't work, remove the comment from the alert to see exactly what {!Location__c.Account__c} is bringing back :D