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
LaurenP6777LaurenP6777 

Javascript Custom List Button

Can someone help me? This button sits on the OpportunitLineItem related list on the Opportunity page.  I would like to add an "if else" that stops the button from firing if the field "Modification__c" on the opportunitylineitem (that is checked of course) = true. I can not figure out how to query for this. Thanks!

 

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

var IdsToClone, cloneLength, IdToClone;

IdsToClone = {!GetRecordIDs($ObjectType.OpportunityLineItem)};

cloneLength = IdsToClone.length;

if(cloneLength == 0) {
alert("You must choose at least one product to clone");
}
else if(cloneLength > 1) {
alert("You can't clone more than one product at a time");
}

else{
IdToClone = IdsToClone[0];
window.open("/apex/cloneamendment?id="+IdToClone);
}

Best Answer chosen by Admin (Salesforce Developers) 
LaurenP6777LaurenP6777

This worked great. Thank you!

All Answers

Jake GmerekJake Gmerek

It the button is on the opportunitylineitem, can't you just use a merge field to get the value of that field and check on that?

LaurenP6777LaurenP6777

The merge fields come up blank bc I am not pulling from the opportunity- I am pulling from the OpportunityLineItem on the related list.

S DigalS Digal

Hello

 

I have added few lines. Check if it works.

 

 

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

var IdsToClone, cloneLength, IdToClone;

IdsToClone = {!GetRecordIDs($ObjectType.OpportunityLineItem)};

cloneLength = IdsToClone.length;

if(cloneLength == 0) {
alert("You must choose at least one product to clone");
}
else if(cloneLength > 1) {
alert("You can't clone more than one product at a time");
}

else{
IdToClone = IdsToClone[0];
var Q = sforce.connection.query("select id, Modification__c from OpportunityLineItem where id = '" + IdToClone+ "'");
var records = Q.getArray('records'); 
if(records[0].Modification__c)
window.open("/apex/cloneamendment?id="+IdToClone);
else alert('Fail'); 
}

LaurenP6777LaurenP6777

This worked great. Thank you!

This was selected as the best answer