CRM 2013 – Investigation into replacing the Assign functionality

I had a small one line change request for a CRM 2013 implementation

Replace Assign functionality with will show users of the current users team.

I thought it would be easy to write a technical specification for this requirement.

First thoughts

Assign form is a special CRM form, I know this cannot be edited or manipulated (in a supported way).

This was much trickier than I initially thought it would be.  As an added bonus finding what users are in a team is not straight forward and you have to use a link entity when you do it in an advanced find.

Here are my thoughts of possibles solutions

Method 1

Create a new form to replace the Assign form.

Work

  • Create ASP page to include a filter lookup to CRM
  • Interact with CRM SDK to retrieve rows and update values
  • Ribbon button change

Pro’s

It would offer the functionality required

Con’s

It would take quite a bit of effort for a seemingly small change

 

Method 2

Open a standard lookup form, calling the lookup form in CRM and filter it

I researched this idea (which I found very difficult to find on the internet)

I go this page

HowTo: Open standard lookup window and get selected record(s)

CRM 2013 Open lookup as dialog in Custom HTML

This method wasn’t suitable because it’s unsupported and I couldn’t see how to filter the lookup.

Method 3

Using a dialog to first return the a list of teams the user is a member.

The user would select a team, press next

This would then return a list of users

Work

Create a dialog

Create custom workflows 1.  retrieve the users team, 2.  Retrieve users in team.

A ribbon button could call the dialog (This can be done using the Ribbon workbench Create a Dialog Short-Cut Ribbon Button)

Pro’s

It should deliver the functionality required

Con’s

Dialog’s are not the quickest

There is still quite a bit of work, two custom workflows and a dialog

 

Method 4

The easiest solution would be to add a user lookup on the form and if the set a value I could trigger a plugin or workflow to assign the records.

The lookup would need be filtered to the team.

I had heard CRM 2013 had prefilters, which allowed you to add filter to a lookup.  When investigating this it turns out you cannot create a filter with a linked entity and can only filter on values which exist on the SystemUser (user) entity.

This excellent blog post

CRM 2013 Using addCustomFilter() to get Filtered Lookup Field based on Linked Entity

Mentions the problem and you can get around it by using the addcustomview but this means you have to create a whole view.

Instead I tried out the functionality in Miss Dynamics CRM blog and use the addCustomFilter()

I thought I would try this out because I had not yet used the AddCustomFilter() solution and this seemed the easiest and quickest

First I created a view in the Advanced find (Why the advanced find is a CRM Developers best friend)

Assign Team problem

 

I then got downloaded the Fetch XML and put it into the FetchXML Builder

Assign Team problem 1

I could then get the guids, Aileen Gusni mentioned some workarounds in her blog to get  AddCustomFilter() to work you could use OData to retrieve the data you needed and


var Hosk = Hosk || { __namespace: true };
Hosk.Functions = Hosk.Functions || { __namespace: true };
Hosk.Functions.HoskTest = Hosk.Functions.HoskTest || { __namespace: true };

; (function () {

this.formLoad = function () {
addEventHandler();

};

function addEventHandler() {
// add the event handler for PreSearch Event
Xrm.Page.getControl("hosk_userassignid").addPreSearch(addFilter);
};

function addFilter() {
//create a filter xml
var filter =
"<filter type='and'>" +
"<condition attribute='systemuserid' operator='in'>" +
"<value>{9fed63fe-c0cc-e411-80c7-000c292122be}</value>" +
"<value>{cba24eea-bacc-e411-80c7-000c292122be}</value>" +
"<value>{2ed69167-0bcf-e411-80c7-000c292122be}</value>" +
"<value>{92c6d456-7bdf-e411-80c8-000c292122be}</value>" +
"</condition>" +
"</filter>";

//add filter
Xrm.Page.getControl("hosk_userassignid").addCustomFilter(filter);
}
}).apply(Hosk.Functions.HoskTest);

The code work, I had filtered the User lookup to those records.

Assign Team problem 2

The filtering kept true even when you clicked look up more records.

The next step I could retrieve the data from an OData call and Dynamically create the line

“<value>{cba24eea-bacc-e411-80c7-000c292122be}</value>” +

Then have a workflow/plugin to assign the records

Work

new field

Javascript change to add filtering

plugin/workflow to assign records.

PRO’s

The quickest solution in time to create and running time

Con’s

It’s different from the current assign button, this may confuse users

The option chosen was….

After spending time thinking about the problem and coming up with some choices the customer decided they didn’t want it.

This is something which happens to developers, one day you can create a change and the next day a customer decides they don’t want it and you have to take it out.

The customer didn’t want the change but I did get to investigate some CRM functionality I hadn’t used yet.

If you have a better solution please leave it in the comments.

Advertisement

Don’t just test the happy path

The original title of this blog post was – Developers should stop being so happy.  I found the old title amusing because over the years I have met some extremely grumpy developers.  Classic old school developers who liked to sit in dark corner and not be disturbed.

The point of this article is grumpy developers can still skip and dance down the happy path when it comes to writing and testing their code.

I am continuing to read Code Complete 2 (it’s over 900 pages long it will take me a while), today I came to an interesting paragraph.

Avoid Failure

Petroski argues that many spectacular bridge failures have occurred because of focusing on previous successes and not adequately considering possible failure modes. He concludes that failures like the Tacoma Narrows bridge could have been avoided if the designers had carefully considered the ways the bridge might fail and not just copied the attributes of other successful designs

 

Developers are too happy

The process of development usually goes

  • Requirements gathered
  • Functional requirement specified
  • Technical requirements specified
  • Code written to deliver requirements
  • Test –> fix bugs cycle

Developers often focus on delivering the functionality, which is often known as following the happy path

Wiki describes as the Happy Path

In the context of software or information modeling, a happy path is a default scenario featuring no exceptional or error conditions, and comprises the sequence of activities executed if everything goes as expected.[1][2] For example, the happy path for a function validating credit card numbers would be where none of the validation rules raise an error, thus letting execution continue successfully to the end, generating a positive response.

 

Focusing on the happy path and creating the required functionality leaves room for bugs in production, when end users stray from the happy path into the alternative path or the exception path.

Developers naturally gravitate towards the happy path, often focusing on happy path testing.  One possible reason for this behaviour is the developer doesn’t see the functionality from the end users point of view, instead the functionality is viewed primarily from the code point of view.

It isn’t obvious to developer why end users would supply different values to what they are expecting, how the end users will use the functionality or what they are trying to achieve using the functionality.

Happy path testing can leave gaps for nulls, incorrect values and a host of error checking/validating errors to slip into a production system because no one has tested these paths.

The other area bugs come in is, is developer under estimate the random actions of end users.

Developers are not good testers

Developers often are poor at testing, this is a badly kept secret of the programming world (developers often dislike testing as well).  Developers are so poor at testing their own code it’s considered good practise to get other people to test the code.

One  reason CRM developers miss bugs in CRM is they test everything using the System Administrator role which avoids many permission bugs, I have written about in this blog

The System Administrator role is a benefit and a curse to CRM developers

Developers are not good at testing because after writing the code it’s difficult to step back and test the functionality rather than test the code.  This is similar to writers editing their own writing, they feel attached to their creation to the extent they find it hard to evaluate it dispassionately.

How to avoid failure

An effective way of avoiding failure is writing unit tests for the code.  The act of writing unit tests make the developer think

  • What should this functionality do e.g. what am I testing
  • What values (min, max) are allowed
  • What alternative values might be presented
  • What should happen when an error happens

Thinking before coding is always beneficial, sometimes developers are eager to get coding they miss this step out.

Once the code is written is unappealing for developers to write unit tests, so the best method of unit testing is to write unit tests while you create the code and use those unit tests to make sure it’s working as expected.

Thinking about errors and failures is very beneficial.  You will capture and avoid many errors.  The developer will decide how to handle errors and its usually a choice

  • Fail fast, abort action
  • continue and warn the user

Errors are not good but code which has blundered on and changed half the values it was expecting can make a greater mess and take longer to clean up, so it’s better to have a plan up front.

Don’t let these often simple errors slip out of your development environment to the end user, make sure you harden your code.

If you don’t write unit tests you should consider doing it

Why CRM Developers should unit test their code

Experiences of Unit testing with Microsoft Dynamics CRM Projects

If you still are not persuaded to write unit tests make sure you go through you code and look for potential errors, validation checks.  Make sure you have decided how you will handle errors in the code.  It’s much better/quicker/easier to manage errors in a dev environment than having to add it in at a later date.

More reading for you

TEST YOUR SAD PATH FIRST

Happy Path Testing

Hosk’s Top CRM Articles of the week – 20th March

Article of the week

turn CRM green

The article of the week showcases the new themes which look awesome.

What’s new for Microsoft Dynamics CRM Online 2015 Update 1

An overview of the new functionality coming in CRM 2015 U1 and if you are not sure why shoul read it then read this – Why you should read the What’s new for developers CRM 2015 SDK 

Best of the Rest

The rest of the article are mainly around the new CRM 2015 highlights and functionality

CRM Online (Carina) API Enhancements Highlights

Tip #346: Scheduling daily bulk delete jobs

This is one of those tips which is good to know because you might need it sometime in the future

Hosk CRM DEV Tip – Always filter your queries

Why you should always filter your queries in CRM.

What’s New with CRM Online (Carina) Highlights

Why all developers should be friends with a cardboard developer

Also known as rubber ducking but this is a method to help you resolve your problems yourself without wasting your fellow CRM Developers precious time

A few interesting things I learnt from the many convergence 2015 tweets

The Hosk’s very brief twitter  highlights from convergence 2015

Release history for the CRM SDK

Interesting I have never seen this document before

get ready for the next release CRM 2015 UR 1

A General overview of the new functionality coming your way

Dynamics CRM 2015 Update 1 SDK assemblies preview (7.1)

You can get the new assemblies quicker if you tick the preview button

http://leontribe.blogspot.de/2015/03/marcs-lemonade-stand-2015.html

CRM MVP Lleon Tribe gives the low down on salesforce using a lemonade stand so everyone can understand

CRM 2015 – resizing the social tab

it is possible to resize the social tab, find out how

CRM 2015 new release has themes

you can change the colour and add a logo

Deploying a CRM2015 solution to CRM2013
Good article on deploying CRM solutions

CRM 2015 roadmap

What changes are coming down the pipe

See what’s new in the CRM2015 Online Update 1 ‘Carina’ SDK

Last Weeks Top CRM Articles

Hosk’s Top CRM Articles of the week – 13th March

Useful Hosk Links

Hosk list Of CRM 2013 Tools

A list and review of CRM 2013 tools, this will probably work in CRM 2015 as well

Hosk’s CRM Developer Articles

A collection of my favourite CRM Developer articles I have written

MB2-703 – CRM 2013 Customization and Configuration Certification Information

All the CRM 2013 content to help you pass the exam

HoskWisdom – Hosk Developer Quotes

 Words of Wisdom from the Hosk.  I have written over 900 articles, surely I should have said a few memorable things