Archive for March, 2018

Dynamics 365 – Create/Modify Views using App Designer

In this article, I am going to detail, how views can be created or modified using App Designer.

Open ‘App Designer’:

  • To start off, go to ‘My Apps’ by navigating to ‘Settings –> Application –> My Apps’

Views - 1.PNG

  • Open the ‘Sales’ app in ‘App Designer’ by clicking ‘OPEN IN APP DESIGNER’

Views - 2

Add/Edit Views:

Once the ‘App Designer’ loads, lets see how to modify Account’s ‘Active Accounts’ view

  • From the ‘App Designer’ window, under ‘Entity View’ section, select the ‘Views’ tab from ‘Account’ row.
  • On the right side ‘Public Views’ tab, select the View you want to modify (i.e., ‘Active Accounts’ in my case)
  • After selecting the view from right window, back to ‘Views’ tab and expand, open the ‘Active Accounts’ to Edit

Views - 3

  • To add new column, click on ‘Add’ button, choose Primary or Related entity to add the fields from and drag and Drop the column you want.

Views - 4

  • Expand the ‘Filter Criteria’ tab to update the filter

Views - 5

  • To add new view, click ‘Create New’ from your ‘App Designer’

Views - 6

With the ‘App Designer’, you can perform all the view customizations, which you can do with conventional view editor.

Refer article  for more details.


[Code Snippet] Upload file to Azure blob – C#

In this article I am going to provide details and code snippets on how to upload attachment to Azure blob storage from console application.


Below are the prerequisites to run the code snippet and upload the file

  • Azure subscription:You need an Azure subscription as the first  step.
    • You can spin up 30 days trail Azure subscription. Click here
    • Note: You need to share valid credit card details to complete the subscription and you will be charged 2 INR.
  • Storage Account:Add a storage account

Azure - Storage Account

  • Container:
    • Add a Container
    • Copy the Container Name.

Azure - Storage Account - Containers

  • Access Keys:Need the ‘Key’ to connect to Azure Blob from your C# console.
    • Copy and keep below 2 values as shown in screenshot
      • Storage Account Name
      • Key 1

Azure - Storage Account - Keys

  • Nuget package:Add below nuget packages to your console project
      • Microsoft.WindowsAzure.Storage

C# Code Snippet:

// Namespaces

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;

private static void AddFileToBlob(){
var accountName = “{Storage Account Name}“; // Refer Prerequisites for value
var keyValue = “{key 1}“; // Refer Prerequisites for value
var useHttps = true;
var connValid = true;

// Establish connection to Azure

var storageCredentials = new StorageCredentials(accountName, keyValue);
var storageAccount = new CloudStorageAccount(storageCredentials, useHttps);
var blobConString = storageAccount.ToString(connValid);

// Retrieve storage account from connection string.
storageAccount = CloudStorageAccount.Parse(blobConString);

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Set container name
CloudBlobContainer container = blobClient.GetContainerReference(“{Container Name}“); // Refer Prerequisites for value

// Set your blob name; It can be anything
CloudBlockBlob blockBlob = container.GetBlockBlobReference(“{Your desired blob name}“);

// Set your file path which you want to upload to blob
using (var fileStream = System.IO.File.OpenRead(@”D:\ABC.PNG”)) {

Console.WriteLine(“File added to Blob!!!”);


Categories: Azure Tags: ,

D365 – JScript – Deep Insert – Xrm.WebApi

Dynamics 365/Version 9.x has brought new objects to the Xrm client object model.

Deep Insert - 4

One of the new additions to Xrm object  is ‘WebApi’ where you can perform CRUD operations.

WebAPI provides wrappers for all CRUD operations with in the framework so that we dont need to rely on 3rd party helper libraries. For example XrmServiceToolKit

In this article I am going to explain the Deep Insert using the Xrm.WebApi.

What is a ‘Deep Insert’:

  • Deep Insert is a create operation where we create a primary record along with new related records.
  • In simpler words, In a single ‘Create’ server call, we can create Account and related Contact and Opportunity along with a Task.
    • Account (i.e., Primary)
  • Deep Insert - 2
    • and Related
      • Contact (and set Account.PrimaryContact)
      • Opportunity (and associate with created Account)

Deep Insert - 3

  • Below is the syntax

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


Here is the sample code to create an Account and related records.

function createAccountAndRelated() {
// Define data to create primary (i.e.,Account) and related (i.e.,Contact and Oppoerunity) entity records
var data =
“name”: “XYZ Account”,
“creditonhold”: false,
“address1_latitude”: 47.639583,
“description”: “Creating Account along with new Primary Contact and Opportunity”,
“revenue”: 5000000,
“accountcategorycode”: 1,
“firstname”: “Rajeev”,
“lastname”: “Pentyala”
“name”: “New Opportunity”,
{ “subject”: “Task associated to the new opportunity” }

// create account record
Xrm.WebApi.createRecord(“account”, data).then(
function success(result) {
console.log(“Account created with ID: ” +;
function (error) {

Deep Insert - I


Categories: CRM, Dynamics 365 Tags: ,

D 365 – Set Recommendation on a field using JScript/Business Rule

In this article I am going to detail the steps to set a notification (i.e., Recommendation/Error) to a particular control on the form.

Notifications can be of 2 types; Error or Recommendation.

  • If an ‘Error’ notification set, a red “X” icon appears next to the control. Setting an error notification on a control blocks saving the form.
  • If a ‘Recommendation’ notification set, an “i” icon appears next to the control. A recommendation notification does not block saving the form.

To explain this better, I am taking below scenario

  • If ‘Account Name’ is ‘Microsoft’ recommend to set ‘Ticker Symbol’ to ‘MSFT’

Recommendation - 1

  • From the recommendation, if I click on ‘Apply’, set ‘Ticker Symbol’ to ‘MSFT’

Recommendation - 2

Setting Recommendation using ‘Business Rule’:

Create a new ‘Business Rule’ with below components

Recommendation - BR 2

  • Add a “Condition” flow with condition (If ‘Account Name’ = ‘Microsoft’ AND ‘Ticker Symbol’ <> MSFT)
  • If condition met, add ‘Recommendation’ action
  • Under ‘Recommendation’ action, add sub Action, set ‘Ticker Symbol’ field to ‘MSFT’

Recommendation - BR 1

Setting Recommendation from JScript:

Register this function on form ‘onload’ and ‘onchange’ of ‘Account Name’ field.

function setRecommendationOnAccountName() {
var ctrlAccountName = Xrm.Page.getControl(‘name’);
var accountName =‘name’);
var tickerSymbol =‘tickersymbol’);

// Check condition (If ‘Account Name’ = ‘Microsoft’ AND ‘Ticker Symbol’ <> MSFT)
if (accountName.getValue(‘Microsoft’) && tickerSymbol.getValue() != ‘MSFT’) {
var actionCollection = {
message: ‘Set the Ticker Symbol to MSFT?’,
actions: null

// Add sub Action, set ‘Ticker Symbol’ field to ‘MSFT’ and clear Recommendation
actionCollection.actions = [function () {

// Set the Notification to ‘Account Name’ control
messages: [‘Set Ticker Symbol’],
notificationLevel: ‘RECOMMENDATION’,
uniqueId: ‘notify_account_name’,
actions: [actionCollection]


  • notificationLevel : Valid values are either ERROR or RECOMMENDATION. If nothing specified in object definition, it is set to ERROR by default.


Dynamics 365 – Capture events from Editable subgrid and set main form fields

To answer one of the queries posted on my blog, in this article I am going to detail, capturing the events from Editable sub grid and Get/Set the form fields.

To simplify the explanation, I am taking below use case

  • On Account from configure ‘Contacts’ editable sub grid
  • On change of ‘Business Phone’ from ‘Contact’ sub grid
    • Read the new ‘Business Phone’ value
  • SubGridEvent_3
    • Set the ‘Telephone’ field on Account form with the Contacts ‘Business Phone’


below are the execution steps

Add ‘Editable Grid’ on Account Form:

  • Add a ‘Contact’ sub grid on the Account form (You can leverage OOB Contacts grid as well)
  • To convert read only grid to Editable grid, Double click on ‘Sub grid’ and go to ‘Controls’ -> Add Control
  • Choose ‘Editable Grid’ option from the list

Add Sub Grid

  • Select ‘Web’ checkbox

Add Sub Grid_1

  • Click ‘OK’

Register ‘onchange’ event on sub grid field:

  • Double click on ‘Sub grid’ and go to ‘Events’
  • Select the Field as ‘Business Phone’ and the Event as ‘OnChange’


  • Add click ‘+Add’ to add your Jscript function name
    • Function : businessPhoneOnChange
  • Make sure you select the ‘Pass execution context as first parameter’ checkbox


  • Save and Publish the form

JScript function:

function businessPhoneOnChange(execContext) {
try {
var formContext = execContext.getFormContext();

// Read the changed Business Phone’ value from sub grid
var entityObject = formContext.getData().getEntity();
var contactBusinessPhone = entityObject.attributes.getByName(“telephone1”).getValue();
// showAlert(“Business Phone – ” + contactBusinessPhone);

// Set the ‘Phone’ field on ‘Account’ form
} catch (e) {
showAlert(“Error in businessPhoneOnChange – ” + e.description);

function showAlert(message) {
var alertStrings = { confirmButtonLabel: “Yes”, text: message };
var alertOptions = { height: 120, width: 400 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
function success(result) {
console.log(“Alert dialog closed”);
function (error) {