web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Hide Form on Next Stage of a Business Process Flow

(0) ShareShare
ReportReport
Posted on by

Hi All,

I want to show / hide fields when Business process flow takes user to the next stage. Whats the best way to implement this ?

Should i use different forms and just switch them on next stage or JavaScript .. Any ideas please, not done this before

Thanks,

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Ncube

    You can use below code for hiding/showing the field on the change of BPF.

    function OnLoad() {

     // *** Whenever the stage changes trigger an onchange function

     Xrm.Page.data.process.addOnStageChange(stageOnChange);

     // To remove the function if required ….. Xrm.Page.data.process.removeOnStageChange(stageOnChange);

     // *** Whenever a stage is selected trigger a function

     Xrm.Page.data.process.addOnStageSelected(stageSelected);

     // To remove the function is required …. Xrm.Page.data.process.removeOnStageSelected(stageSelected);

    }

    function stageOnChange() {

     stage = Xrm.Page.data.process.getActiveStage();

     Xrm.Page.getControl('fieldname1').setVisible(true);

     Xrm.Page.getControl('fieldname2').setVisible(false);

    }

    function stageSelected() {

     stage = Xrm.Page.data.process.getSelectedStage();

     Xrm.Page.getControl('fieldname1').setVisible(true);

     Xrm.Page.getControl('fieldname2').setVisible(false);

    }

    If you find it helpful,Please mark my answer as verified.

    Best Regards,

    Shahbaaz

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    You can implement this using JavaScript method. Here is the code you only need to replace field Id and register "AttachProcessStageChange" function on load  event of your form. Here is the code

    //You need to register the function  AttachProcessStageChange on load of the form
    function AttachProcessStageChange() {
        Xrm.Page.data.process.addOnStageChange(StageChangeAction);
        Xrm.Page.data.process.addOnStageSelected(StageSelectedAction);
    }
    
    function StageChangeAction() {
        //This is for on change
    }
    //This function will fire at the time of stage selection
    function StageSelectedAction() {
        var stageName = Xrm.Page.data.process.getSelectedStage().getName().toString().toLowerCase(); //Return stage name  
        //var stageID = Xrm.Page.data.process.getSelectedStage().getId().toString().toLowerCase(); //  Stage Id will return GUID You can also do a check with the ID as well
        if (stageName = "Qualify Lead") {
    
            Xrm.Page.getControl("fieldId").setDisabled(true);  //Replace fieldId everywhere , this will hide form field
            Xrm.Page.getAttribute("fieldId").setSubmitMode("always"); //Replace fieldId
    
            if (Xrm.Page.ui.controls.get("header_process_fieldId") != null) { //Replace fieldId only
                Xrm.Page.getControl("header_process_fieldId").setDisabled(true);  //Add prefix "header_process_" with your field name to get the BPF field. 
            }
        }
    }
    


    Hope this helps.

  • Jay2014 Profile Picture
    on at

    Thank you both, I will look into your suggested solutions

  • Shahbaaz Ansari Profile Picture
    6,211 on at

    And don't forget to mark answer Verified if it resolves your issue.

    Best regards,

    Shahbaaz

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans