Optimistic concurrency in CRM Online 2015 Update 1

Another enterprise capability has been added to the Dynamics CRM 2015 Online Update 1. Kudo’s the Dynamics CRM PG team.  This is going to ease the Optimistic concurrency enablement in the product layer.

Prior to CRM online 2015 update 1, There were no concurrency lock checks out of the box and CRM always saves the value on the field level. The latest transaction will win (Overwrite). Developers might build some customization code to ensure the data integrity. However it requires lot of customization effort.

Provided in the latest SDK release is the ability to detect whether an entity record has changed on the server in the time between when your application retrieved the record and when it tries to update or delete that record.

The ConcurrencyBehavior Property specifies the type of optimistic concurrency behavior that should be performed by the Web service when processing this request:

Member name Description
AlwaysOverwrite Specifies the behavior where an update or delete operation is applied without regard to the version of the record in the database. Value = 2.If optimistic concurrency is not enabled for the target entity, the AlwaysOverwrite behavior is applied.
Default Specifies to use the default behavior. Value = 0. The default value is also used if no value is set in the ConcurrencyBehavior property of the request. The meaning of “default” is interpreted differently based on the calling context.
IfRowVersionMatches Specifies the behavior where an update or delete operation is only applied if the entity record in the database has the same row version as the entity or entity reference in the request. Value = 1.If no row version value is provided on the entity or entity references in the request, the request fails immediately.

The following sample code from SDK shows how to use optimistic concurrency for update and delete operations. The complete sample can be downloaded from MSDN: https://code.msdn.microsoft.com/Use-optimistic-concurrency-e0b0440d.

using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials))
{
CreateRequiredRecords();
// Retrieve an account.
var account = _serviceProxy.Retrieve(“account”, _accountId, new ColumnSet(“name”,”creditlimit”));
Console.WriteLine(“\tThe row version of the created account is {0}”, account.RowVersion);

if (account != null)
{
// Create an in-memory account object from the retrieved account.
Entity updatedAccount = new Entity()
{
LogicalName = account.LogicalName,
Id = account.Id,
RowVersion = account.RowVersion
};

// Update just the credit limit.
updatedAccount[“creditlimit”] = new Money(1000000);
// Set the request’s concurrency behavour to check for a row version match
UpdateRequest accountUpdate = new UpdateRequest()
{
Target = updatedAccount,
ConcurrencyBehavior = ConcurrencyBehavior.IfRowVersionMatches
};
// Do the update.
UpdateResponse accountUpdateResponse = (UpdateResponse) _serviceProxy.Execute(accountUpdate);
Console.WriteLine(“Account ‘{0}’ updated with a credit limit of {1}.”, account[“name”],((Money)updatedAccount[“creditlimit”]).Value);
account = _serviceProxy.Retrieve(“account”, updatedAccount.Id, new ColumnSet());
Console.WriteLine(“\tThe row version of the updated account is {0}”, account.RowVersion);
_accountRowVersion = account.RowVersion;
}
DeleteRequiredRecords(promptforDelete);
}

Hopefully you find it useful!
Thank you,
Zhe Chen

Advertisements

Dynamics CRM 2015 – Turn off the Navigation Tour permanently

The Navigation tour was introduced in CRM 2013. It shows up to users each time they access the system and user can select the “Don’t show me this again” check box to turn it off. However this configuration is temporarily stored in user’s local browser cache hence it will re-appear after cleaning up the cache or access the CRM from different device.

crm navigation & settings

crm navigation & settings

 

Now with the latest CRM 2015, system administrator has a way to enable/disable the Navigation Tour page permanently for the whole organization. Following is the definition of this new flag on MSDN:

Set whether users see navigation tour
Display navigation tour to users when they sign in When users start CRM, they’re presented with a welcome screen (navigation tour) that provides a quick overview of CRM. Choose No to disable this tour for all users in your organization.NoteThis feature is available if you’re using CRM Online and you have installed the 2015 Update, or if you’re using CRM 2015.

 

To do that, go to Microsoft Dynamics CRM > Settings > Administration > System settings > General tab. In Set whether users see navigation tour, set the Display navigation tour to users when they sign in to No, as shown below:

The details can be found on https://technet.microsoft.com/en-us/library/dn832123.aspx

crm navigation2

I hope you find it useful!

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

Dynamics CRM 2015 – Interact with the Business Process Flow controls in the form

With Microsoft Dynamics CRM 2015, the Xrm.Page.data.process namespace provides events, methods, and objects to interact with the business process flow data in a form.

This sample demonstrates how to switch to different stage using the new Xrm.Page.data.process methods.

Followings are the API used in the sample code:

getActiveProcess() – retrieve information about the active process

setActiveProcess()- Set different process as the active process.

getActiveStage()- retrieve information about the active stage

setActiveStage() – set a different stage as the active stage.

getActivePath() – get a collection of stages currently in the active path with methods to interact with the stages displayed in the business process flow control.

addOnStageChange(),removeOnStageChange() – add or remove event handlers for the business process flow control.

addOnStageSelected() – add a function as an event handler for the OnStageSelected event so that it will be called when a business process flow stage is selected.

removeOnStageSelected() – remove a function as an event handler for the OnStageSelected event.

moveNext()- move to the next stage

movePrevious()- Moves to the previous stage.

stageObj.getId() – Returns the unique identifier of the stage

stageObj.getName() – Returns the name of the stage

getEnabledProcesses() – retrieve the enabled business process flows that the user can switch to for an entity

 

Followings are the Javascript to demonstrate how to switch the process stage:

//move to new stage by stage name

function moveToStage(newStageName){

 

//get active stage

var activeStage = Xrm.Page.data.process.getActiveStage();

var activeStageName = activeStage.getName();

//get a collection of stages currently in the active path

var activePathCollection = Xrm.Page.data.process.getActivePath();

//Enumerate the stages

activePathCollection.forEach(function (stage, n) {

var name = stage.getName();

//search for specific stage by name

if( (newStageName == name) && (newStageName != activeStageName) ) {

//move to the new stage

Xrm.Page.data.process.setActiveStage(stage.getId() , onSetActiveStage);

}

})

}

 

//This callback function is passed the result to indicate whether the setActiveStage operation succeeded.

function onSetActiveStage(returnStatus){

switch (returnStatus) {

case “success”:

break;

case “crossEntity”:

alert(“crossEntity!”);

break;

case “unreachable”:

alert(“unreachable stage”);

break;

case “invalid”:

alert(“invalid stage”);

break;

}

}

 

//Progresses to the next stage

function moveNext(){

Xrm.Page.data.process.moveNext(onMoveNext);

}

 

//This callback function is passed the result to indicate whether the moveNext operation succeeded.

function onMoveNext(returnStatus){

switch (returnStatus) {

case “success”:

break;

case “crossEntity”:

alert(“crossEntity!”);

break;

case “end”:

alert(“Last stage”);

break;

case “invalid”:

alert(“invalid stage”);

break;

}

}

//Progresses to the next stage

function movePrevious(){

Xrm.Page.data.process.movePrevious(onMovePrevious);

}

 

//This callback function is passed the result to indicate whether the movePrevious operation succeeded.

function onMovePrevious(returnStatus){

switch (returnStatus) {

case “success”:

break;

case “crossEntity”:

alert(“crossEntity!”);

break;

case “beginning”:

alert(“Stage beginning”);

break;

case “invalid”:

alert(“invalid stage”);

break;

}

}

 

// Methods to manage event handlers

// on form load

function registerProcessEvent(){

//add OnStageChange event handlers for the business process flow control.

Xrm.Page.data.process.addOnStageChange(onStageChange);

//add OnStageSelected event handlers for the business process flow control.

Xrm.Page.data.process.addOnStageSelected(onStageSelected);

 

//show current process

retrieveActiveProcess();

 

//show current stage

retrieveActiveStage()

 

}

 

//Retrieve active process

function retrieveActiveProcess(){

//Get active process

var activeProcess = Xrm.Page.data.process.getActiveProcess();

var processName = activeProcess.getName();

var processID = activeProcess.getId();

alert(“Acitve process is ” + processName + ” ID = ” + processID);

}

//Retrieve active stage

function retrieveActiveStage(){

//Get active stage

var activeStage = Xrm.Page.data.process.getActiveStage();

var stageName = activeStage.getName();

var stageID = activeStage.getId();

alert(“Acitve stage is ” + stageName + ” ID = ” + stageID);

}

 

//event handler for Stage Change

function onStageChange(){

alert(“On stage change event”);

}

 

//event handler for Stage Selected

function onStageSelected(){

alert(“On stage Selected event”);

}

 

I hope you find it useful!

 

 

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

CRM 2013 – Workflows – Schedule workflows using ISV Provider North52

We’ve requirement to schedule workflows to run at certain times/dates. The workflows can be created in CRM and then run by a console tool or something by a Windows schedule service.

We have used Windows Service or Scribe Insight to trigger workin some project and it works as expected. Today we will introduce another CRM tool N52 which is highly configurable and easily setup.

Below are the steps to set up the workflow schedule by using N52:

 

1. Download N52 solution from North52 website: http://www.north52.com/business-process-activities/download-solution/

2. Import the N52 solution into CRM:

North 52-1

3. Create an on-demand workflow on account entity which is used to send notification on daily basis:

North 52-CRM-2

4. Create a new N52 Schedule from N52 menu. You can specify the workflow to be executed; Select the frequency, start date time and end date time. The Fetch XML query is required to retrieve the records:

North 52-3

5. Start Schedule:

North 52-4

6. After the workflow is triggered, you can review the running status in N52 Schedule tab:

North 52-5

 

I hope you find it useful!

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

CRM 2013 – Reports – Avoid updating reports on Reporting Server Directly!

Dynamics CRM reporting service supports automatic data Pre–Filtering to

  • Make reports context-sensitive by narrowing the scope of a report to return more relevant data.
  • Retrieve and display a result set faster because only more relevant data is returned.
  • Allow the report to be filtered using the Advanced Find feature.

To enable automatic data pre-filtering on a report, you can alias entity tables in queries by using an alias name that starts with “CRMAF_”.

 

Here is one reference you can take a look at: http://msdn.microsoft.com/en-us/library/bb955092.aspx

 

When CRM administrator deploys the report RDL in Dynamics CRM solution, CRM automatically modifies the uploaded RDL code to add “p1” parameter and modify the query. It works very well and Pre-Filtering will be enabled for this report.

CRM Reports

Figure 1: Uploading RDL in CRM Solution

 

Report Parameters

Figure 2: CRM Automatically added Parameters

 

However sometime report administrator might go to Reporting Server and deploy/modify the RDL on server directly which might cause the CRM automatically added code lost. It’s difficult to troubleshooting the issue until you realize the RDL code was modified by CRM when uploading the report.

To avoid this kind of potential issue in our project, we always deploy and update the custom report through CRM and avoid the direct modification on reporting server.

 

I hope you find it useful!

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

CRM 2013 – Business Process Flow – Disable the fields on process bar

Dynamics CRM 2013 BPFs have many beneficial qualities.  They are available for both OOB and custom entities, can span across multiple entities.

When a form displays a business process flow control in the header, additional controls will be added for each attribute that is displayed in the business process flow. These controls have a unique name like the following: header_process_<attribute name>.

Controls displayed in the form header are accessible and have a unique name like the following: header_<attribute name>.

CRM Process bar

CRM Process bar

We have requirement to disable the fields on process bar based on some logic. Below is the Java Script code to implement it:

var c = Xrm.Page.getControl(“header_process_xxxxxxxx”);  //Get the field from process bar

if (c!= null) {

c.setDisabled(true);

}

CRM Process bar

CRM Process bar

 

I hope you find it useful!

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

CRM 2013 – Business Process Flow – How to hide the ‘Create +’ button on the process bar

Dynamics CRM 2013 BPFs have many beneficial qualities.  They are available for both OOB and custom entities, can span across multiple entities. You can design business process flows that tie together the records for up to five different entities into a single process so that people using CRM can focus on the flow of their process rather than on which entity they are working in. They can more easily navigate between related entity records.

The ‘Create’ button will show up after clicking Next Stage on the process bar allowing user to create the associated record and attach it to the process.

 

Dynamics CRM Process Bar

Dynamics CRM Process Bar

We have business requirement to automatically create one single record (Entity B) associated to Entity A so that user can simply select the created record from the pop up menu. This can be easily implemented by workflow. However the ‘Create+’ button in the pop up menu is always displayed and user might click it by mistake to create one more record.

My solution is to dynamically overwrite the CSS to hide the link dynamically. Following is the details:

Dynamics CRM Process Bar

Dynamics CRM Process Bar

 

JavaScript:

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);

 

}

 

CSS:

/*Hide the ‘Create +’*/

.processNavigateMenu.ui-flyout-dialog .navigateFooterSection .navigateMenuCreate{display:none !important;}

 

I hope you find it useful!

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