Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Making only BPF field required using JS

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

We have a field that is on the form and on the BPF. I would like to make the field conditionally required in the BPF to move from Stage X to Stage Y.

However, when I use JS to make it required referencing the "header_process" field, the normal field on the form becomes required as well. Meaning that in order to save the record, you have to fill in a value, which I don't want. It should only be necessary to fill it in to go to the next stage.

Is this just a limitation of CRM?

*This post is locked for comments

  • Verified answer
    RE: Making only BPF field required using JS

    Hi Miniso,

    Try below Code,

    // JavaScript source code

    function onLoadfn(executionContext){

       var formContext=executionContext.getFormContext();

       formContext.data.process.addOnStageChange(RestrictStageChange);

    }

    function RestrictStageChange(executionContext) {

       var formContext = executionContext.getFormContext();

       var country = formContext.getAttribute("ita_country").getValue();//field 1

       var priority = formContext.getAttribute("ita_priority").getValue();//field2

       if (country != null) {

           if (priority == null && executionContext.getEventArgs().getDirection()=="Next") {

               formContext.data.process.movePrevious(function () { alert("You Can't move to next stage as the field Priority is empty"); })

    //above steps restricts user from moving to next stage if country is filled and priority is null.

           }

       }

    }

    Mark as verified if you think it answers your query.

    Thanks and Regards,

    Faheem

  • Suggested answer
    RE: Making only BPF field required using JS

    Hi Miniso,

    Try below Code,

    // JavaScript source code

    function onLoadfn(executionContext){

       var formContext=executionContext.getFormContext();

       formContext.data.process.addOnStageChange(RestrictStageChange);

    }

    function RestrictStageChange(executionContext) {

       var formContext = executionContext.getFormContext();

       var country = formContext.getAttribute("ita_country").getValue();//field 1

       var priority = formContext.getAttribute("ita_priority").getValue();//field2

       if (country != null) {

           if (priority == null && executionContext.getEventArgs().getDirection()=="Next") {

               formContext.data.process.movePrevious(function () { alert("You Can't move to next stage as the field Priority is empty"); })

    //above steps restricts user from moving to next stage if country is filled and priority is null.

           }

       }

    }

    Mark as verified if you think it answers your query.

    Thanks and Regards,

    Faheem

  • AXTechie2120 Profile Picture
    AXTechie2120 560 on at
    RE: Making only BPF field required using JS

    alright try this

    www.inogic.com/.../

    it might help you.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Making only BPF field required using JS

    Field A is on the form and in the BPF in stage X.

    I want to make Field A required to move from Stage X to Stage Y, without making Field A on the form required.

    This is a conditional requirement based on Field B. Not sure if I can make it more clear than that.

    Your code does not help.

    If I do this:

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

    Field A on the form becomes required as well, which I do not want. Only Field A in the BPF should be required.

    This was the entire problem.

  • AXTechie2120 Profile Picture
    AXTechie2120 560 on at
    RE: Making only BPF field required using JS

    You mean you have fieldA in both stages X and Y?

    and how you want the values to be filled up.

  • AXTechie2120 Profile Picture
    AXTechie2120 560 on at
    RE: Making only BPF field required using JS

    try this ,

    upto my understanding

    if (fieldB != null) {

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

    } else if (fieldB == null) {

       Xrm.Page.getAttribute("fieldA").setRequiredLevel("none");

    }

    Please explain these

    "If Field B is filled in, Field A is required to go from Stage X to Stage Y, but not required to save the record itself."

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Making only BPF field required using JS

    Say the field that needs to be conditionally required in the BPF is Field A. The field is also on the form itself.

    We have another field on the form; Field B.

    If Field B is filled in, Field A is required to go from Stage X to Stage Y, but not required to save the record itself.

    If Field B is not filled in, Field A is not required.

    The problem is, people can toggle fill in or clear B whenever they want, so the requirement of A should be able to change without doing a refresh.

  • AXTechie2120 Profile Picture
    AXTechie2120 560 on at
    RE: Making only BPF field required using JS

    Conditionally required means on what basis you want your field in the BPF to be conditionally required?

    Can you explain a bit?

  • AXTechie2120 Profile Picture
    AXTechie2120 560 on at
    RE: Making only BPF field required using JS

    Hi,

    after making the field as required try the  below code for not moving to next bpf if the required field is empty.

    function passonstage() {
    stage = Xrm.Page.data.process.getSelectedStage();
    if (requiredfield == null) {
    var curProcessID = Xrm.Page.data.process.getActiveProcess().getId();
    Xrm.Page.data.process.setActiveProcess("curProcessID", callBackFunction)
    //remain in the same stage
    } else if (requiredfield != null) {
    //move on to the next stage
    }
    }

    function callBackFunction(result) {
    if (result == "success") {} else {}
    }
    Please try the above and let me know.
    mark it as verified if found useful.
    Regards,
    AxTechie2120
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Making only BPF field required using JS

    @AXTechie2120, I have made some words bold in my original post to make it more clear. I need it to be conditionally required. This means your option won't work as it will always be required.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans