mscrm-addons.com - Blog

IMPORTANT INFORMATION

This blog is deprecated since July 2020.The articles below are no longer maintained and might contain outdated information. 
You can find the most acutal and relevenat information in our Knowledge Base at support.mscrm-addons.com

News.mscrm-addons.com Blog

rss

Hello and welcome to our blog! What can we do for you? Are you looking for further technical information or step-by-step instructions to our products? Or would you like to read the latest news on mscrm-addons? Please feel free to browse our blog for detailed information and to share our posts!


CustomPrintInWordActionAccount

The below-described methods are part of the ptm_dcp_custombuttonactions.js-web resource. More information on this resource can be found here. If you are using Dynamics 365, please also have a look at this article here

The comments and the code for one example of this resource are added below.

Basically, this example is already ready to use. At line 52 you will see the method call that contains the template name (Account Reconnect.dot). This is a standard template which is installed during the installation of DocumentsCorePack.
If you want to change it to a different template, you simply have to change the name. The GUID for this template is retrieved with a helper method that is part of the web resource

If you are creating additional functions for other entities, we recommend keeping a similar naming convention like ours. For example, CustomPrintInWordActionLead for leads, because users could get confused and also cause problems with the DocumentsCorePack Client if you use a method that contains a template which cannot be used with this entity. Basically, a specific template can only work for a specific type of entity.

Global variable:

// This variable is for the registry value which holds the selected ID's
// and the selected entity typecode. DON'T change this format of the
// string! Otherwise DocumentsCorePack Client will not work.
var writeToReg;

This is the CustomPrintInWordActionAccount example:

//--------------------------------------------------------------------------//
//
// This is a sample of how a basic method should look. When you click the 
// Print in Word button from the CRM Grid, the three parameters are defined.
// If you click the button from the Entity Form, the parameters will be
// undefined.
//
// selectedIds:     The unique ID's of the selected records in the grid
// typeCode:        The entity type code of the selected entity
// entityName:      The entity logical name
//
// --------------------------------------------------------------------------//
function CustomPrintInWordActionAccount(selectedIds, typeCode, entityName)
{
    try
    {
        // BLOCK WHICH SHOULD NOT BE CHANGED START
        
        // we're starting from grid view
        if (selectedIds != undefined && selectedIds.length > 0)
        {
            try
            {
                // this for-loop builds the registry value when starting from grid                
                for (var i = 0; i < selectedIds.length; i++)
                {
                    var tmp = "?id=" + selectedIds[i] + "&oType=" + typeCode + ";";
                    writeToReg = writeToReg + tmp;
                }
            }
            catch (err)
            {
                showJsError(err.number, err.description);
            }
        }
        // We're starting from the entity record form
        else
        {
            entityName = Xrm.Page.data.entity.getEntityName();

            // This builds the registry value when startnig from the entity form
            var oType = crmFormSubmit.crmFormSubmitObjectType.value;
            writeToReg = "?id=" + Xrm.Page.data.entity.getId() + "&oType=" + oType + ";";
        }
        // BLOCK WHICH SHOULD NOT BE CHANGED END


        // You could optinally retrieve a template id by the template name
        // In this example the Account Reconnect basic template will be retrieved
        // You have to specify a callback method whenn the template id is retrieved
        // In that callback method you'll run the merge
        retrieveTemplateIdByName('Account Reconnect.dot', entityName, CustomPrintInWordActionAccountTemplateRetrievedCallBack);

        // If you don't want to retrieve the template by name, you could directly specify
        // the unique template id. Then you don't have to create a callback method and can
        // run the merge direct in this method.

        // This line initates the DocumentsCorePack Print in Word ActiveX
        // var printInWord = new ActiveXObject('PrintInWordActiveX.PrintInWord');

        // You could set the TemplateId to let DCP open a specific template
        // This property is optional
        // printInWord.TemplateId = UNIQUETEMPLATEID;

        // reset the reg variable
        // var registryValue = writeToReg;
        // writeToReg = '';

        // now you start the Print in Word and DCP generates the document
        // with the optionally specified template
        // printInWord.Print(registryValue);
    } catch (err)
    {
        showJsError(err.number, err.description);
    }
}

Here you can see the corresponding CallBackMethod: (CustomPrintInWordActionAccountTemplateRetrievedCallBack)

// -------------------------------------------------------------------------- //
//
// This is the callback method for CustomPrintInWordActionAccount to retrieve the
// template id. This method is called when the template id was retrieved via REST
//
// -------------------------------------------------------------------------- //
function CustomPrintInWordActionAccountTemplateRetrievedCallBack(result, textStatus, request)
{
    try
    {
        if (result != null && result != undefined && result.length > 0)
        {
            //get the template id from the result
            var templateId = result[0].ptm_mscrmaddons_dcptemplatesId;

            // This line initates the DocumentsCorePack Print in Word ActiveX
            var printInWord = new ActiveXObject('PrintInWordActiveX.PrintInWord');

            // You could set the TemplateId to let DCP open a specific template
            // This property is optional
            printInWord.TemplateId = templateId;

            //reset the reg variable
            var registryValue = writeToReg;
            writeToReg = '';

            // now you start the Print in Word and DCP generates the document
            // with the optionally specified template
            printInWord.Print(registryValue);
        }
    } catch (err)
    {
        showJsError(err.number, err.description);
    }
}

 

That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com.




Comments are closed.