I am trying to get a lookup field value and set the value into another field ('Name' field for example) by Javascript in Microsoft Dynamics CRM. How can I do it?
-
What pages??? You want change javascript default in pages? – Mojtaba Nava Oct 06 '18 at 09:09
-
No, I dont want to change default of MS Dynamics CRM. I just want to add new functionality to my form as I save the form, some of fields contents concatenate in name field of form. – babak jafari Oct 06 '18 at 09:14
2 Answers
To use the new (CRM 365) methods you need to do two things:
When you write your form library, your function must include a parameter. This is set by CRM when it calls your function. In my example here, the parameter name is executionContext
but the name does't matter
Once you have this CRM parameter, you can get the Form Context which is the new Xrm.Page
equivalent. See below
function onLoad(executionContext)
{
var formContext = executionContext.getFormContext();
var lookup = formContext.getAttribute("new_account").getValue();
formContext.getAttribute("new_name").setValue("Your Account Name is:" + lookup[0].name);
}
Secondly, when you register your form library, you must pass the Execution Context. This is what tells CRM that your form library method has the executionContext
parameter that must be set

- 6,039
- 3
- 28
- 43
I found it on docs.microsoft. To do this, first you should know about Document Object Model in Dynamics CRM which is called "Xrm":
var lookupValue=Xrm.Page.data.entity.attributes.get('new_account').getValue()[0].name;
Xrm.Page.getAttribute("new_name").setValue("Your Account Name is:"+lookupValue);
You can use it as a function and call it on save (OnSave) event of Microsoft dynamics CRM Form.

- 97
- 1
- 10

- 32
- 1
- 1
- 9
-
1Xrm.Page is deprecated. There are updated ways of retrieving the attribute value; however, your question does not have enough detail. Is this a form library? – jasonscript Oct 08 '18 at 03:46
-
I didn't see anything about deprecation of Xrm.Page, it mentioned in docs.Microsoft as a model. Can you help me about updated ways??? – babak jafari Oct 08 '18 at 05:24
-
3Here is the list of deprecated methods: https://learn.microsoft.com/en-us/dynamics365/get-started/whats-new/customer-engagement/important-changes-coming#some-client-apis-are-deprecated – jasonscript Oct 08 '18 at 08:34
-
-