Posted in CRM, JavaScripts

BPF Fields locking and unlockingbased on the stages

Bpf fields locking and unlocking based upon the stages

Scenario:
1. Business Process Flow has three stages, based on the active stage lock the fields which are present in the other 2 stages
2. Also keep one section in the form which will be hidden in the initial stage and visible in other 2 stages.

Stage1 contains new_test1 and  new_test2 fields

Stage2 Contains new_test3 and new_test4 fields

Stage3 Contains new_test5 and new_test6fields

/// Javascript code- Form Onloadevent register two functions

one is main function – bpf  and another state change. function

function bpf()
{
 debugger;
 var activeStage = Xrm.Page.data.process.getActiveStage();
 var stage =activeStage.getName();
 if(stage=="Stage1")
{
 Xrm.Page.getControl("header_process_new_test1").setVisible(true); 
 Xrm.Page.getControl("header_process_new_test2").setVisible(true);
 Xrm.Page.getControl("header_process_new_test1").setDisabled(false); 
 Xrm.Page.getControl("header_process_new_test2").setDisabled(false); 
 Xrm.Page.getControl("header_process_new_test3").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test4").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test5").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test6").setDisabled(true);
 Xrm.Page.ui.tabs.get("hidetab").sections.get("tab_2_section_1").setVisible(false);
 
}
Xrm.Page.data.process.getSelectedStage(stageChange);

Xrm.Page.data.process.addOnStageChange(stageChange);
}
function stageChange()
{
var activeStages = Xrm.Page.data.process.getActiveStage();
var stages = activeStages.getName();
if(stages=="Stage1")
{
 Xrm.Page.getControl("header_process_new_test1").setVisible(true); 
 Xrm.Page.getControl("header_process_new_test2").setVisible(true); 
 Xrm.Page.getControl("header_process_new_test1").setDisabled(false); 
 Xrm.Page.getControl("header_process_new_test2").setDisabled(false);
 Xrm.Page.getControl("header_process_new_test3").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test4").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test5").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test6").setDisabled(true);
 Xrm.Page.ui.tabs.get("hidetab").sections.get("tab_2_section_1").setVisible(false);
 
}
 if(stages=="Stage2")
{

 Xrm.Page.getControl("header_process_new_test1").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test2").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test3").setVisible(true); 
 Xrm.Page.getControl("header_process_new_test4").setVisible(true); 
 Xrm.Page.getControl("header_process_new_test3").setDisabled(false); 
 Xrm.Page.getControl("header_process_new_test4").setDisabled(false);
 Xrm.Page.getControl("header_process_new_test5").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test6").setDisabled(true);
 Xrm.Page.ui.tabs.get("hidetab").sections.get("tab_2_section_1").setVisible(true);
}
 if(stages=="Stage3")
{
 
 
 Xrm.Page.getControl("header_process_new_test1").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test2").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test3").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test4").setDisabled(true);
 Xrm.Page.getControl("header_process_new_test5").setVisible(true); 
 Xrm.Page.getControl("header_process_new_test6").setVisible(true); 
 Xrm.Page.getControl("header_process_new_test5").setDisabled(false); 
 Xrm.Page.getControl("header_process_new_test6").setDisabled(false);
 Xrm.Page.ui.tabs.get("hidetab").sections.get("tab_2_section_1").setVisible(true);
}
}




Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s