Ribbon and UI Customizations


Email Template Selector

On the form ribbon of the Template Record add a flyout to display a list of Email Templates for leads. On click of a button in the flyout, set the Template field to the id of the specified Email Template. The flyout should be enabled only for existing, editable records.


Code:
/************************************************
populateArticles - function to populate a button
on the ribbon with the available disclaimers
Policy is 1
************************************************/
function PopulateArticles1(CommandProperties) {

    var serverUrl = Xrm.Page.context.getClientUrl();
    var requestUrl = serverUrl + "/xrmservices/2011/OrganizationData.svc/cdi_emailtemplateSet?$select=cdi_emailtemplateId,cdi_name&$filter=statecode/Value eq 0";
    
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        async: false,
        url: requestUrl,
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.             
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest) {
            var engines = data.d["results"];

            var theXml = '<Menu Id=\"Columbus.new_templaterecord.ClickDimensionButton\"><MenuSection Id=\"Columbus.new_templaterecord.ClickDimensionButton.Section\" Sequence=\"10\"><Controls Id=\"Columbus.new_templaterecord.ClickDimensionButton.Controls\">';
            var i = 0;
            for (engineKey in engines) {
                theXml += '<Button Id=\"' + engines[engineKey].cdi_emailtemplateId + "||" + engines[engineKey].cdi_name + '\" Command=\"new.new_templaterecord.ClickDimensionEmailTemplate.Command\" Sequence=\"' + ((i + 1) * 10).toString() + '\" LabelText=\"' + engines[engineKey].cdi_name + '\" />';
                i++;
            }
            theXml += '</Controls></MenuSection></Menu>';
            //prompt("the xml", theXml);
            CommandProperties.PopulationXML = theXml;

        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert(XmlHttpRequest.status + "\n" + textStatus + "\n" + errorThrown);
        }
    });
}
/***  end populateArticles    ***/


/************************************************
openKbArticle - function to append a specific
disclaimer to the field
************************************************/
function openKbArticle1(CommandProperties) {
    var controlId = CommandProperties.SourceControlId;
   // alert(controlId);
    Xrm.Utility.openEntityForm("kbarticle", controlId);
}


function MainAlert1(CommandProperties) {
    var controlId = CommandProperties.SourceControlId;
var Tem_Type='100000000';
if(controlId != null)
{
var str_array = controlId.split('||');
for (var i = 0; i < str_array.length; i++) {
            // Trim the excess whitespace.
            str_array[i] = str_array[i].replace(/^\s*/, "").replace(/\s*$/, "");
        }
controlId=str_array[0];
var name=str_array[1];
    Xrm.Page.getAttribute("new_template").setValue(controlId);
Xrm.Page.getAttribute("new_name").setValue(name);
Xrm.Page.getAttribute("new_templatesource").setValue(Tem_Type);
}
else
{
 alert("Please Select the Template!");
 return;
}
}
/***   end openKbArticle   ***/

Comments

Popular posts from this blog

Workflow Activity Input and Output Parameters and Data Types in MS CRM 2013/15/16

Get Workflow Guid in Javascript using OData query

Convert Plugin to Sandbox mode,