Required Dynamics CRM field that appears twice in the form, once hidden once visible

I have a form that has two sections, each with a specific field that is "business required". In my current scenario, the first of these sections is hidden while the second is visible. (Basically which of the two visible is set in JScript and depends on the value of the dropdown).

The problem is that if the user doesn't enter a value for a required field and then deletes save, the form tries to validate it on the first of the two occurrences (i.e., the one that doesn't show up). When it discovers that the user has not completed this value, it then displays a hidden section, even though the same offending field is already being examined further down the form.

Is there a way to stop this, or solve the problem in another way?

Edit:

OK, from the answers below, I think maybe I haven't made the situation clear enough. I don't think setting a field is optional or filling it with a token value will do the trick because I want the required status to be confirmed if the user hasn't filled in the field.

The problem I'm running into is that by confirming it, it will show the user the version of the hidden field, not the one already visible.

Image depicting the scenario.  When the form is validated, the hidden section (shown with red border) appears, because the "Consultant" field is not filled

As far as I know, a simple API to set a required field or not applies equally to any occurrences of that field in a form, not just one specific one.

+3


source to share


4 answers


Edit: ok, this is not very good, but should work.

You can get a set of values ​​with

var bothControls = Xrm.Page.getAttribute('transactioncurrencyid').controls

      

And using



bothControls.get(1)

      

Gives you a second (zero based index, natch) so you can turn it off

bothControls.get(1).setDisabled(true)

      

This means that the check will be skipped.

+4


source


You can change the value of the requirement:



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

      

+1


source


You can make the fields Xrm.Page.getAttribute("field_tonotbe_required").setRequiredLevel("none");

unnecessary using this call But since the field is on the form twice, I'm not sure if the Javscript SDK will make all fields unnecessary or just the first, so you might need to traverse the hierarchy from the section to find the field and then call setRequiredLevel

in the exact field you want to change.

+1


source


Do you consider using a script that will fire on change and populate the entered value from the visible section field to the correspondent of the hidden section?

Suppose the two fields required by the business are named Hubba and Bubba. Connect the JavaScript code so that on change it will check if Hubba is empty (and if so, copy the content of Bubba into it, otherwise it will just copy what is in Hubba into Bubba.

I am assuming that the fields are matched in nature so that you can copy information between them.

I thought of two other options (less optimal IMHO). The first is what Pedro said, augmented by turning the check on and off. Not sure if this will work. I just mentioned it for the sake of completeness.

The second is the application of the process driven user interface from Polaris. Not really sure if this will work, but in theory it should.

0


source







All Articles