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 :
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,216 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
    703 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
    703 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

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans