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
DTAPADMINDTAPADMIN 

How to see if a returned value contains a word

I have an S-control that updates the status of a case based on the status of a custom Bug object.  What I want to do now is check to see if the status of the Bug that is returned contains the word "Closed" if it does I want to send a message asking the user to Close the associated Case.  Here is my current code:
 
Code:
<html> 
<head> 
<script src="/soap/ajax/9.0/connection.js"></script> 
<script src="/js/dojo/0.4.1/dojo.js"></script> 
<script> 
dojo.addOnLoad(init); 
function init() { 
var callback = { 
onSuccess : displayResult, 
onFailure : displayError 
}; 

var queryResult = sforce.connection.query("SELECT Case__r.Id, Status__c FROM SFDC_Bug__c WHERE Name = '{!SFDC_Bug__c.Name}'"); 

var records = queryResult.getArray('records'); 

var myObj = new sforce.SObject("Case"); 
myObj.Id = records[0].Case__r.Id; 
myObj.Status = records[0].Status__c; 
sforce.connection.update([myObj], callback); 
} 

function displayResult(result) { 
document.getElementById("output-div").innerHTML = "Case successfully updated!"; 

} 

function displayError(error) { 
document.getElementById("output-div").innerHTML = 
"oops something went wrong ... " + error; 
} 
</script> 

</head> 
<body> 
<div id="output-div"></div> 
</body> 
</html>

 
Any help or suggestions would be greatly appreciated.
 
Thanks
Ron HessRon Hess
If i understand, you have the Status__c that you got back from the query, to check that field for a string you would do something like this (not tested)

if ( /Closed/.test ( records[0].Status__c ) ) {
  // do a message

}



I use a cheat-sheet from www.visibone.com which describes regular expressions
DTAPADMINDTAPADMIN
That did the trick!  Thanks so much.  Now my only question is where to put this code so that it doesn't execute the rest of the code once it sees that the status of the Bug contains Closed.