Need to update a field but don’t want to include it on your form?
Yes, this was really required since the developers wanted to update a field via Javascript which was not really required on the form but they were forced to add the fields to the forms and hide it.
Now it got easier with the introduction of “Attribute Dependency“.
If your JavaScript web resource depends on an entity attribute value that you don’t want to display in the form, you can set the attribute as a dependency for the JavaScript web resource.
This means that the attribute will be available within the client API attributes collection so you can get or set the value in your code. When you add a dependency this way, the controls collection of the attribute will be empty because there will be no control on the form.
Before this feature you would need to manually add the attribute to the form and then configure the control to be hidden. Now you can establish this dependency more directly and eliminate the possibility that someone will remove the hidden field from the form.
Let’s say you have an Opportunity Form and you want to set the value of the “Actual Value” field but don’t want to add on the form.
The Javascript file that you have added is new_/scripts/Opportunity.js
Note: Actual Value field is not present on the Opportunity Form and the field needs to be updated via JavaScript.
Once you have saved the JavaScript webresource and published it, then go ahead to click on the Dependencies tab on the webresource window as shown below:
The first section is for the other webresources dependency. Attribute Dependency needs to be added in the second section as highlighted.
When you click on “+Add” as highlighted, it will open a pop-up window to select the entity and its attributes. For different entities, you need to add different rows of dependencies.
The Good part here is you can select the different attributes of any entity whether it is the same entity that you are working on or any other entity attribute that you wanted to update.
I hope this feature will really help the developers going forward with Dynamics 365 v9.
Enjoy 🙂