11/11/2016 - 12:00 PM

apply script on Header fields and BPF fields

apply script on Header fields and BPF fields

//CRM 2013 now allows java script coding on header fields as well as BPF fields. Sometimes we come across with the requirement where we need to write script on the fields existing in the business process flow and not on the form. Same with the fields on header of any form.
//When a form displays a business process flow control in the header, additional controls gets added for each attribute that is been displayed in that BPF. These controls hold unique names like: header_process_<attribute name>. So using this control we can write script around these fields.
//The Controls displayed in the form header are also accessible and hold unique name like: header_<attribute name>.
//We can perform all those operations that we can perform on the attribute added on the form. Below we have mentioned some of the sample scripts around such fields.
//Show/Hide field
//We can also show/hide the fields from the BPF same like we do for the other form attributes. Below we have hidden the field based on the value selected on the form.

//We can simply use below line of code to show/hide the field from the BPF.


//You can use below line of code to show/hide the field from the Header.


 = function() {
  var parentFieldName = "ad_componentlevel1";
  var lookupFieldName = "ad_componentlevel2";
  lookupFieldName = "header_process_" + lookupFieldName;
  parentFieldName = "header_process_" + parentFieldName;
  //Check if the control exist on the form
  if (Xrm.Page.getControl(lookupFieldName) != null) {
  	//clear value
  // add the event handler for PreSearch Event
    function() {
		var lookupId = null;
		var lookup;
		try {			
			//Check if control exist on form		
			if (Xrm.Page.getControl(parentFieldName) != null && Xrm.Page.getControl(parentFieldName).getAttribute().getValue() != null) {		
				//Get lookup value			
				lookup = Xrm.Page.getControl(parentFieldName).getAttribute().getValue();
				//Get the id				
				lookupId = lookup[0].id;			

			//Build fetch		
			if (lookupId !== null || lookupId !== undefined) {		
				var fetchQuery = [
						"<condition attribute='ad_componentgroupid' operator='eq' value='" + lookupId + "' />",
				//add custom filter			
		catch (e) {			
			Xrm.Utility.alertDialog("addFilter Error: " + (e.description || e.message));			
}; = function() {
	var parentFieldName = "ad_componentlevel1";
	bpf_parentFieldName = "header_process_" + parentFieldName;
	if (Xrm.Page.getAttribute(parentFieldName) && Xrm.Page.getControl(bpf_parentFieldName)) { 
		var componentGroupViewId = "01FFA784-0EA8-E611-80BE-00155DFCDF39"; //Component Group View