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
Anil DuttAnil Dutt 

Split Comma seperated string in Javascript

Hi,

 

I have a situation where i m returing comma seperated string from a function and want to split this string in an array.

Here is what i m doing on Button click javascript but its gives me an error "message.Split is not a function"

 

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

var oppId= "{!Opportunity.Id}";

var message= sforce.apex.execute("CreditMemo","CloneOpp",{oppId:oppId });

var result = message.Split(",");
var newOppId ='';

if (result.length > 0)
{
   newOppId= result[1];
}

 

alert(result[0]);

if(result[0]== 'Success')
{
   window.location="https://na14.salesforce.com/"+newOppId;

}

 

Any idea?

Best Answer chosen by Admin (Salesforce Developers) 
Anil DuttAnil Dutt

Ok i got the solution

 

Adding .toString() to

 

var message = sforce.apex.execute("CreditMemo","CloneOpp",{oppId:oppId }).toString();

 

make message  as string and split work fine on it

 

Thanks