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
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
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
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.
You mean you have fieldA in both stages X and Y?
and how you want the values to be filled up.
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."
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.
Conditionally required means on what basis you want your field in the BPF to be conditionally required?
Can you explain a bit?
Hi,
after making the field as required try the below code for not moving to next bpf if the required field is empty.
@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.
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
52
Victor Onyebuchi
6