Friday, August 14, 2015

'navBarData' is undefined error – CRM 2015 / CRM 2013 / CRM 2011


'navBarData' is undefined error – CRM 2015 / CRM 2013 / CRM 2011
To fix this issue Export entity and update form defination "shownavigationbar" from false to true.
 shownavigationbar="true"

 

------
 
 

Tuesday, August 4, 2015

Remove Click-To-Call Hyperlink / Remove hyperlink of phone number and email address field in CRM 2013/ CRM 2015

Remove Click-To-Call Hyperlink / Remove hyperlink of phone number and email address field in CRM 2013/ CRM 2015
 
By editing form customization you can remove hyperlinks for phone fields and email fields.

 
Export Contact/ Lead/ Account entity. In customization xml locate form definition, locate field you want to remove hyperlink.
 
 
Export Contact/ Lead/ Account entity. In customization xml locate form definition, locate field you want to remove hyperlink.                                                                                                                                                                  
Then Change classid of field with calssid of any varchar/ text fie
 
ld on form. (in above sa_preferredphone is text field. I updated emailaddress1 classid with classid of sa_preferredphone.)
Import and then publish will remove hyperlink of email address1
Note: This will remove hyperlink on forms as you are modifying form definition, it will enforce CRM validations like email and phone number format.
 
 
If you want to remove validations too then you will have to update format of that attribute in customizations. Changing format from email/ phone to text will remove all validations and hyperlinks on that field.
 

Wednesday, July 29, 2015

Set CRM IFrame Url Dynamically to aspx page / Post data to CRM IFrame aspx page / Get Response from aspx page in CRM IFrame – CRM 2015 / CRM 2013/ 2011


Set CRM IFrame Url Dynamically to aspx page / Post data to CRM IFrame aspx page / Get Response from aspx page in CRM IFrame – CRM 2015 / CRM 2013/ 2011

 

CRM Js

// In following example on page load am binding iframe url dynamically and calling aspx page. On save, posting data to aspx page to perform some operation. On success am saving crm from data.

var dbWaiting;
 function onLoad() {
    dbWaiting = true;

    // Set IFrame URL dynamically to aspx page / service.
    var databaseRecordIDField = Xrm.Page.getAttribute('sa_databaserecordid');
    var o = document.getElementById('IFRAME_TemplateBody');

    if (o != null) {
        o.src = 'https://server.com/emailclient/template?id=' + databaseRecordIDField.getValue();
    }
    if (o != null) {
        IFrame.setSrc(o.src);
    }
    else {
        var IFrame = Xrm.Page.ui.controls.get("IFRAME_TemplateBody");
        IFrame.setSrc('https://server.com/emailclient/template?id=' + databaseRecordIDField.getValue());
    }

    // Add event listener to get response back from aspx page / service
    if (window.addEventListner) {
        window.parent.addEventListener("message", receiveMessage, false);
        window.addEventListener("message", receiveMessage, false);

    }
    else if (window.attachEvent) {
        window.parent.attachEvent("onmessage", receiveMessage);
        window.attachEvent("onmessage", receiveMessage);
    }
}

 

function onSave(ExecutionObj) {
    if (dbWaiting == true) {
        ExecutionObj.getEventArgs().preventDefault();
        var databaseRecordIDField = Xrm.Page.getAttribute('sa_databaserecordid');
        var o = document.getElementById('IFRAME_TemplateBody');

        // Data/ Json object to pass to aspx page/ service
        var pass_data = {
            'name': Xrm.Page.getAttribute('sa_name').getValue(),
            'id': Xrm.Page.getAttribute('sa_databaserecordid').getValue(),
            'action': 'saveRequestedFromCRM',
        };

         // Post data to aspx page/ service, you will get response back in receiveMessage
        if (o != null) {
            o.contentWindow.postMessage(JSON.stringify(pass_data), 'https://server.com/emailclient/template?id=' + databaseRecordIDField.getValue());
        }
        else {
            Xrm.Page.ui.controls.get("IFRAME_TemplateBody").getObject().contentWindow.postMessage(JSON.stringify(pass_data), 'https://server.com/emailclient/template?id=' + databaseRecordIDField.getValue());
        }
    }
}

 

function receiveMessage(event) {
    dbWaiting = false;
    if (event.data === 'error') {
        alert('An error occurred, could not save.  Please make sure the {{Body}} tag is included. ');
    }
    else {
        // You can read response object in to event.data
        Xrm.Page.data.entity.save();
    }
}

Disable fields on CRM Form - CRM 2015/ 2013/ 2011

function DisableForm() {
    Xrm.Page.ui.controls.forEach(
     function (control, index) {
         if (control.getControlType() != "subgrid" && control.getControlType() != "iframe" && control.getControlType() != "webresource")
             control.setDisabled(true);
     });
}

Refresh or Reload CRM IFRAME / Pass data to CRM IFRAME from CRM form – CRM 2015 / CRM 2013


Refresh or Reload CRM IFRAME / Pass data to CRM IFRAME from CRM form – CRM 2015 / CRM 2013

 
// For Posting / Passing data to IFrame, you can call following line on CRM form event. Following line will send/ post data to iframe and you can access data in receiveMessage event on html page in iframe.
 
Xrm.Page.ui.controls.get('WebResource_Dropdown').getObject().contentWindow.postMessage('refresh/data', "*")

 
Html Web Resource
<html>
<head>
    <title></title>
    <script type="text/javascript" src="sa_jQuery"></script>
    <script type="text/javascript" src="sa_JSON"></script>
    <script type="text/javascript" src="sa_XrmServiceToolkit.js"></script>
    <script src="ClientGlobalContext.js.aspx"></script>
    <script type="text/javascript">
        function receiveMessage(e) {
            // You can fetch data that you have posed in "e"
            //Refresh/ Reload data here

            LoadData();
        }

        window.attachEvent("onmessage", receiveMessage);

        function LoadData() {

        }

    </script>
    <meta charset="utf-8">
    <meta>
 </head>

<body onload="LoadData()">
</body>
</html>

Tuesday, July 28, 2015

Resize IFRAME to adjust – CRM 2015 / CRM 2013


In CRM 2015 / CRM 2013 you can resize ifram setting style by following way

Friday, July 24, 2015

Override/ Persist the Modified Date / Actual End date in entities in CRM 2015/ 2013/ 2011.


We can override or persist modifiedon date / actual end date in crm in Pre Operation.

In below sample am overriding modifiedon date on update of notes. Same way you can override actualend date in CRM 2015/ 2013/ 2011

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Client;

namespace Plugin
{
    public class NotePlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IOrganizationService service = null;

            Entity entity = null;
            ITracingService tracingService = null;

            tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            service = serviceFactory.CreateOrganizationService(context.UserId);

            try
            {
                switch (context.MessageName)
                {
                    case "Update":
                        {

                            DateTime? createdon = null;
                            if (entity.Attributes.Contains("createdon"))
                            {
                                createdon = entity.GetAttributeValue("createdon");
                            }
                            else if (context.PreEntityImages.Contains("PreImage"))
                            {
                                Entity PreImage = context.PreEntityImages["PreImage"];

                                if (PreImage.Contains("createdon"))
                                {
                                    createdon = PreImage.GetAttributeValue("createdon");
                                }
                            }

                            if (createdon != null && entity.Attributes.Contains("modifiedon"))
                            {
                                entity["modifiedon"] = createdon;
                            }
                            else if (createdon != null)
                            {
                                entity.Attributes.Add("modifiedon", createdon);
                            }
                        }
                        break;
                }
            }
            catch (FaultException ex)
            {
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }