Introduction
This article demonstrates how to pass the dynamic value as the parameter to the Web resource from any entity form. This article starts with an introduction of the Web Resource creation. Afterwards, it demonstrates how to map and add event handler for a control in the Entity Form.
Creating a Web Resource
JavaScript function ValidateBaseline given below accepts few parameters (context, isFrmSave), which are passed from an Entity Form, “OnChange” of BaseLine field (“Two Option Set”). The same ValidateBaseLine function is also called in Form OnSave event also. The value of the parameter isFrmSave is set as true in this case.
- function ValidateBaseLine(context, isFrmSave) {
- var saveEvent = context.getEventArgs();
- var result = false;
- var mtdname = Xrm.Page.getAttribute("new_measuretypedetailsname").getValue();
- if (mtdname.length > 0) {
- mtdname = mtdname[0].name
- };
- var mname = Xrm.Page.getAttribute("new_measurename").getValue();
- if (mname.length > 0) {
- mname = mname[0].name
- };
- var pmdname = Xrm.Page.getAttribute("new_name").getValue();
- var isbaseline = Xrm.Page.getAttribute("new_baseline").getValue();
- if (isbaseline) {
- If((pmdname.indexOf(mname) !== -1) || (pmdname.indexOf(mtdname) !== -1)) {
- result true;
- }
- }
- if (result) {
- if (isFrmSave) {
- saveEvent.preventDefault();
- } else {
- return false;
- }
- }
- return true;
- }
- if ('this_is' == /an_example/) {
- of_beautifier();
- } else {
- var a = b ? (c % d) : e[f];
- }
Adding a Web Resource to Custom Solution
Steps for creating custom solutions and adding new Web resources are given below.
Figure 1: Creating custom solution
Select Web resources and click New, as shown below.
Figure 2
Figure 3: Adding web resources to custom solution
Mapping a Web Resource to Entity Form Event
The screenshot given below shows how to add web resources to an Entity Form and map it to Event Handler.
Figure 4
Add all the necessary .js files to form Libraries.
Figure 5
The final output is given below.
Summary
I hope you have learned to pass the values from the Entity form as the parameter to the Web Resource function. Please let me know, if you have any queries regarding this article.