Email button with relevant email template..

Need some assistance.

I have created an email button to send a particular document to our customers. I have created an email template to be used whenever this email is sent. When the button is pressed to send the email, I would like for the relevant email template to display automatically without the user having to choose the template as I don't want to have the user select the wrong template and it also speeds up efficiency.

I have tried to make this work with a post in the community called "Create "New email" Buttons, and have each button automatically use the relevant template. However, it is not working for me.

I put this in my ASP page for the button...

var strTESTEmailLeaseButton = CRM.Button("TestEmail Lease","NewEmail.gif",CRM.URL("1500") + "&customTemplateId=1012");

I added this to my container block...

AddButton(strTESTEmailLeaseButton);

I added this to the custom content area of the EmailFilingBox in Communication..

<script>

// Add to EmailFilingBox

window.attachEvent( 'onload', function () {

// Using setTimeout is optional - I ran into problems

// changing the template before the FCKEditor had loaded

setTimeout( "doTemplateRedirect ()", 1000);

});

function doTemplateRedirect () {

var customTemplateIdRegEx = /customTemplateId=([0-9]+)/gi ;

if (customTemplateIdRegEx.test(document.location.href)) {

customTemplateIdRegEx.exec(document.location.href);

var newTemplateId = RegExp.$1;

if ($( "#template" ).val() != newTemplateId) {

$( "#_HIDDENtemplate" ).val(newTemplateId);

$( "#template" ).val(newTemplateId);

$( "#template" ).change();

}

}

}

When I press the button, the default template comes through and not my "relevant" template. This is the URL that I get when I hit my button...

http://sagecrm/CRM/eware.dll/Do?SID=107142790038959&Act=1500&Mode=1&CLk=T&Key0=1&Key1=1276341&Key2=1974054&customTemplateId=1012

Can anyone see what I am doing wrong?

Any assistance would be greatly appreciated. We are using 7.2

Thank you!


  • 0

    Don't know if this will be of use to you, but this is how it seems to work on that screen, and all this is quite new to me, so there may be a better way to handle this.

    Looking at the source for the new email, it seems that it is controlled by:

    document.getElementById("template")

    In my system I have 2 options for a template, they are:

    Name: Standard Email

    ID: 1

    Name: New Email Template

    ID: 11

    If I load the new email screen and look at the value for the template, I get:

    Which you can see in the source code:

    Value="" SELECTED >Click here to select an E-mail templateValue="11">New Email TemplateValue="1">Standard EmailVALUE="">

    In the source code, I can see the following:

    onChange="document.EntryForm.action='/SageCRM/eware.dll/Do?SID=137654903442186&Act=1500&Mode=1&CLk=&FileDir=System+Administrator%5CTEMP%5C12195190';document.EntryForm.submit();

    So in the console on chrome, if I first set:

    document.getElementById("template").value=11

    Then run what is executed on change, I set the template, then load it.

    To automate this, I added the following on the EmailFilingBox:

    function SetTemp()
    {

    var TempId = $('#template').val();
    if(TempId != 11)
    {
    document.getElementById("template").value=11;
    $( "#template" ).change();
    }

    }

    crm.ready(function()
    {
    SetTemp();

    });

    This then loads the template with ID 11 when I load that screen.

    My thinking is, if you add to your button a custom param, then you can check the value of that param when the screen loads, then if it equals a specific value, you can run the correct function to load the correct email template.

    Something like:

    CRM.Button("TestEmail Lease","NewEmail.gif",CRM.URL("1500") + "&WkRl=Y");

    Then in your code:

    function SetTemp()
    {

    var Donald = crm.getArg("WkRl,crm.url());
    if(Donald == Y)
    {
    document.getElementById("template").value=11;
    $( "#template" ).change();
    }

    }

    crm.ready(function()
    {
    SetTemp();

    });

    You just add a different value for WkRl for each button, so you can write a function for to set the right template, then call the right function based on the value for WkRl in the URL.

  • 0

    Thanks Toby! This does look like it will help me a lot. I follow what you are doing here so I will give it a go and let you know.

    Thank you so much!

  • 0

    Toby...

    I went to take a look through the javascript console and this is what I am seeing. I am pretty sure I am in the right place...I am using Chrome. I went to the new email screen and hit F12. I clicked on the Console tab. This is what I see..

    I wonder if there is something wrong with our FCKeditor file. I don't think I should be seeing this error. I am going to contact technical support and see if I can get my console to look like yours.

    Thanks!

  • 0

    Michele

    In Sage CRM 7.2 and Sage CRM 7.3 the client side javascript you want to apply to a screen does not need to be placed in the custom content - you can actually add it to an external library file. These are the files you can place in the js/custom folder. The script can look at the arguments in the url to make sure that it only works in the context you want.

    See: community.sagecrm.com/.../sage-crm-7-2-script-libraries-reusing-client-side-code-between-screens.aspx

  • 0

    Toby...

    Even though my JavaScript Console is not working quite right, I was able to get this working....partially.

    If I put this in the custom content of the Email Filing Box, it works perfectly... (my template id is 1012). However, I unfortunately cannot leave it there because there are other areas of CRM where the emails are used and I won't always want that template...

    function SetTemp()

    {

    var TempId = $('#template').val();

    if(TempId != 1012)

    {

    document.getElementById("template").value=1012;

    $( "#template" ).change();

    }

    }

    crm.ready(function()

    {

    SetTemp();

    });

    I tried your recommendation of using a custom param. However, I cannot get it to work. I must not be understanding how to add that custom param. Can you see what I am doing wrong? Any assistance is greatly appreciated. (I must admit I did a little happy dance when the above code gave me what I needed.)

    This is my button...

    var strTESTEmailLeaseButton = CRM.Button("TestEmail Lease","NewEmail.gif",CRM.URL("1500") + "&Lease=Y");

    I am thinking that my custom param is + "&Lease=Y"

    This is what I added to the custom content of the Email Filing Box...

    function SetTemp()

    {

    var Donald = crm.getArg("Lease",crm.url());

    if(Donald == Y)

    {

    document.getElementById("template").value=1012;

    $( "#template" ).change();

    }

    }

    crm.ready(function()

    {

    SetTemp();

    });

    This is what my URL looks like after I hit my button...

    sagecrm/.../Do

    Thank you for any assistance you can provide!!

  • 0

    Hi,

    I think your issue is that you are not containing Y in "", which is my fault I guess as it isn't in mine.

    Here is how I checked it:

    1. Go to a company screen, then add Lease=Y to the url, reload it:

    2. Open the console in chrome, and load the following function into it:

    function HR3938()
    {
    var RIPDYO = crm.getArg("Lease");
    if(RIPDYO == "Y")
    {
    alert("It's there.");
    }
    else
    {
    alert("It's not.")
    }
    }

    3. Once loaded into the console, call it:

    4. You then get an alert based on if it can match the value or not:

    If you try and call the function with the lines:

    ...var RIPDYO = crm.getArg("Lease");

    if(RIPDYO == Y)...

    In the console you get the error of:

    Which, in retrospect, is an obvious syntax error. Live and learn.

  • 0

    Michele

    I am in awe of your determination to learn and you are asking some very pointed good questions.

    To understand how external JavaScript files can automatically work without being called, have a look at the drop in code contained in this example file

    community.sagecrm.com/.../27456.aspx

    You can add lots of files to make it easier to understand. Just please not the automatically running files, not only must they have the same structure but they should also be named carefully to make sure they load after the core Sage CRM clientside api library loads.

    But thinking about the custom content. Yes - you can put the JavaScript in any custom content box on the screen.

  • 0

    Michele

    " I am again doing a happy dance!! :-) "

  • 0

    I just think it is important you keep calling your variables Donald.

  • 0

    Thank you Jeff...

    I think I read this article before in regards to another screen I was working on (not this email screen). I do understand that I could have put the code in a js page. However, when I tried to do this previously, I did not get it to work. I had some other functions in the MyFunctions.js page already and I think they might have been processing. However, I thought I would need to "call" the function for it to have been doing anything. Anyway, I tried it with a page that had a lot of JavaScript functions on it. I will go back and try it on a smaller scale and see if I can get it to work as I would rather have the code in one place than scattered around on different screen blocks. I am trying to document all the customizations so that other admins know where to find things in the system and one place would be much easier! :-)

    Also, just so I understand, on the client side javascript and the custom context box, I could put the code in the custom content box of any block on the screen, right? The email filing box may be the only block available (accessible) on this screen. However, if I was working with a different screen. Right now, I cannot think of a good example...but if I had multiple blocks on a screen and I wanted to add some custom content to the screen...I could pick any block if my code was not specific to THAT block...right?

    What I am trying to say is, there was nothing "special" about the Emailing Filing Box in regards to this code. It was just available so we used it. Am I understanding that correctly?

    Hope I am making sense...thank you for your patience and assistance! It is greatly appreciated.

  • 0

    Toby...

    Thank you!! That was it. Changed this if(Donald == Y) to this if(Donald == "Y") and now it works beautifully!!

    Glad to know that I was at least understanding the concept and it was only syntax. Thank you so much for also explaining how you tested it. It goes a long way in helping understand the system.

    Prior to Sage CRM, I never used javascript...just SQL and VB. Therefore, I am still learning the language. Hopefully sometime in the future, I will be able to recognize the missing syntax. In the meantime, I am extremely grateful for your willingness to help me out.

    I am again doing a happy dance!! :-) I still have more to go on getting this screen operating most efficiently for our users...but you have helped me start to see the light at the end of the tunnel. Thank you..thank you..thank you!!

  • 0

    Thanks Jeff...

    I too am in awe of what we are able to have the system do for us. As I have said before, I love that we can customize the system to meet our requirements. Therefore, I am determined to learn what can be done and help implement it.

    I want our users to be excited about using the system because it is going to make their work easier. Therefore, I want to be able to do as much as we can with the system to accomplish that.

    Plus, I have both a blessing and a curse in that I have a need to know how things work! :-) If you understand how something works, it is easier to figure out how to make something work in conjunction with it. Therefore, if my boss asks me...can we do this or this, I can provide a confident answer.

    Thank you for helping me understand the system and not telling me...you don't need to know. Also, thank you for being will to answer my questions without getting frustrated with me! :-)

  • 0

    Ha! It really did happen .. I have witnesses!! Plus it was "Happy"...but not particularly good! :-)

    I kinda love it when I plug in some code and it works!!! Even better when I understand what I plugged in and why. :-)

    It is not unheard of to hear some cheers coming from my office!!

    Once I get this particular screen fully operating the way I want....I might be doing cartwheels down the hallway!!

  • 0

    I thought it was funny that you did that.

    I originally used Toby instead of Donald when I put the code in my system...but I changed it when I posted it back to the forum to show what I did.

    Tee Hee...

    Thanks again...You Rock!