You need to sign in to do that
Don't have an account?
Oliver Freeman 9
List Button (OnClick JS)
Hi there,
I'm trying to create a list button (OnClick JavaScript), to tick a checkbox on a record from a related list on a case.
I'm wanting to tick a checkbox on a custom object (Contract Loan) which is related to the Case object, without having to go on the record page itself.
So far, I've written this:
This works for a detail page button on the object page layout, but not a list button, it just doesn't do anything.
Any help greatly appreciated.
Thanks,
Oli
I'm trying to create a list button (OnClick JavaScript), to tick a checkbox on a record from a related list on a case.
I'm wanting to tick a checkbox on a custom object (Contract Loan) which is related to the Case object, without having to go on the record page itself.
So far, I've written this:
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} var newRecords = []; var c = new sforce.SObject('Contract_Loan__c'); c.id ='{!Contract_Loan__c.Id}'; c.MSC_Replacement_Device__c ='True'; newRecords.push(c); var result = sforce.connection.update([c]);
This works for a detail page button on the object page layout, but not a list button, it just doesn't do anything.
Any help greatly appreciated.
Thanks,
Oli
Hi,
You should query for all child (Contract_Loan__c) corresponding to the case and then update that list.
Explanation:
This button works for record detail page bcoz there is only one id.
But in the related list, there may be more than one records.
Thus as per above logic, it is not certain, which id will be fetched.
Solution:
Just add the query before fetching the id
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
var strQuery="Select Id from Contract_Loan__c where case.id";
var newRecords = [];
var c = new sforce.SObject('Contract_Loan__c');
var otherP = sforce.connection.query(strQuery);
var records = otherP.getArray("records");
if (records.length >= 1) {
for(var i=0; i < records.length ; i ++) {
c.id ='{!Contract_Loan__c.Id}';
c.MSC_Replacement_Device__c ='True';
newRecords.push(c);
var result = sforce.connection.update([c]);
}
try this and let me know if any issue comes
otherwise please choose as best answer :)
Thanks
Is there any way that I can just select the record that is ticked in the list?
Could you please attach the screenshot that how to select the records in the related list?
Thanks