Tuesday, February 24, 2015

MS CRM form load Performance Anyalyzer

This is good Microsoft CRM Hidden tool to check how much time is taken by form to load.

All Credit goes to Gareth Tucker 

This tool opens when you click CTRL +SHIFT +Q

Here are details about how to use Form Load Performance analyzer tool



Add Account/Contact GUID in email template

In CRM Email template, you cannot add record id, but sometime we need to send GUID in email or need to send record URL which will contain record ID/ GUID.

To Add GUID in email template,

1. Create one text attribute in Account or contact entity.. say Account GUID.

2. Add this attribute on form, so that we can able to use it in JavaScript.

3. Add following JavaScript code on form load.

function getRecordId() {
            var accountGuid = Xrm.Page.getAttribute('new_accountguid').getValue()

            if (Xrm.Page.ui.getFormType() == 2 && accountGuid == null) {
                var accountId = Xrm.Page.data.entity.getId();
                Xrm.Page.getAttribute('new_accountguid').setValue(accountId);
                Xrm.Page.data.entity.save();
            }
        }



Here I am getting account id and updating in custom attribute. We can do this only if existing record is opened. 

If want to populate this custom Account GUID attribute on save of account record, then need to create custom plugin and register on Post-Save method. Make sure.. this plugin is not going into Loop by adding some condition like if new_accountguid is null then only execute & update account. 

4. Now open or create email template for account and add this custom attribute in email template



5. Now use this email template for Account.. 





Another option will be by updating Template body XML. but for this need to update template XML using SQL query.

CRM stores templates in Template table. 

to get particular template, 

select Body from Template where Title='Account Reconnect'

Email template body is represented in XML and xml is look like



if email template is like



Notice that account name is selected like

      < xsl:when test="account/name>
        < xsl:value-of select="account/name" / >

      < /xsl:when >

If changed this to

      < xsl:when test="account/accountid>
        <xsl:value-of select="account/accountid" / >

      < /xsl:when >

and updated back template body using SQL statement




Now when you use this email template then you will see GUID in email template.




Friday, February 20, 2015

Minimum product quantity required when creating Quote/order/invoice

Some time in order needs to products with certain Quantity, if product added below certain Quantity, then need to stop user from creating quote.

I am doing this functionality using JavaScript.

In this example I am using crmFetchkit.js.  this kit is available on  http://crmtoolkit.codeplex.com

Here are steps

1. Create JavaScript web resource and add following code in JavaScript.. I created Js web resource with name Quote.js
In this script I am using FetchXML to retrieve products from Quote. To generate FetchXML, easiest option is using Advanced find.



2. Add latest jquery library in form library

3. Add CrmFetchkit.js web resource in Form library

4. Add Quote.Js in form library


5. Call CheckPrductQuantity with product name as parameter function onLoad and OnSave event of Form.



6. Save and publish your form. 

7. Now if product added with quantity less than 5, it will show message as below.