My Photo

Microsoft Dynamics 365

Official Blog for Microsoft Dynamics Functional and Technical Solutions....
Browsing Category " IN MSCRM "

Show Progress Indicator (Out of the box) Microsoft Dynamics 365 CRM V9

Yesterday used a nice feature progress indicator, before we use to write custom JS to show loading progress image but now we can use new JavaScript function of the Xrm.Utility namespace : showProgressIndicator.


  • showProgressIndicator
  • closeProgressIndicator

show progress indicator (loading image)

------------------------------------------------------------------------------------------------------

function setFaxNumber() {
    Xrm.Utility.showProgressIndicator("Loading contact Info..");
    setTimeout(setFaxNumberafterdelay, 3000);
}
function setFaxNumberAfterDelay() {
    var phoneNumber = Xrm.Page.getAttribute("telephone1").getValue();
    if (phoneNumber != null) {
        Xrm.Page.getAttribute("description").setValue(phoneNumber);
    }
    Xrm.Utility.closeProgressIndicator();

}

---------------------------------------------------------------------------------


Entity for Views in CRM based on View Ownership - SavedQuery and UserQuery Entity

There are 2 types of View in CRM entity based on View Ownership , which are stored in two different entities.

1)  Organisation or System View - stored in the View Entity (SavedQuery)
2)  Individual, personal or User/Team View - stored in the Saved View Entity (UserQuery)

Below is the Fetch XML that you can use to retrieve the Data of the entites

1)  Organisation or System View
<fetch top="5000" >
  <entity name="savedquery" >
    <attribute name="name" alias="ViewName" />
    <attribute name="createdbyname" alias="Owner" />
    <attribute name="description" alias="Description" />
    <attribute name="returnedtypecode" alias="returnCode" />
    <attribute name="fetchxml" alias="fetchXML" />
  </entity>
</fetch>

2)  Individual, personal or User/Team View
<fetch top="5000" >
  <entity name="userquery" >
    <all-attributes/>
    <attribute name="name" />
    <order attribute="name" descending="false" />
    <attribute name="ownerid" />
    <attribute name="modifiedon" />
    <attribute name="userqueryid" />
  </entity>
</fetch>

We can retrieve the data of these entries by C# also you can see the full code example here:
https://msdn.microsoft.com/en-us/library/gg594431.aspx

You can also use LINQ query for retrieving these view.

Happy CRMing 😊

Add value in option set - Status Reason C#

Reference to be used - using Microsoft.Crm.Sdk.Messages;
var response = ((InsertStatusValueResponse)service.Execute
(
new InsertStatusValueRequest
{
    AttributeLogicalName = "statuscode",
    EntityLogicalName = "task",
    Label = new Microsoft.Xrm.Sdk.Label("Auto Closed", 1033),
    StateCode = 1 //Status: 0 active & 1 inactive
}
)).NewOptionValue;


Happy Coding 😊

Validation to accept only Numeric Character in MS CRM


Below script is a generic validation which will show for error if field is having anything except numeric value



function ValidateOnlyNumeric(context) {
    var fieldname = context.getEventSource().getName();
    var phone = Xrm.Page.getAttribute(fieldname).getValue();
    if (checkFormat(phone)) {
        Xrm.Page.getControl(fieldname).clearNotification();
    } else {
        Xrm.Page.getControl(fieldname).setNotification("Please enter only numeric characters");
    }
}
function checkFormat(phone) {
    var regex = /^\d+$/;
    if (regex.test(phone)) {
        return true;
    } else {
        return false;
    }
}

To enable it for any field just register it on change of the required field with function name “ValidateOnlyNumeric” and check “Pass execution context as first parameter ” and save an publish it will start working



Hope it helps

Happy Coding 😊

Create and Send Email Message Activity from javascript using api D365 / MS CRM 2016

For Creating email message activity from java script MS CRM , you can update and use the below code according to your requirement. Here to show I have taken up a scenario to send a email to system user when a Quote is won.

Replace the User GUID for to and from user in "fromFieldIdSystemAdmin" and  "toPartyUsersId"

function CreateEmail() {
    var fromFieldIdSystemAdmin = "53536B3D-4D71-4FC2-857C-0477750A92BE"; //todo Email from User GUID
    var toPartyUsersId = ["53536B3D-4D71-4FC2-857C-0477750A92BE"]; //todo Email To user array
    var quoteId = Xrm.Page.data.entity.getId();
    quoteId = quoteId.replace(/[{}]/g, "");
    var customerLookUp = Xrm.Page.getAttribute("customerid");
    var accountName = null;
    if (customerLookUp != null)
        accountName = customerLookUp.getValue()[0].name;
    var webapiPath = Xrm.Page.context.getClientUrl() + "/api/data/v8.0/emails";
    var email = {};
    //Lookup
    email["regardingobjectid_quote@odata.bind"] = "/quotes(" + quoteId + ")"; //Regarding is quote
    email["subject"] = "Quote Sent ";
    email["description"] = "See attachment for the Quote that was set as Won";
    var parties = [];
    //ActivityParty (From)
    var sender = {};
    sender["partyid_systemuser@odata.bind"] = "/systemusers(" + fromFieldIdSystemAdmin + ")";
    sender["participationtypemask"] = 1; //From
    parties.push(sender);
    for (i = 0; i < toPartyUsersId.length; i++) {
        var receiver = {};
        receiver["partyid_systemuser@odata.bind"] = "/systemusers(" + toPartyUsersId[i] + ")";
        receiver["participationtypemask"] = 2; //To
        parties.push(receiver);
    }
    email["email_activity_parties"] = parties;
    var service = new XMLHttpRequest();
    service.open("POST", webapiPath, false);
    service.setRequestHeader("Accept", "application/json");
    service.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    service.setRequestHeader("OData-MaxVersion", "4.0");
    service.setRequestHeader("OData-Version", "4.0");
    service.send(JSON.stringify(email));
    if (service.readyState == 4) {
        if (service.status == 204) {
            var uri = service.getResponseHeader("OData-EntityId");
            var regExp = /\(([^)]+)\)/;
            var matches = regExp.exec(uri);
            var emailGblId = matches[1];
            SendEmail(emailGblId);
        } else {

            Xrm.Utility.alertDialog(this.statusText);
        }
    }
}

function SendEmail(emailGblId) {
    var parameters = {};
    parameters.IssueSend = true;
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/emails(" + emailGblId + ")/Microsoft.Dynamics.CRM.SendEmail", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var results = JSON.parse(this.response);
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(parameters));
}

function successCallback() {
}
function errorCallback() {
}
Happy Coding 😊


SOURCE : mscrm.com

Create Your First Plugin Dynamics MS CRM

For your first Plugin we will take a test scenario - on create of contact record our plugin will forcefully update its email address to "testemail@gmail.com" and to achieve this you just need to follow the below steps.

There are two parts to successfully run a plugin in MSCRM

1) Create Your Plugin
2) Resister your plugin

Plugin Creation

Step 1 - Open Visual studio


Step 2 - Go to File - New - and Click on Project


Step 3 - A dialogue will appear, from left navigation panel select Class Library template in Visual C#  and Enter Project and Solution name and hit on OK Button


Step 4 - Visual studio will create and open a blank class library template.Right Click on Project and click on Add References option


Step 5 - Reference Manager dialogue will open.From left navigation panel go to Assemblies - Framework then select two references and click on OK button
1)System.Runtime.Serialization
2) System.ServiceModel


Step 6 -  Right Click on Project and again click on Add References option, then in Reference Manager dialogue from left navigation panel go to Browse - Click on Browse button then select two references
1)System.Runtime.Serialization
2) System.ServiceModel



Step 7 -  After Click on Browse button go to your sdk (downloaded from prerequisites) - bin, then select the following dlls files and click on add and then OK button
1) miscrosoft.xrm.client.dll
2) Microsoft.Xrm.Sdk.dll


Step 8 -  Open the class named Class.cs from solution explorer and modify the below code in it.
If your namespace name and class name is different then remember to verify and update it.

Code Snippet : 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;

namespace My_First_Plugin
{
    public class Class1 : IPlugin     //{inherit the class Iplugin in your class}
    {
        public void Execute(IServiceProvider serviceProvider)        //{add the execute method}
        {
            // create context , service factory and service objects
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            //to enter  value in Email field in contact entity

            //create an object of predefined class Entity and pass entity name as its parameter
            
            Entity Object = new Entity("contact");   // in place of contact you can write schema name of entity on which you want to preform operations

            Object.Attributes.Add("emailaddress1", "testemail@gmail.com");  //emailaddress1 is the schema name of the Email field in contact entity
             //testemail@gmail.com is the value

            //to update the record service.Update(object of the entity)
            service.Update(Object);

        }
    }
}

After updating your code your code will look like this 


Step 9 -  Right click on Project and click on Properties


Step 10 -  Now, we have to create a key. Go to Signing - select the checkbox "Sign the assembly" and click on <New..> option 


Step 11 -  Enter any name you want for your Key and click on OK button


Step 12 -  Click on Save Button


Step 13 - Go to BUILD from ribbon menu and select Build Solution option




Will Update this thread Soon 


Happy Coding 😊


Xrm.Page.ui control (client-side reference)

SOURCE : msdn.microsoft.com

Xrm.Page.ui control (client-side reference)

Dynamics CRM 2013
This topic has not yet been rated Rate this topic
Applies To: Microsoft Dynamics CRM 2013, Microsoft Dynamics CRM Online
The control object provides methods to change the presentation or behavior of a control and identify the corresponding attribute.