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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Show/Hide Business Process Flow on Contact form based on Field value

(0) ShareShare
ReportReport
Posted on by

Hi, 

I have a contact form with a Lead Qualification Business Flow.  I only want this BPF to show when Contact Type = Prospect and Contact Sub-Type = Lead.  For example, if Contact Type = Employee, I would not want this Business Process Flow to show.  

I tried doing this via Workflow to call an Action, but I do not see the "SetProcess" Action step. 

I know this can be done via JScript, but I don't have the code for that.  

If someone knows a way to do this without code, could you let me know?  If not, I would gladly take sample code :)  

Thanks in advance!  

I have the same question (0)
  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi, 

    Please refer to this example:

    function onLoad(executionContext) {
        var formContext = executionContext.getFormContext();
        if (executionContext.getFormContext().ui.getFormType() != 1) {
            formContext.data.addOnLoad(hideProcess);
            formContext.getAttribute('new_contacttype').addOnChange(hideProcess);
        }
    }
    
    function hideProcess(executionContext) {
        var formContext = executionContext.getFormContext();
        var contactType = formContext.getAttribute("new_contacttype").getValue();
        var contactTypeValues = {
            Employee: 700000002,
        }
        if (contactType == contactTypeValues.Employee) {
            formContext.ui.process.setVisible(false);
            formContext.data.process.setStatus("aborted");
        } else {
            formContext.ui.process.setVisible(true);
            formContext.data.process.setStatus("active");
        }
    }
     

    You should then register the "onLoad" function in the onLoad event. Feel free to give more details if you need more guidance, Good Luck !!

  • Chrisbra22 Profile Picture
    on at

    Thank you sir!

  • Inogic Profile Picture
    748 on at

    Hi,

    We cannot set the Business Process Flow through workflow but we can use the “formcontext.data.process.setActiveProcess ()” method within javascript to change the Business Process Flow on the form-based on the field value in Dynamics365 CRM.

    Please find below the sample code for the same.

    Function setBPFProcess(executionContext)
    {
    var formcontext = executioncontext.getFormContext();

    //retrieve the value of Contact Type field and Contact Sub Type
    var contactType = formcontext.getAttribute(ContactType).getValue();
    var contactSubType = formcontext.getAttribute(contactSubType).getValue();

    //validate both field values
    If ( contactType ==Prospect && contactSubType == Lead)
    {

    //set the Business Process Flow
    var processId =”<<Guid of the Business Process flow>>”;
    formcontext.data.process.setActiveProcess(processId);
    }
    }

    Thanks!

  • Chrisbra22 Profile Picture
    on at

    Thanks!  I see that this sets the process, but does it else hide it, if Contact Type = any other value?

  • Chrisbra22 Profile Picture
    on at

    This is the latest code I will implement, onLoad, and on change of msemr_contacttype, aces_contactsubtype

    Function setBPFProcess(executionContext)

    {

       var formcontext = executioncontext.getFormContext();

       //retrieve the value of Contact Type field and Contact Sub Type

       var contactType = formcontext.getAttribute(msemr_contacttype).getValue(602660001);

       var contactSubType = formcontext.getAttribute(aces_contactsubtype).getValue(602660036);

       If ( contactType ==Prospect && contactSubType == Lead)

       {

           //set the Business Process Flow

           var processId ="580e164c-6222-4786-b847-026f8bd4d5bd";

           formcontext.data.process.setActiveProcess(processId);

       formContext.ui.process.setVisible(true);

       } else {

       formContext.ui.process.setVisible(false);

     }

    }

  • Inogic Profile Picture
    748 on at

    Hi,

    We cannot set the Business Process Flow through workflow but we can use the “formcontext.data.process.setActiveProcess ()” method within javascript to change the Business Process Flow on the form-based on the field value in Dynamics365 CRM.

    Please find below the sample code for the same.

    Function setBPFProcess(executionContext)
    {
    var formcontext = executioncontext.getFormContext();

    //retrieve the value of Contact Type field and Contact Sub Type
    var contactType = formcontext.getAttribute(ContactType).getValue();
    var contactSubType = formcontext.getAttribute(contactSubType).getValue();

    //validate both field values
    If ( contactType ==Prospect && contactSubType == Lead)
    {

    //set the Business Process Flow
    var processId =”<<Guid of the Business Process flow>>”;
    formcontext.data.process.setActiveProcess(processId);
    }
    }

    Thanks!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 184 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 125

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans