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
LosintikfosLosintikfos 

JavaScript Error

I am using a JavaScript to pass BillingStreet field to an appex script and keeps poping up with the error below;

A problem with the OnClick JavaScript for this button or link was encountered:
unterminated string literal.

When i pass in AccountAlias it works.

Do anyone knws whats' happening? do i need to do do some validity checks on the billing field?



pls. Hlp.


Message Edited by Losintikfos on 10-03-2008 03:18 AM
LosintikfosLosintikfos
Guys i forget to say this!

The script works perfect on sandbox - this issues only happends when i deploy to production.


Any Help!


Message Edited by Losintikfos on 10-03-2008 03:01 AM
werewolfwerewolf

Could be that the data you're using has an apostrophe in it or a quote, which JS is interpreting as the end of a string.  So if you have:

var contactName = '{!Contact.Name}';

But the guy's name is Jim O'Malley, then it will turn out as:

var contactName = 'Jim O'Malley';

And Javascript will think that the string is 'Jim O', Malley makes no sense, and another string starts after the Malley - hence the unterminated string.

LosintikfosLosintikfos
Sorry werewolf!

I am doing something like this;

Code:
var streetC = "{!Account.BillingStreet}";

 
The others works, example var cityC = "{!Account.BillingCity}";
works perfect, it is only the Street. I did some research on the web and it says it might be some breaks in the address field fetched but dont know how to handle it.

Any ideas?


Message Edited by Losintikfos on 10-03-2008 08:06 AM
LosintikfosLosintikfos
any ideas experts need your advice!
SteveBowerSteveBower

Instead of using the merge variable directly, put it in a html tag and then get the value from the DOM.  (There are some discussion threads on this if you look for "textarea").  E.G.

<input type="hidden" id="peanuts">{!my_merge_field}</input>

and later:

var my_value = Document.getElementById('peanuts").value;

Hope this helps, Steve.

LosintikfosLosintikfos
Hi SteveBower,

Base on your advice, i am doing something like this;

 <input type="hidden" id="billing">{!Account.BillingStreet}</input>
   var
streetC = Document.getElementById('billing").value;

And still gets the same error!


Any advice pls?


B
LosintikfosLosintikfos
I have just realise i can't use the input element in the onClick event!  - currently doing something like this but still  won't work;

try
{
if (con == true){
var Account = sforce.Xml();

document.getElementById('billing").value={!Account.BillingStreet};
var streetC = document.getElementById('billing").value.replace(/[\r\n]+/g, " ");

var IDC = "{!Account.Id}";
var naC = "{!Account.Name}";
var cityC = "{!Account.BillingCity}";

var action = sforce.apex.execute("APiBilling","createBill", {ID: IDC, na: naC, street: streetC, city: cityC);

alert(action);
}else
{alert("Successfully Cancelled");}
}
catch (ex)
{
alert ("Failed : " + ex);
}

Need your help experts!:smileysad:


Message Edited by Losintikfos on 10-06-2008 02:24 AM
SteveBowerSteveBower
I'm sorry, I didn't see you were doing this as an on-click bit of code.

Here's a dumb question.... if you're trying to pass information into an Apex class, why bother trying to pass specific fields from the Account object?

Why not just pass the Account Id, and let the Apex class do the select and get the fields it needs itself.   This way if you ever need to make changes, you can just change the class and not have to touch the javascript.

However.... in your example, you are missing quotes around BillingStreet merge field.  Aside from that, if you are able to assign it to "document.getElementById("billing").value", then you would also be able to assign it to "var streetC = " in the first place.  After all, they are *both* just javascript variables.

I'm not sure I have an answer for you.  I'd just pass in the ID value.   Steve.

p.s. Are you using debugging tools for your javascript?   Firebug is an excellent Add-on for Firefox.

LosintikfosLosintikfos
SteveBower!

Did follow your advice and it worked perfectly well!


tHANKS FOR A GOOD ADVICE :smileywink: