Tuesday, 16 May 2017

Update Optionset, lookup data using OData service, JSON


Here we are going to update Optionset and Lookup fields using Odata Service in CRM 2011. In the SDK sample you will find only to update Text fields. After spending some time on Odata service, i got the solution to update Option set and Lookup fields.

        Here i am going to update Account information using Odata service.
function updateOptionset() {
    // Gets the record Guid
    var id = Xrm.Page.data.entity.getId();    
    var changes = {
      // Text field
        Telephone1: "123456789", 
     // Option set field    
       Address1_AddressTypeCode: {  Value: 3 },
      // Lookup field
       ParentAccountId: {         
           Id: "8F8338A9-9AB2-E011-9E6D-000C29B0167C", // Guid of the parent account
           LogicalName: "account"
       }
    };
  
    //updateRecord exists in JQueryRESTDataOperationFunctions.js
    updateRecord(id, changes, "AccountSet", updateAccountCompleted, null);
}

function updateRecord(id, entityObject, odataSetName, successCallback, errorCallback) {
    var context = Xrm.Page.context;
    var serverUrl = context.getServerUrl();

    //The XRM OData end-point
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

    //id is required
    if (!id) {
        alert("record id is required.");
        return;
    }
    //odataSetName is required, i.e. "AccountSet"
    if (!odataSetName) {
        alert("odataSetName is required.");
        return;
    }

    //Parse the entity object into JSON
    var jsonEntity = window.JSON.stringify(entityObject);

    //Asynchronous AJAX function to Update a CRM record using OData
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        data: jsonEntity,
        url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.             
            XMLHttpRequest.setRequestHeader("Accept", "application/json");

            //Specify the HTTP method MERGE to update just the changes you are submitting.             
            XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
        },
        success: function (data, textStatus, XmlHttpRequest) {
            //The MERGE does not return any data at all, so we'll add the id 
            //onto the data object so it can be leveraged in a Callback. When data 
            //is used in the callback function, the field will be named generically, "id"
            data = new Object();
            data.id = id;
            if (successCallback) {
                successCallback(data, textStatus, XmlHttpRequest);
            }
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            if (errorCallback)
                errorCallback(XmlHttpRequest, textStatus, errorThrown);
            else
                errorHandler(XmlHttpRequest, textStatus, errorThrown);
        }
    });
}


function errorHandler(xmlHttpRequest, textStatus, errorThrow) {  
    alert("Error : " + textStatus + ": " + xmlHttpRequest.statusText);
}

//Called upon successful Account update.
function updateAccountCompleted(data, textStatus, XmlHttpRequest) {   
    //Get back the Account JSON object
    var account = data;
    alert("Account updated: id = " + account.id);
}

Hope it helps!!!!

Email Configuration in Dynamic CRM 2016 or 2015

For GMAIL  :



Perform the following Steps to enable the following Gmail settings to work with CRM:

Server Type: Other (POP3/SMPT)
Incoming Server Location: pop.gmail.com
Outgoing Server Location: smtp.gmail.com
Authenticate Using: Credentials Specified by a User or Queue
Use same settings for Outgoing: No (currently, but have used Yes and "Credentials Specified by a User or Queue" also)

Incoming Port: 995
Outgoing Port: 587


Other things to be noted :


1.- Enable POP/Imap ports in GMAIL (configuration/settings Forwarding and POP/IMAP)
2.- Security Checkup: Accounts and Import - Other Google Account settings
3.- Disable less secure apps www.google.com/.../lesssecureapps

Monday, 15 May 2017

CRM 2015 or 2016 Retrieve Plugin code

public void Execute(IServiceProvider serviceProvider)
{
    // Obtain the execution context from the service provider.
    Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
        serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

    if (context.Depth == 1)
    {
        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

        // Obtain the target entity from the input parmameters.
        EntityReference entity = (EntityReference)context.InputParameters["Target"];

        ColumnSet cols = new ColumnSet(
                             new String[] { "lastname", "firstname", "address1_name" });

        var contact = service.Retrieve("contact", entity.Id, cols);

        if (contact != null)
        {
            if (contact.Attributes.Contains("address1_name") == false)
            {
                contact.Attributes.Add("address1_name", "a default first time value: " );
            }
            else
            {
                contact["address1_name"] = "a value already exist";
            }
            service.Update(contact);
        }
    }
}
 
message : retrieve
mode : synchronous 
pipeline stage :post operation 

Thursday, 11 May 2017

Managed And Unmanaged Solutions in Dynamic crm

Microsoft Dynamic CRM supports two types of solutions:
  • Managed solution
  • Unmanaged solution.
Managed Solution:
A managed solution is a completed solution in which the solution is prevented from being modified in the environment to which it is imported. A managed solution is intended to be distributed and installed.
• Possible to set granular levels of rights to alter elements of the solution such as create views, change field properties, add fields etc.
• Solution cannot be exported.
• Easier administration with new versions. Any changes including field removal will be rendered
• If the solution is removed all the customizations pertaining to that solution will be removed and there will be a Risk of data loss.
Once the managed solution is imported following steps takes place:
  • User cannot add or remove the components in a managed solution.
  • User cannot Export a managed solution.
  • By deleting the managed solution all the components in the solutions will also be uninstalled.
  • Managed solution can be overridden by another new version of managed solution.
Unmanaged Solution:
Unmanaged solution allows the solution to be modified after it is imported. Unmanaged solution is still under development stage and it is not intended to be distributed or installed.
  • All the elements or components in the solution can be customized without any restriction.
  • An unmanaged solution can be exported.
  • When the unmanaged solution is completed and ready to distribute it, export it and package it as a managed solution.
· Unmanaged solution files can be transported from one environment to the other.
  • Entities, Fields, web resources can be removed manually.
The solution acts as a container for the components. If user deletes the solution the components still exist in the default solution.
When a solution is unmanaged, the following steps can takes places:
  • Components can be added and removed.
  • Components can be deleted that allow for deletion.
  • Can Export and Import the unmanaged solution.
  • Unmanaged Solution can be exported as a managed solution once the changes are done.

Power Apps Drag & Drop Kanban code sample

  Introduction: The Kanban Board App Developers at a software company use the Kanban board to show their progress on development tasks and b...