Dynamics CRM - Passing Dynamic Value As Parameter To Web Resource From Entity Form


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. 

  1. function ValidateBaseLine(context, isFrmSave) {  
  2.     var saveEvent = context.getEventArgs();  
  3.     var result = false;  
  4.     var mtdname = Xrm.Page.getAttribute("new_measuretypedetailsname").getValue();  
  5.     if (mtdname.length > 0) {  
  6.         mtdname = mtdname[0].name  
  7.     };  
  8.     var mname = Xrm.Page.getAttribute("new_measurename").getValue();  
  9.     if (mname.length > 0) {  
  10.         mname = mname[0].name  
  11.     };  
  12.     var pmdname = Xrm.Page.getAttribute("new_name").getValue();  
  13.     var isbaseline = Xrm.Page.getAttribute("new_baseline").getValue();  
  14.     if (isbaseline) {  
  15.         If((pmdname.indexOf(mname) !== -1) || (pmdname.indexOf(mtdname) !== -1)) {  
  16.             result true;  
  17.         }  
  18.     }  
  19.     if (result) {  
  20.         if (isFrmSave) {  
  21.             saveEvent.preventDefault();  
  22.         } else {  
  23.             return false;  
  24.         }  
  25.     }  
  26.     return true;  
  27. // This is just a sample script. Paste your real code (javascript or HTML) here.  
  28. if ('this_is' == /an_example/) {  
  29.     of_beautifier();  
  30. else {  
  31.     var a = b ? (c % d) : e[f];  
  32. }   

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.


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.


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now