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
AmphitriteAmphitrite 

conditional onclick javascript button - query syntax help

I need this javascript onclick button to populate fields conditionally. I'm pretty sure I need to query for just the results that need to be update. But am getting malformed query error when I try to run the button.

 

Any help wtih syntax of query would be much appreciated.

 

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
pagRef = window.location.href;
var records = {!GETRECORDIDS($ObjectType.Case)};
var qry="SELECT id,XLS06__c,ReturntoViewURL__c,InEditUser__c,InEditUserId__c,UserLock__c, UserControl__c,IsWriteable__c FROM Case where Id IN records AND IsWriteable__c=TRUE";

var qr = sforce.connection.query(qry);
var records = qr.getArray(records);


var newRecords = [];
if (records[0] == null)
{
alert("Please select at least one row")
}
else
{
for (var n in records) {
var c = new sforce.SObject("Case");
c.id = records[n];
c.XLS06__c =1;
c.ReturntoViewURL__c=pagRef;
c.InEditUserId__c="{!$User.Id}";
newRecords.push(c);
}
result = sforce.connection.update(newRecords);
window.location = pagRef;
}}

Best Answer chosen by Admin (Salesforce Developers) 
AmphitriteAmphitrite

All Answers

AdrianCCAdrianCC

Hi,

 

Check this similar thread: link

 

My guess is that the IN operator doesn't get the ids the way he wants it. The way you have it 'records' is inside that string and it's not replaced with the actual value of the var.

Use console.log() statements to debug and see what values are in the records and qry variables.

 

Happy Monday,

Adrian

AmphitriteAmphitrite
This was selected as the best answer