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
SlanganSlangan 

Custom Mail Merge Button

Hello -

 

I am a newbie here, and haven't been able to find an answer to this question on any of the forums. If someone has already solved this problem in another post and I have missed it, I would be forever greatful if you could please direct me to it.

 

We want to create custom button at the top of the opportunity object which will check to see if the user has obtained the required approvals for the opportunity (pricing, etc.) before they are allowed to create and e-mail the required merged documents. Ideally I would love to automate both processes into one (have the mailmerge execute and then automatically generate and send an e-mail with the newly created merged docs w/o any further input from the sales rep).

 

Because I am still really green at this, I am just trying to get a basic button working. I want it to take the user to the mailmerge page when they click it (assuming the right approvals have been obtained). I keep getting an  Insufficient Privileges error. I am the admin so I am unclear as to why I wouldn't have priviledges into any aspect of our org? The code I am using is below - any help/advice would be really REALLY appreciated.

 

 {!REQUIRESCRIPT ("/soap/ajax/10.0/connection.js")}
var newURL = "{!URLFOR( $Action.Activity.MailMerge, Opportunity.Id)}";

if (
{!ISPICKVAL(Opportunity.Order_Status__c,"Payment Received - SOA" )}
)
{
window.parent.location.replace(newURL);
}
else
{
alert("You have either already sent the ERF form or you do not have sufficient approvals to perform this action");
}

 

Thanks a million to anyone who can assist!


 

Best Answer chosen by Admin (Salesforce Developers) 
SlanganSlangan

I solved the issue myself. By replacing the URLFOR function with a straight url address pointing to the MailMerge item(I don't need to create an address to the MailMerge item as it never changes) and then putting an Opportunity.Id merge field at the end I was able to get to the right page and load the right opportunity as a default. Here is the code for anyone else suffering the same issue -

 

{!REQUIRESCRIPT ("/soap/ajax/10.0/connection.js")}
var newURL = "https://[put.your.default.salesforce.org.url.here]/mail/mmchoose.jsp?id={!Opportunity.Id}";

if (
{!OR(ISPICKVAL(Opportunity.Order_Status__c,"SOA Approved (Mgmt)"),ISPICKVAL(Opportunity.Order_Status__c,"SOA Approved (Mgmt & Finance)"),ISPICKVAL(Opportunity.Order_Status__c,"Down Pmt. Received - SOA"))}
)
{
window.parent.location.replace(newURL);

}
else
{
alert("You do not have sufficient approvals to perform this action");

All Answers

CaffeineCaffeine

Slangan,

Difficult to tell with the information given, but one thing you might check is the Field Level Security on the field Opportunity.Order_Status__c

 

 

SlanganSlangan

Thanks for your reply!

 

If you need more information, just tell me what you need to know, I would be more than happy to give you whatever information you need to help me with this.

 

I tried breaking out the parts to see what item was causing the issue and it is coming from the mail merge item. For some reason it says I have Insufficient Priviledges to do a merge (yet when I go through account or if I activate the mail merge button in the associated list, I am allowed to perform a merge???).

 

I found another post where a user said URLFOR gave them the same issue and they had to switch to a link button to solve the issue rather than using Onclick JavaScript. There MUST be a way to do this with Onclick JavaScript though? I need the javascript to change the Order Status field....

 

Thanks again for your help.

SlanganSlangan

I solved the issue myself. By replacing the URLFOR function with a straight url address pointing to the MailMerge item(I don't need to create an address to the MailMerge item as it never changes) and then putting an Opportunity.Id merge field at the end I was able to get to the right page and load the right opportunity as a default. Here is the code for anyone else suffering the same issue -

 

{!REQUIRESCRIPT ("/soap/ajax/10.0/connection.js")}
var newURL = "https://[put.your.default.salesforce.org.url.here]/mail/mmchoose.jsp?id={!Opportunity.Id}";

if (
{!OR(ISPICKVAL(Opportunity.Order_Status__c,"SOA Approved (Mgmt)"),ISPICKVAL(Opportunity.Order_Status__c,"SOA Approved (Mgmt & Finance)"),ISPICKVAL(Opportunity.Order_Status__c,"Down Pmt. Received - SOA"))}
)
{
window.parent.location.replace(newURL);

}
else
{
alert("You do not have sufficient approvals to perform this action");

This was selected as the best answer