Dynamics 365 Editable Grid Events & Methods

 

The much-awaited capability of editing a CRM grid inline is one of the new features in Dynamics 365. Using this functionality improves the productivity of the CRM user by significantly reducing the number of mouse clicks.

 

Editable grid is available as a UI control which can be added to an entity through entity customization. Addition of the editable grid to the desired entity will make all the entity views for that entity inline editable allowing the users to make in-place updates to the values of the grid view columns. The editable grid control also enables a very useful feature to group the records in the view by selected view columns. Using form customizations, this control can also be added to the subgrids on the form enabling them for inline edits.

To interact with the editable grid developers can write scripts which can be executed on the following grid events.

  • OnChange
  • OnRecordSelect
  • OnSave

The following table details out several editable grid methods to access the grid control elements and their values programmatically.

Method

Description Implementation

Grid Methods

getGrid() –  Returns the grid object

–  Contains information about all the grid elements

CRM Editable Grid 1
getRows() –  Returns an enumerable collection of data row of the grid

–  Contains information about the row elements of the grid

–  Returns all the rows displayed on the UI

CRM Editable Grid 2
getSelectedRows() –  Returns an enumerable collection of selected data rows of the grid

–  Returns data related to one or more rows selected on the UI

CRM Editable Grid 3
getTotalRecordCount() –  Returns the count of the number of rows in an entity view  

CRM Editable Grid 4

Grid Row Methods

getData(),

getKey(), getData().getEntity(), getData().getEntity().getEntityName(), getData().getEntity().attributes

–  Returns an object of the row data specific to the record displayed/selected in the grid

–  Contains entity information, attributes information and related entity information

–  Attributes returned are limited to the columns presented in the editable grid

CRM Editable Grid 5

 

Grid Cell Methods

setNotification(),

clearNotification(),

getName(),

getLabel()

–  Each grid cell is associated with a UI control like text, lookup, picklist

–  Information related to these control is available in the attribute collection

–  These controls can be accessed in a similar way as on the entity form

 

CRM Editable Grid 6

 

Hope you find it useful, stay tuned for more updates.

Thank you,
Swaroop Deshmukh
Lead Dynamics CRM Consultant @ Adisys

Advertisements

Introducing Transactions with Dynamics CRM 2015

 

We always wanted a transactions capabilities when you are performing business logic in enterprise applications, given the complexity of the application, integration or business rules. Transactions gives full capability to manage application behavior.

In order to implement transactions through windows or web based applications we used to write our own logic to roll back the operations in case of any business logic failure or change in data status.

We can take the example of my project where I wanted to rollback all operations in case of payment failure while buying order through online portal. In case of payment failure, I wrote my own logic to rollback records.

In Dynamics CRM 2015 update 1, as transactions been introduced, I was able to use ExecuteTransactionRequest, this is  helpful to maintain integrity during the context of transactions.

We can execute multiple operations in single database transaction so that either all operations will be executed successfully or none (revert back).

You need to add the reference to Microsoft.Xrm.Sdk dll.. We can provide collection of Organization request as given in below example.  I have added 3 requests to the collection. ExecuteTransactionRequest takes request collections as a parameter

public static void PerformTransactionOperation(OrganizationService service)
{
var request = new ExecuteTransactionRequest()
{
Requests = new OrganizationRequestCollection()
};

var account = new Entity(“account”);
account[“name”] = “Account Test”;
var createRequest = new CreateRequest() { Target = account };
request.Requests.Add(createRequest);

RetrieveRequest retReq = new RetrieveRequest() { Target = new EntityReference(“account”, new Guid(“B6F79317-5E8E-E511-80E7-3863BB2E1390”)) };

retReq.ColumnSet = new ColumnSet(“name”);
request.Requests.Add(retReq);
Entity accToUpdate = new Entity(“account”);

accToUpdate.Id = new Guid(“B6F79317-5E8E-E511-80E7-3863BB2E1390”);
var updateRequest = new UpdateRequest() { Target = accToUpdate };
request.Requests.Add(updateRequest);
try
{
var respTrans = (ExecuteTransactionResponse)service.Execute(request);
foreach (var response in respTrans.Responses)
{
switch (response.ResponseName.ToUpper())
{
case “CREATE”:
var createResponse = (CreateResponse)response;
Console.WriteLine(“Account created: {0}”, createResponse.id);
break;

case “UPDATE”:
var updateResponse = (UpdateResponse)response;
break;

case “DELETE”:
var deleteResponse = (DeleteResponse)response;
break;

case “SETSTATE”:

var setstateResponse = (SetStateResponse)response;

break;

case “RETRIEVE”:
var retResponse = (RetrieveResponse)response;
break;
}}}
catch (FaultException<OrganizationServiceFault> ex)
{
ExecuteTransactionFault fault = (ExecuteTransactionFault)ex.Detail;
}}

It will be executed in the same order as it was added to collection.

In our case we got 3 responses for each request. In my code, I am checking the Response name and accordingly performing each operation.

If you want to know the exact request that was failed, you can check the FaultedRequestIndex as given below. It will tell you the index number of the request that was failed.

Few important points to Note:

  • An ExecuteMultipleRequest may have multiple ExecuteTransactionRequest instances.
  • An ExecuteTransactionRequest instance may not contain a ExecuteMultipleRequest or ExecuteTransactionRequest.
  • It has same limit as ExecuteMultipleRequest. Maximum batch size could be 1000. You can have maximum 1000 Requests in a batch.
  • CRM online can have maximum 2 Concurrent batch request.
  • If you have more than 1000 Requests you have to split the requests in batches.

Hope this Post is helpful. I would love to hear your suggestions.

Happy CRMing!!!!!!!!
Thank you,
Kalim Ansar
Adisys Corporation

Set Custom Help URLs in Dynamics CRM Online 2015

Set Custom Help URL CRM Online 2015
Custom Help URL is another exciting feature in Dynamics CRM 2015. Administer can simply enable and configure the URL at both Global Level and Entity Level.

There are 3 kind of Help URL:

  • Build-in CRM Help (Default)
  • Global Level Custom Help
  • Entity Level Custom Help (Support both OOB entity and Custom Entity)

1)    Build-in CRM Help:

Below is the built-in CRM Online Help hosted on Microsoft website. User will be navigated to this online knowledge base center by default after clicking on Help link.

Dynamics CRM Help #1

Dynamics CRM Help #1

Dynamics CRM Help #1

 

 

 

 

 

 

2)     Custom URL at Global Level

System administrator can configure Global custom Help URL. Go to Settings -> Administration -> System Settings -> General:

Dynamics CRM Help #2

Dynamics CRM Help #2

 

 

Global Custom Help URL link in CRM:

Dynamics CRM Help #3

Dynamics CRM Help #3

 

3)     Entity Level Custom Help URL

To enable and configure the custom help URL on a specific entity form, administrator can go to Entity Customization:

Dynamics CRM Help #4

Dynamics CRM Help #4

 

Help Link on Entity form:

Dynamics CRM Help #5

Dynamics CRM Help #5

Hopefully you will find it useful!
Thank you,
Zhe Chen
Adisys Corporation

Set Hierarchy Security in Dynamics CRM Online

We have a requirement to allow the manager to view and update the records owned by the direct report.

In Dynamics CRM 2015 introduced hierarchy security model in CRM 2015 Update 1 which make it super easy to implement this kind security requirement.

Hierarchy security is an extension to the existing security models that use business units, security roles, sharing, and teams. There are two security options in Hierarchy Security Model:

  • Management Chain, based on the direct reporting structure and the hierarchy depth
  • Position Hierarchy, based on the defined job positions and the hierarchy depth
Dynamics CRM 2015 Hieararchy Security

Dynamics CRM 2015 Hieararchy Security

 

A user can be assigned to one position and hence get a Read, Write, Update, Append, AppendTo access to the lower positions’ data in the direct ancestor path. The non-direct higher positions, have Read-only access to the lower positions’. Following is a sample of the Position Hierarchy structure defined in CRM.

In this organization, CEO has full access to the data owned by HR Managers, Sales Managers and Service Managers. Sales managers has the full access to the data owned by Sales. Once you have position hierarchy defined in system then administrator can easily assign the user for the position to get the access accordingly.

Dynamics CRM 2015 Hierarchy Security #2

Dynamics CRM 2015 Hierarchy Security #2

Hopefully you find it useful!
Thank you,
Zhe Chen
Adisys Corporation

CRM 2013 – JavaScript – Unsaved Message due to a jQuery masking Plug-In

CRM Unsaved Message due to a JQuery masking plugin

We have a requirement to have telephone number displayed with the carrier code. It can be implemented by using a JQuery masking plugin. The details can be found in this blog: http://slalomdotcom.wordpress.com/2011/06/03/crm-field-masking-with-jquery/

However the record status will be changed to ‘unsaved changes’ after page loading. CRM pops up message ‘Your changes have not been saved. To stay on the page so that you can save your changes, click Cancel’ when user leave page without any changes. This is very frustrating and it can’t be resolved directly by setting Xrm.Page.data.setFormDirty(false)

crmunsaved

Finally we decided to use JS to Mask the telephone fields instead of JQuery plugin. Following is the sample code:

On Form Load:

Function formatTel()

{

var sTmp = Xrm.Page.getAttribute(“telephone1”).getValue();

sTmp = sTmp.replace(/[^0-9]/g, “”);

switch (sTmp.length) {

case 10:

sTmp = “(” + sTmp.substr(0, 3) + “) ” + sTmp.substr(3, 3) + “-” + sTmp.substr(6, 4);

break;

default:

sTmp = “(” + sTmp.substr(0, 3) + “) ” + sTmp.substr(3, 3) + “-” + sTmp.substr(6, 4) + ” x” + sTmp.substr(10, sTmp.length – 10)

break;

}

Xrm.Page.getAttribute(“telephone1”).setValue(sTmp);

Xrm.Page.getAttribute(“telephone1”).setSubmitMode(“never”);

}

//On Field change reset submit mode to always:

function changeSubmitMode(mode) {

// mode = “always”

if (Xrm.Page.getAttribute(“telephone1”).getSubmitMode() != mode ){

Xrm.Page.getAttribute(“telephone1”).setSubmitMode(mode);

}

}

 

 

// Remove phone masking before saving back to CRM

function removePhoneMasking(text) {

text = text.replace(“(“, “”);

text = text.replace(“)”, “”);

text = text.replace(“-“, “”);

text = text.replace(/ /g, “”);

return text;

}


 

I hope you find it useful!

Author: Zhe Chen
Title: Lead Dynamics CRM Consultant @ Adisys
Email: zhechen@adisys.co

CRM 2013 – Business Process Flow – Access to multiple entities on the same business process flow

Dynamics CRM 2013 BPFs have many beneficial qualities.  They are available for both OOB and custom entities, can span across multiple entities. You can associate business process flows with security roles so that only people with those security roles can see or use them. Also there could be multiple entities associated with the same business bar for different security roles. What’s the behavior if user doesn’t have write access to one of the entity? Can this user click next stage to move the process forward without the write access to next entity?

We have two entities (Entity A & Entity B) added into the same business process flow. Below are our observations:

1)      If user has write access to Entity B, he is allowed to click on the Next Stage to create a new Entity B record or select an existing entity B record to make it associated to the business process flow:

CRM Business Prooces  Flow 1

CRM Business Prooces Flow 1

2)     If user has only read access to Entity B, the ‘create’ button will be hidden:

CRM Business Prooces  Flow 2

CRM Business Process Flow 2

After selecting an existing Entity B record, the entity B form shows up without process bar. This makes sense as this user is not allowed to update the process id on Entity B without the write access.

CRM Business Process  Flow 3

CRM Business Process Flow 3

 

I hope you find it useful!

Author: Zhe Chen
Title: Lead Dynamics CRM Consultant @ Adisys
Email: zhechen@adisys.co

CRM 2013-Increase width of Process Step Label in Business Process

Business Process is the new feature in CRM 2013 and user can add multiple steps on the form. However we don’t have ability to change the layout of the process bar and the step name will be wrapped automatically.

To show the step name on the form completely, we decide to increase the width of the step name label by loading the customized CSS file. Following is the screenshot of layout change, JavaScript and the CSS file.

 

Business Process Formatting

Business Process Formatting

Sample Java Script used:

//***************************************************************************

// Script Type: Changing Process step Label width

//***************************************************************************

function LoadCSS() {

var head = document.getElementsByTagName(‘head’)[0];

var link = document.createElement(‘link’);

var path = Xrm.Page.context.getClientUrl() + “/WebResources/_cssfile”;

link.rel = ‘stylesheet’;

link.type = ‘text/css’;

link.href = path;

link.media = ‘all’;

head.appendChild(link);

 }

// End of the script

CSS:

/*Increase width of process step*/

.processControlContainer div.processStepLabel {

width: 230px!important;

}

.processControlContainer div.processStepLabel span {

max-width: 220px!important;

}

//end of CSS Script

______________________________________________________________

I hope you find it useful!

Author: Zhe Chen
Title: Lead Dynamics CRM Consultant @ Adisys
Email: zhechen@adisys.co