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)

Set BPF Fields Required/Not Required using javascript

(0) ShareShare
ReportReport
Posted on by 440

In Version 9, can we set the Required status of a field in the Business Process Flow with either a javascript or workflow?

I have a customer with a complex BPF and adding branching would make it unworkable.

Thanks

Simon

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi ,

    you can achieve it via JS. Follow the below post on how to write JS with BPF.

    community.dynamics.com/.../how-to-apply-script-on-header-fields-and-bpf-fields

  • Simon Staniforth Profile Picture
    440 on at

    Thanks for this.  When I try this I get an error:

    TypeError: Object doesn't support property or method 'setRequiredLevel'

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    in my environment, it does not work anymore. It seems the newer version of CRM cannot support this method over BPF anymore.

    community.dynamics.com/.../make-the-business-process-flow-fields-to-be-required-conditionally

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

     Xrm.Page.getControl("header_process_description").getAttribute().setRequiredLevel("required");

    this is the code i used, and it worked.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    You can try this.

    var businessPhone = Xrm.Page.getControl("header_process_telephone1").getAttribute().getValue();

    businessPhone.setRequiredLevel("required");

    Hope it helps,

    Thanks

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    you also need to take care of the ID, if same field used in BPF more than one time, the schema name is a bit different . so always make sure you use F12 to see the schema name

    7673.10.png

    3326.8.png

    3857.7.png7673.10.png

  • Simon Staniforth Profile Picture
    440 on at

    Hey guys, thanks for your help so far.  The client has fields in the BPF that are marked as required.   When I try and set required level to 'none" it doesn't appear to work.

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    if you wish to use JS with BPF ( So far i found setRequiredLevel has this problem) , you have to turn off the required in BPF. All the scenario should handle by JS.

    3404.12.png

    Description is set as required by JS when on load.

    3404.12.png

    after updated budget amount and remove mandatory field.

    3113.13.png

  • L-A Filiatrault Profile Picture
    130 on at

    In a recent 8.2 version project, I struggled with a couple of requirements for a business process flow:

    1) Making a stage-gate step required or not depending on other field values.

    2) The field values involved were necessary in more than one phase of the process, but I didn't want them shown in the BPF ribbon.

    For making a stage-gate step visible and required or not:

    To make the attribute visible or not in the BPF, you need to affect the control.

    To make an attribute required or not in the BPF, you need to affect the attribute.

    For example, I am using the attribute called "new_verifiedapproval" that is a "Two Options" type field that is part of the BPF.

    If in a certain situation, I want that field to appear as required in the BPF:

    Xrm.Page.getControl("header_process_new_verifiedapproval").setVisible(true);

    Xrm.Page.getAttribute("new_verifiedapproval").setRequiredLevel("required");

    The 2nd line of code only works if the attribute is on the entity form.

    If it already is, no worries.

    If it isn't, then add it to your form, in a visible or non-visible state as appropriate to your needs. Since in my example the attribute serves only as a stage-gate, I don't want the user to interact with it anywhere else than in the BPF.

    For affecting a BPF step tied to an attribute that is used more than once in the BPF:

    Again, to make the attribute visible or not in the BPF, you need to affect the control.

    Since the attribute is used more than once in the BPF, that means there are X controls in the BPF for the same attribute.

    The first instance of the control will be called header_process_(attributename).

    The second instance of the control will be called header_process_(attributename)_1.

    The thrid instance of the control will be called header_process_(attributename)_2.

    and so on.

    So if your attribute is used as 3 distinct steps in your BPF for conditions but you want the attribute hidden from the BPF because it will be filled out in the entity form:

    Xrm.Page.getControl("header_process_new_attribute").setVisible(false);
    Xrm.Page.getControl("header_process_new_attribute_1").setVisible(false);
    Xrm.Page.getControl("header_process_new_attribute_2").setVisible(false);
    This was a tricky one since in the form, the rule for multiple instances of a same attribute is attributename, attributename1, attributename2, etc.
    Go figure why the syntax is different for BPF controls.

    Hope this helps!

  • L-A Filiatrault Profile Picture
    130 on at

    An addendum to my previous post.

    The "Required" property on BPF step tied to a "Two Options" attribute has a very specific behavior.

    The "Required" property on a "Two Options" attribute means that the BPF step must be set to "Yes" to pass to next stage or finish the process.

    It's not the same as the "Requirement Level" property of the attribute itself.

    If you remove that property in the BPF and try to manage the requirement level via JavaScript like I described, the step will look like it's required (because of the attribute's requirement level) but the BPF will accept "No" has an answer to move forward or finish the process!

    If you leave the property in the BPF and try to hide the step and turn off the requirement level via JavaScript, the control will be hidden but you will still get a notification that "You have to complete the required steps before you can advance."

    I haven't found any way to manage this properly via JavaScript so instead I did this:

    - Set the step to "Required" in the BPF

    - If in a given situation the step is not required, use JavaScript to hide the step and set it to "Yes" so that it satisfies the "Required" property of the step.

    Hope this helps!

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