Showing posts with label Business Process Flow. Show all posts
Showing posts with label Business Process Flow. Show all posts

Thursday, September 3, 2015

Filtering Lookup Attributes in Business Process Flows

I know that this has been posted elsewhere on the Interwebs, but now I can't find the original article, so here goes...

You can, in fact, apply JavaScript to attributes appearing in the Form Header and Business Process Flow display in CRM 2013/2015.

The attributes are not addressed as normal, but with header_ tag for attributes in the Header section, and header_process_ prefix for elements in the Business Process Flow section.

So if we had an attribute that existed in the Business Process Flow of the Incident form, called:

new_caseaccountid

we would address that element in Javascript with:

Xrm.Page.getControl("header_process_new_caseaccountid")

One of the things that we might want to do is to filter the lookup values for another field, (say, Case Contact) based on the value in the Case Account attribute. That being the case, we can attach an event handler to the 'Pre Search' event on the lookup attribute:

1:  if (Xrm.Page.getControl("header_process_new_casecontactid") != null) {  
2:    Xrm.Page.getControl("header_process_new_casecontactid").addPreSearch(addFilter);  
3:  }  

We can define addFilter as:

1:  function addFilter() {  
2:    var accountId = null;  
3:    var accountLookup;  
4:    var fetchQuery;  
5:    try {  
6:      if (Xrm.Page.getControl("header_process_new_caseaccountid") != null &&   
7:        Xrm.Page.getControl("header_process_new_caseaccountid").getAttribute().getValue() != null) {  
8:        accountLookup = Xrm.Page.getControl("header_process_new_caseaccountid").getAttribute().getValue();  
9:        accountId = accountLookup[0].id;  
10:      }  
11:      if (accountId != null || accountId != undefined) {  
12:        fetchQuery = "<filter type='and'>" +  
13:        "<condition attribute='statecode' operator='eq' value='0' />" +  
14:        "<condition attribute='parentcustomerid' operator='eq' value='" + accountId + "' />" +  
15:        "</filter>";  
16:        Xrm.Page.getControl("header_process_new_casecontactid").addCustomFilter(fetchQuery);  
17:      }  
18:    } catch (e) {  
19:      Xrm.Utility.alertDialog("addFilter Error: " + (e.description || e.message));  
20:    }  
21:  }  

Now we have a search filter on the Contact Case element on the Business Process Flow:

Found it!! The original article is here: http://inogic.com/blog/2014/07/how-to-apply-script-on-header-fields-and-bpf-fields/

Thursday, October 2, 2014

Manipulating Business Process Flow Fields with Business Rules

This is a re-post from a colleague - credit must go to Martin Miller at OA Systems for this sage piece of advice...

2013 Business Process Flows can contain fields as part of the definition.

By default, these are unlocked which may not be what you intend, especially if you want to maintain required fields by workflow or other process.

For example, you have a flag maintained by process 'All actions complete'. The Business Process Flow definition does not allow you to set the field read only or locked.

The solution is to use a Business Rule to lock the field. This will fire and will set the attribute of the field in the Business Process Flow ribbon, regardless of whether the field is elsewhere on the form.

You can also use a Business Rule to set the field value.