Fun with JavaScript
In this post we pick some of the examples of JavaScript
Part 1 : Working with aliased value (getting attributes value from Link Entity) in JavaScript.
Most often we find that the content available on the web, concentrate on how to retrieve the aliased value in C# . Below is an easy way to get the aliased value in JavaScript.
For example : Fetch Xml is
<fetch version=”1.0″ output-format=”xml-platform” mapping=”logical” distinct=”false”>
<entity name=”pcl_EntityA”>
<attribute name=”pcl_fieldA” />
<order attribute=”pcl_fieldA” descending=”true” />
<link-entity name=”pcl_EntityB” from=”pcl_EntityBid” to=”pcl_fieldBonEntityA” visible=”false” link-type=”outer” alias=”AB”>
<attribute name=”pcl_fieldB” />
</link-entity>
</entity>
</fetch>
Conventionally to get the value of field A : collection[0].attributes. pcl_EntityA.value;
To get the value of the field B from the Link Entity B : collection[0].attributes[‘AB. pcl_fieldB’].value;
Part 2 : Registering a JavaScript function on all CRM Entities
Usually we can register a plugin on all CRM entities but do you know we can also register JavaScript function on all CRM entities?
For example: Suppose there is a used case scenario where there is bulk update of records, which will take up considerable amount of time to complete. Now in an ideal situation, one wouldn’t want the user to wait till it completes and prompt the user once it’s done in which ever entity he currently is working on. For this the following steps can be followed:
1. Add the Application Ribbon to the solution and open the solution in the Ribbon Workbench.
2. Select a button which will be common on the required or all entities For example: New Button.
3. Add a new Custom Enable Rule and further add your logic to it and return true by default to enable the function.
4. Enable rule of a function fires on load of the form so the function gets called each time on load.
The post has been written by Chetan Khandelwal