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
mgodseymgodsey 

javascript popup with salesforce dependent picklists

I have a project that includes the requirement for the following process: a user clicks a salesforce button, and under certain conditions, a pop-up window appears. On that window should be two, dependent picklist fields. Once they complete those fields and click "Ok", the values in those fields should be mapped to the corresponding fields in Salesforce. If they click that button again under the same conditions, the values they have already selected should default.

I know this is possible using a custom button which re-directs the user to a Visualforce page (so not quite a pop-up) and uses apex:inputFields. However, does anyone know if this would be possible using a custom button that executes JavaScript on click? I'm just not sure if it would be too much overkill to build the dependent picklists on this pop-up page or if there is an easy way to grab the information from the Salesforce fields.

I'm not really looking for the code here, just general thoughs on if this approach is even possible/worth considering.

Thanks!
Swayam  AroraSwayam Arora
Hi,

I think it is possible using javascript but it will be too much of coding for a custom button.
There is one more solution, on click of the custom button a popup will open and that popup will contain a vf page containing those 2 picklists.
If you are interested in this solution then let me know I can help you with this.

Regards,
Swayam Arora
mgodseymgodsey
Thanks for such a quick response! Just to clarify - is your suggested solution to use a custom button that redirects to a vf page, or is it possible to have a javascript pop-up/dialog box actually contain a vf page? Thanks!
Swayam  AroraSwayam Arora
Yes, it is possible to have a javascript pop-up/dialog box containing a vf page. For this you will have to share with me the Custom Button code, Vf Page code and the URL (including parameters) of the Vf Page
mgodseymgodsey
Thank you for the help! I don't have the custom button yet; I am still in the design decision phase of the project. However, if you know of links to any examples, that would be much appreciated!

The visualforce page will be something simple like this:
https://c.cs30.visual.force.com/apex/MediaPlanRevisionDetails
<apex:page standardController="Quote" showHeader="true" sidebar="true">
	<apex:form>
		<apex:pageBlock>
			<apex:pageBlockSection columns="1">
				<apex:inputField value="{!quote.RevisionReason__c}"/>
				<apex:inputField value="{!quote.RevisionDetail__c}"/>
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>

This is the simple test button I had previously created when I thought I might try and do it all in javascript, but the simple prompt text field won't work for this situation.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 

//identify the record 
var q = new sforce.SObject("Quote"); 
q.id = "{!Quote.Id}"; 

//ask for the revision reason if the version number is greater than one 
if({!Quote.Version__c} >= 1){ 
var revisionReason = prompt("Why are you requesting the revision?"); 
q.Description = revisionReason; 
} 

//save the change 
sforce.connection.update([q]); 

//refresh the page 
window.location.reload();