You need to sign in to do that
Don't have an account?

S-Control problem - how to debug?
Hi,
I have an S-Control (in Javascript) that is failing and I have no idea why. I am unable to see any trace of the problem in the logs. How can you see what the issue is?
Also, in case someone can help, here is the issue. The following Code works perfectly:
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/8.0/connection.js"></script>
{!INCLUDE($SControl.RecordTypesLookup)}
<script language="JavaScript">
function redirect() {
var DonationRecordType = "012400000009J6q";
parent.frames.location.replace("/006/e?retURL=%2F{!Recurring_Donation__c.Id}&RecordType="+DonationRecordType+ "&accid={!Recurring_Donation__c.OrganizationId__c}&opp3={!Recurring_Donation__c.Contacto__c} Donacion Recurrente - {!Today}&opp9={!Today}&opp11=Concretada&CF00N80000002VMyv={!Recurring_Donation__c.Name}&CF00N40000001tLEN_lkid={!Recurring_Donation__c.ContactoId__c}&CF00N40000001uHhg_lkid={!Recurring_Donation__c.Id}&CF00N40000001uHhg={!Recurring_Donation__c.Name}&CF00N40000001tLEN={!Recurring_Donation__c.Contacto__c}&opp7={!Recurring_Donation__c.Donation_Amount__c}&00N40000001dRhJ=TC")
But, if I add the following it stops working (changes in bold):
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/8.0/connection.js"></script>
{!INCLUDE($SControl.RecordTypesLookup)}
<script language="JavaScript">
function redirect() {
var DonationRecordType = "012400000009J6q";
var TipoPago = "";
if ({!Recurring_Donation__c.RecordTypeId} == "012R0000000CprF") {
TipoPago="TA";
}
else {
TipoPago="TC";
}
parent.frames.location.replace("/006/e?retURL=%2F{!Recurring_Donation__c.Id}&RecordType="+DonationRecordType+ "&accid={!Recurring_Donation__c.OrganizationId__c}&opp3={!Recurring_Donation__c.Contacto__c} Donacion Recurrente - {!Today}&opp9={!Today}&opp11=Concretada&CF00N80000002VMyv={!Recurring_Donation__c.Name}&CF00N40000001tLEN_lkid={!Recurring_Donation__c.ContactoId__c}&CF00N40000001uHhg_lkid={!Recurring_Donation__c.Id}&CF00N40000001uHhg={!Recurring_Donation__c.Name}&CF00N40000001tLEN={!Recurring_Donation__c.Contacto__c}&opp7={!Recurring_Donation__c.Donation_Amount__c}&00N40000001dRhJ="+TipoPago)
On this line:
if ({!Recurring_Donation__c.RecordTypeId} == "012R0000000CprF") {
Try putting double quotes around {!Recurr....}
The substitution mechanism is doing literal substitution, so your IF statement is ending up like:
if(012R0000000CprF == "012R0000000CprF") {
which fails syntactically.
:-) Best, Steve
p.s. If you want to get into it, use Firefox for your browser and download the Firebug extenstion. It has a console window, allows interactive debugging, etc.
Thanks a bunch Steve, that solved it! Also thanks for the Firebug tip, I will definetely use it...
I must say however that it is a bit odd having to put "" for this comparison, hey well! each programming language has it´s own little things, doesn´t it?
One last favor Steve. I am downloading Firebug and will play with it later on. My Javascript is still not working, worst, sometimes it does and sometimes it doesn´t with no apparent change... It is driving me a bit crazy. Can you find the problem below?
<script type="text/javascript" src="/js/functions.js"></script> <script src="/soap/ajax/8.0/connection.js"></script> {!INCLUDE($SControl.RecordTypesLookup)} <script language="JavaScript"> function redirect() { var DonationRecordType = "012400000009J6q"; var TipoPago=""; if ("{!Recurring_Donation__c.RecordTypeId}" == "012R0000000CprF") { TipoPago="TA"; } else { TipoPago = "TC"; } parent.frames.location.replace("/006/e?retURL=%2F{!Recurring_Donation__c.Id}&RecordType="+DonationRecordType+ "&accid={!Recurring_Donation__c.OrganizationId__c}&opp3={!Recurring_Donation__c.Contacto__c} Donacion Recurrente - {!Today}&opp9={!Today}&opp11=Concretada&CF00N80000002VMyv={!Recurring_Donation__c.Name}&CF00N40000001tLEN_lkid={!Recurring_Donation__c.ContactoId__c}&CF00N40000001uHhg_lkid={!Recurring_Donation__c.Id}&CF00N40000001uHhg={!Recurring_Donation__c.Name}&CF00N40000001tLEN={!Recurring_Donation__c.Contacto__c}&opp7={!Recurring_Donation__c.Donation_Amount__c}&00N40000001dRhJ="+TipoPago)
}
redirect();
</script>
Hey Ray, well, it looks fine from a syntax point of view, and if it's working on and off, you have to evaluate what's changing. Odds are that it's the values in the fields that you are substituting.
Remember that you're essentially building a string to redirect your browser to. If you were to take the resulting string and put it in the address bar of your browser, ask yourself if it would work. Are you substituting in characters that can mess up the URL? Do any of the data fields sometimes have an ampersand in them? Question marks, spaces, etc.
Another question is: are all those field ID's correct? I notice that you're substituting in the same values several times into different fields (Name for example). How about the ID's for the RecordTypeId's? (By the way, as long as you're including "RecordTypesLookup", you might as well use it:
var DonationRecordType = recordTypeId("Donation","Opportunity");
Hope this helps... Steve.
Thanks Steve. To be honest the S-Control is part of the (now deprecated, there is a new version) Non Profit SF version. I am just adapting the S-Control to pass additional parameters for the custom fields I´ve created.... I noticed too about RecordTypesLookup not being used. Thanks for your tips,
J
Hi Steve, I was looking at the technical docs I have to see the usage of RecordTypesLookup. But neither the Apex API, the Metadata API nor the Force Cookbook have any reference to it.
Do you know any doc that can be helpful? Thanks,
J
This line:
says "include the code that's stored in the S-Control called RecordTypesLookup into this s-control".
That s-control defines a javascript function which takes the name of the Record Type that you are looking up and the Object Type ("Contact", "Opportunity", etc.) as arguments and returns the ID of the record type.
I don't think it will be documented anywhere.
-Steve.