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

Announcements

News and Announcements icon
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

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

I have the same question (0)
  • AXTechie2120 Profile Picture
    568 on at

    Hi,

    You can set your field as required in the BPF itself like the below screenshot.

    pastedimage1566478668915v1.png

    by marking it as required in the Business Process itself.

    Please mark it as verified it found useful and let me know for any further queries.

    Regards,

    AxTechie2120

  • Community Member Profile Picture
    on at

    @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.

  • AXTechie2120 Profile Picture
    568 on at

    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
  • AXTechie2120 Profile Picture
    568 on at

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

    Can you explain a bit?

  • Community Member Profile Picture
    on at

    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
    568 on at

    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."

  • AXTechie2120 Profile Picture
    568 on at

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

    and how you want the values to be filled up.

  • Community Member Profile Picture
    on at

    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
    568 on at

    alright try this

    www.inogic.com/.../

    it might help you.

  • Suggested answer
    Mohammad Faheemuddin Profile Picture
    5 on at

    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

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans