Javascript in CRM 2011

Disclaimer: New for JavaScript

Form : MyForm

Fields :

ntt_name ntt_lookup1 ntt_lookup2 

Demand

Read the value of ntt_lookup1 and ntt_lookup2 and get the name (not the identifier) ​​and combine them and fill it in the name field (primary attribute).

I load this as a web resource, bind it to the MyForm form and add it to the onsave event.

I get the following error.

enter image description here

Question : What am I doing wrong?

What i have done so far :

  • A Google search error occured and found this question . Thus, double is checked for missing parentheses, using both Notepad ++ and manually tracking it manually.

Code

 if (typeof(CRMDynamics2011) == "undefined") { CRMDynamics2011 = {}; } CRMDynamics2011.MyForm = { FormSave: function() { alert("Within Function FormSave"); var lookup1 = Xrm.Page.getAttribute("ntt_lookup1").getValue(); var lookup2 = Xrm.Page.getAttribute("ntt_lookup2").getValue(); if (lookup1 != null && lookup1[0] && lookup1[0].name != null) { alert("lookup1 is NOT NULL"); var value1 = lookup1[0].name; } if (lookup2 != null && lookup2[0] && lookup2[0].name != null) { alert("lookup2 is NOT NULL"); var value2 = lookup2[0].name; } var fieldName = Xrm.Page.getAttribute("ntt_name"); fieldName.setValue(value1 + ' - ' + value2); } }; 
+4
source share
1 answer

Since you are using a namespace, you must fully qualify the method you want to call.

Thus, in the form properties for CRM for the OnSave event,

 CRMDynamics2011.MyForm.FormSave(); 

Then CRM should call your method when you click "Save."

+3
source

Source: https://habr.com/ru/post/1468938/


All Articles