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
AbAb 

Custom button | Query on account | if-else condition | error message

Hello,

I have a checkbox on Account object "CustomCheck__c"

In the quote, i have a custom button
User-added image
window.location.href='/apex/QUOTES__Quote_Get?&id={!Quote.Id}&retURL=//{!Quote.Id}&cancelURL={!Quote.Id}';

I want to execute this URL only when the checkbox on Account is unticked else display an error message 

How can i acheive it ?

thanks for suggestions
Best Answer chosen by Ab
Dayakar.DDayakar.D
Hi Sandrine,
Try this code, it will work.
{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 

var quoteRec = sforce.connection.query("select Account.Id from Quote where Id='" + '{!Quote.Id}' + "'"); 
var records1 = quoteRec.getArray('records'); 

if(records1 !=null) 
{ 
var AccRec = sforce.connection.query("select Name,CustomCheck__c from Account where Id='" + quoteRec.records.Account.Id + "'");
alert('account'+AccRec.records.CustomCheck__c);
if(AccRec.records.CustomCheck__c='false')
{
window.location.href='/apex/QUOTES__Quote_Get?&id={!Quote.Id}&retURL=//{!Quote.Id}&cancelURL={!Quote.Id}';
}
}

BestRegards,
Dayakar.D​

All Answers

LBKLBK
Hi Sandrine,

Try this JS code.
 
{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")}

 if("{!Quote.Account.CustomCheck__c}" == true){
    window.location.href='/apex/QUOTES__Quote_Get?&id={!Quote.Id}&retURL=//{!Quote.Id}&cancelURL={!Quote.Id}';
}
Let me know if this helps.
 
Dayakar.DDayakar.D
Hi Sandrine,
Try this code, it will work.
{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 

var quoteRec = sforce.connection.query("select Account.Id from Quote where Id='" + '{!Quote.Id}' + "'"); 
var records1 = quoteRec.getArray('records'); 

if(records1 !=null) 
{ 
var AccRec = sforce.connection.query("select Name,CustomCheck__c from Account where Id='" + quoteRec.records.Account.Id + "'");
alert('account'+AccRec.records.CustomCheck__c);
if(AccRec.records.CustomCheck__c='false')
{
window.location.href='/apex/QUOTES__Quote_Get?&id={!Quote.Id}&retURL=//{!Quote.Id}&cancelURL={!Quote.Id}';
}
}

BestRegards,
Dayakar.D​
This was selected as the best answer