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.

CRM 2011/2013 – use the debugger console to enabled/disable controls on a form

I was trying to fix a small bug but I was getting bogged down with the business logic (which I didn’t need/want to change) on the form.

The problem was there was lots of business logic which kept disabling the fields I wanted to change.

I tried briefly to understand the business logic but it was complex and detailed and I wasn’t really interested in understanding the form logic and/or briefly amending the JavaScript onload.  All I needed to do was to enable an optionset on the form, which would enable a ribbon button.

So it’s time for a bit of off the cuff hacking

I loaded the form

Press F12 to bring up the debugger window

You can use the console to manipulate the fields and enable/disable certain fields.

You have access to the CRM JavasScript objects

So I used the Xrm.Page, selected the control (not the field attribute) and did a setDisabled(false); which enables the control.
Xrm.Page.getControl(customerid”).setDisabled(false);
This didn’t enable the ribbon button because although the JavaScript function which is used by the ribbon button (e.g. the enable rule for the Ribbon button) the ribbon hadn’t been refreshed.

So I used the console to do a Ribbon Refresh

Xrm.Page.ui.refreshRibbon();

Fantastic, now my field was enabled and the ribbon button was enabled and ready to be pressed.

 

Other uses for F12 JavaScript debugger is to get the guid of the record, which I did on this blog post

 

Browser bookmark

An alternative to bringing up the F12 debugger is to create a bookmark, this will enable you to pass javascript into a form before loading it.

The blog post below created a God Button, which enables all fields

http://www.magnetismsolutions.com/blog/paulnieuwelaar/2014/07/29/activate-god-mode-in-crm-2013—don-t-let-your-users-see-this

 

This blog post will talk you through the logic and is the first part in a series of blog posts on the subject

http://blog.sonomapartners.com/2014/01/crm-2013-javascript-bookmark-series-part-1.html