Are you still including unnecessary fields on your Dynamics 365 forms so that your scripts can access it? May be it’s time to use Attribute dependency feature of webresources.

Sometimes we are so much busy in our day to day consulting stuffs that we frequently miss those small little gems in Dynamics 365 which are scattered throughout but we tend to ignore them more often than not.

And one of them is the Attribute dependency feature in webresources.

Advertisements

How many of you faced a situation where you needed to just put an attribute on the form so that the code inside your form events and field events can access the field to get its value and take logical decisions depending on the field value? And attribute dependencies just helps you to get around it. But trust me, still in 95% of the cases where a requirement like this arises, we go ahead and put the field on the form and hide it so that our scripts can access it. Now that you understand, let’s see how it is done.

We will use account entity attribute “industrycode” of type optionset as dependent attribute to the web resource which is being referred in the form load of account entity.

Create a web resource and go to Dependencies tab. Click Add to choose your entity and fields

Advertisements
clip_image002[4]

Select Account entity and choose your dependent fields from the available fields

clip_image004[4]

Now save and publish the web resource. I have added the lookup field, parentaccountid as well as dependency

Advertisements

Note: Make sure you save & publish your web resource to establish the configured dependencies. It’s very important to first click on Save and then publish to reflect the changes.

Open the Account entity form make sure the “Industry” field is not there on the form. All our customizations are in place and let’s see what magic we can see now

Open any existing account record. I will use Developer Tools window to test this.

P.S – I am using the deprecated Xrm.Page here since I am demoing it in developer tools window. For real scenarios, use the formContext to access your controls and attributes.

Let us now verify whether the industry control is available on the form. To do that just type this command “Xrm.Page.getControl(“industrycode”)”.

clip_image006[4]

The control is unavailable which makes sense but the great thing is that we can still get the value of the industry field. To get the value of field just type following commands

Advertisements

Value : Xrm.Page.getAttribute(“industrycode”).getValue()

Text: Xrm.Page.getAttribute(“industrycode”).getText()

clip_image008[4]

Not only this, you can even set the value and save the record.

In this way we can set value of fields which are not placed on the form. And also use their value to arrive at business decisions. Before this feature we would need to add the field on the form and hide the control. The dependent attributes are not limited to single entity, we can even select attributes from multiple entities and attach to web resource and the same webresource can be used in multiple entity form and field events.

Advertisements

So unless you need to work with the control, use Attribute dependency and don’t unnecessarily drag and drop the controls on the form and increase the form clutter.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Notes Manager (https://debajmecrm.com/2019/02/28/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Published by

Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

2 thoughts on “Are you still including unnecessary fields on your Dynamics 365 forms so that your scripts can access it? May be it’s time to use Attribute dependency feature of webresources.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s