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
Erich.WeihrauchErich.Weihrauch 

Need help debugging some javascript code...

Ok so its not Apex but wasn't sure where else to post this in...

Code:
{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
var c = new sforce.SObject("Case");
c.JIRA = "{!Case.JIRA_Case__c}";
c,JIRA = (c.JIRA).replace(' ','');
var mySplit = c.JIRA.split(",");
for(i = 0; i < mySplit.length; i++)
{
window.open('http://sever:8080/browse/'+mySplit[i]);
}

 
Basically, I have a field in a case that you can enter in JIRA issue #'s into, e.g. SW-001, RMA-001, etc.
Right now, it works such that for multiple entries, you'd enter in SW-001,RMA-001 (no spaces, and seperated only by a comma).
I've been trying to parse it at least one additional way for now, which is to have it such that I can remove white spaces so that I can do SW-001, RMA-001 , but so far I've been unable to do so. 

Can someone help me figure out what I'm doing wrong there?
DevAngelDevAngel
Hi Erich,

So, aside from the compile issue, you need the JS equivalent of replaceAll.  I believe replace only replaces the first occurrence of the search term.

Try a regular expression like

Code:
function replaceAll(source, searchTerm, replacement) {
  var re = new RegExp(searchTerm, "g");
  return source.replace(re, replacement);
}

 Cheers



Erich.WeihrauchErich.Weihrauch
I still gotta be doing something wrong..I tried that, got nowhere, and even went back to something like
Code:
{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
var c = new sforce.SObject("Case");
c.JIRA = "{!Case.JIRA_Case__c}";
var spaceFix = / /g;
var mySplit = c.JIRA.replace(spaceFix,"+");
var mySplit = c.JIRA.split(",");
for(i = 0; i < mySplit.length; i++)
{

window.open('http://server:8080/browse/'+mySplit[i]);
}


 Problem is, it doesn't seem to touch the spaces..above it should have replaced a space with a + but did not.

That and if I don't have the space replace funtion before the joining of , the command opens up a window for each character in the field!

Erich.WeihrauchErich.Weihrauch
Ker-BUMP!
CaptainObviousCaptainObvious

Try this:

Code:
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}

var c="{!Case.JIRA_Case__c}";
var spaceFix=c.replace(/\s/g,'');
var mySplit = spaceFix.split(",");

for(i = 0; i < mySplit.length; i++) {
 window.open('http://server:8080/browse/'+mySplit[i]);
}


 

Erich.WeihrauchErich.Weihrauch
Perfect! Thanks!