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);
var stageid = Xrm.Page.getAttribute("stageid").getValue(); alert(stageID);
Notes and Details
- 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.
- Hide a field on the form by unchecking the visible by default box on that field.
- 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.
- 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();