Friday, February 19, 2021

Create a record in Dynamics 365 Online V 9.X using JavaScript WebAPI

 
Here is the latest Syntax available to create a record in Dynamics 365 Online V9.X using JavaScript,

Syntax:

Xrm.WebApi.createRecord(entityLogicalName, data).then(successCallback, errorCallback);

Parameters:

NameTypeRequiredDescription
entityLogicalNameStringYesLogical name of the entity you want to create. For example “account”.
dataObjectYesA JSON object defining the attributes and values for the new entity record.

See examples later in this topic to see how you can define the data object for various create scenarios.

successCallbackFunctionNoA function to call when a record is created. An object with the following properties will be passed to identify the new record:

·        entityType: String. The entity logical name of the new record.

·        id: String. GUID of the new record.

errorCallbackFunctionNoA function to call when the operation fails. An object with the following properties will be passed:

·        errorCode: Number. The error code.

·        message: String. An error message describing the issue.

Return Value:
On success, returns a promise object containing the attributes specified earlier in the description of the successCallback parameter.

Example:
Create a new Javascript Webresource (new_Account.js) and copy paste the below code in it and call it OnLoad of the page of the Account.

After that, open any existing Account record

function CreateAccountRecord() {
    // Define the data to create new account
    var accountData =
    {
        "name": "Amresh K Ltd.", // Single Line of Text
        "creditonhold": false, // Two Option Set
        "description": "This is the description of the sample account", // Multiple Lines of Text
        "revenue": 10000000, // Currency
        "industrycode": 1, // 1 - Accounting // OptionSet
        "primarycontactid@odata.bind": "/contacts(39582A13-E6E7-E711-A95E-000D3AF27CC8)" // ContactId - Amresh K // Lookup
    }
 
    // Create account record
    Xrm.WebApi.createRecord("account", accountData).then(
        function success(result) {
            // Show Account GUID
            Xrm.Utility.alertDialog("Account created with ID: " + result.id, null);
        },
        function (error) {
            // Show Error
            Xrm.Utility.alertDialog("Error :" + error.message, null);
        }
    );

}


Output:



Thanks!
Keep Learning ...
Happy CRMing...


Thursday, February 11, 2021

In Dynamics 365 steps to create early bound entity classes using CrmSvcUtil.exe

 

Steps to Create early bound entity classes with the code generation tool (CrmSvcUtil.exe) 💭

CrmSvcUtil.exe is a command-line code generation tool for use with Dynamics 365 for Customer Engagement. This tool generates early-bound .NET Framework classes that represent the entity data model used by Dynamics 365 for Customer Engagement.

The code generation tool (CrmSvcUtil.exe) is distributed as part of the Microsoft.CrmSdk.CoreTools NuGet package. For information about downloading the code generation tool (CrmSvcUtil.exe), see Download tools from NuGet.

Follow the below steps to generate early bound class for dynamics 365 using CrmSvcUtil.exe:

  1. Download the latest CRM SDK.
  2. Go to SDK\Bin folder or CoreTools folder, where you can find the CrmSvcUtil.exe tool
  3. Open the command prompt and go to the SDK folder path where the tool is present using "cd <here add SDK path>".  e.g.: If you have placed the CoreTools folder in c drive then run the command "cd C:\Software\SDK9.0\Tools\CoreTools\" to move to CoreTools directory as shown below:

4.  Run the code generation tool: Run the CrmSvcUtil.exe tool from the SDK\Bin folder. If you run the tool from another folder location, make sure that a copy of the Microsoft.Xrm.Sdk.dll assembly is in that same folder.

The following sample shows the format for running the tool from the command line for an on-premises installation of Dynamics 365 for Customer Engagement. You supply the parameter values for your installation.   

Type the following command post replacing service URL, username, and password with your org details:

CrmSvcUtil.exe /url:https://<serverName>/<organizationName>/XRMServices/2011/Organization.svc    /out:<outputFilename>.cs /username:<username> /password:<password> /domain:<domainName>    /namespace:<outputNamespace> /serviceContextName:<serviceContextName>
For Example:

CrmSvcUtil.exe /url:https://***/XRMServices/2011/Organization.svc /out:C:\EarlyBound.cs /username:"***@myOrg.onmicrosoft.com" /password:"mypassword" /namespace:earlybound /serviceContextName:ServiceContext

(To get service URL to navigate to Settings>Customization>Developer resources>Organisation Service )

Click on the enter button and you will have the EarlyBound.cs file in the C drive. 

Refer to MS Docs for more information:

https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/org-service/create-early-bound-entity-classes-code-generation-tool


Hope it helps!

Thanks!!