You need to sign in to do that
Don't have an account?

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);
}
This worked great. Thank you!
All Answers
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?
The merge fields come up blank bc I am not pulling from the opportunity- I am pulling from the OpportunityLineItem on the related list.
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');
}
This worked great. Thank you!