+ Start a Discussion
barfsurferbarfsurfer 

Want to use Opportunity.Pricebook2Id in a formula field

We have a quoting application that lives on the opportunity.  Users enter the app by clicking a new quote button on the quotes related list section.  I wanted to validate that a particular pricebook was being used prior to allowing the user to enter the quoting system.

 

I've done javascript validation buttons in the past, and it works well -- something like this for example:

 

if (({!Opportunity.Ship_To_Count__c == 0}) || ({!Opportunity.No_of_Bill_To_Sites__c == 0 })) { alert('Your Opportunity is missing a Bill-To or Ship-To Site. At least 1 Bill-To and 1 Ship-To site are required to create a Quote. Please select the appropriate Bill-To and Ship-To sites using the "Select Bill-To and Ship-To button on the Opportunity page.');} else { location.replace('/apex/BM_NewQuote?oppId={!Opportunity.Id}&actId={!Opportunity.AccountId}');}

 But if I try to stick Opportunity.Pricebook2Id in there, it errors and says the field doesn't exist.  I know it does, I can see it in the schema.  Why is this field "hidden" from some parts of the app?  Any other ideas?  I'm stuck!

 

Best Answer chosen by Admin (Salesforce Developers) 
barfsurferbarfsurfer

Good tip, but still didn't work.  For whatever reason, that field just doesn't show up in the available list of merge fields when creating a javascript custom button.  I was able to work around this by creating a new text formula field on the opportunity, and the value of that formula field is simply =pricebook2Id.  Once I had that custom field, it showed up in the javascript screen as an available merge field I could work with.

 

Bizarre and klugey, but it got the job done.

All Answers

prathap raoprathap rao

If the JScript works well i would say if the field is not accessible check the field level security in the Security controls under the Administration Setup.

 

Hope this helps.

barfsurferbarfsurfer

Good tip, but still didn't work.  For whatever reason, that field just doesn't show up in the available list of merge fields when creating a javascript custom button.  I was able to work around this by creating a new text formula field on the opportunity, and the value of that formula field is simply =pricebook2Id.  Once I had that custom field, it showed up in the javascript screen as an available merge field I could work with.

 

Bizarre and klugey, but it got the job done.

This was selected as the best answer
spurusho1.3904247420542078E12spurusho1.3904247420542078E12
@prathap rao - You cant set the FLS for standard setup fields.