Skip to main content

Dynamics CRM - Setting the Default View for Fields in the Process Stage Bar

Author by Concurrency Blog

One constraining aspect about having fields live in the process bar, is that you cannot set the default view on the fields as you would on the form. This causes issues with lookup fields needing that filtering to shorten the long list of data that goes with it. Fortunately, there are a few lines of JavaScript that can handle this. The process for writing the code goes as follows; first take in consideration what stage of the process you are on, check if the user is on the correct stage, look to the same field’s view hidden on the form then match it to the process header field. Using this method, you can tweak and update aspects of the code to match the goal you are trying to accomplish.

First get the ID of which stage the record is on:

                var stageid = Xrm.Page.getAttribute("stageid").getValue();

Next, check if that stage is the desired stage; containing the field needing a new default view.

                 if (stageid == '99999999-8b5e-8ee2-2dda-52a22b 457445')

Last, when the if statement is satisfied, read in the view from the hidden field and set it to the header process field.


                var View = Xrm.Page.getControl("new_field").getDefaultView();

                Xrm.Page.getControl("header_process_ new_field ").setDefaultView(View);


Hint: To get the Stage ID for the stage you are on; use the following code to pop up a message box containing this staged number which then can be hardcoded into the JavaScript.

                       var stageid = Xrm.Page.getAttribute("stageid").getValue();                                                       alert(stageID);

 Notes and Details

  1. If you try to run the code within the if statement, without verifying which stage the record is on, you will receive errors because the code cannot see process header fields that are not in the current stage, so you want to make sure the code is only running on the correct stage.
  2. Hide a field on the form by unchecking the visible by default box on that field.
  3. When you add a field to the process bar, it gets the name ‘header_process_fieldname’ where fieldname is the original name of that field.
  4. The 'stepname' field holds a text value for the current process flow stage if you don't want to mess with GUIDs.                                                                                    Xrm.Page.getAttribute('stepname').getValue();



Concurrency Blog

The latest about Concurrency