0Day Forums
Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: JScript (https://0day.red/Forum-JScript)
+--- Thread: Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript (/Thread-Accessing-Other-Entities-Attributes-in-Dynamics-CRM-365-Forms-with-javaScript)



Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript - bowe314 - 07-24-2023

This function `buttonBuzz()` works inside the Forms of the Entities Account, Contacts and Leads. But not in the Opportunity form.
Mainly because there is no `telephone1` attribute. There is however a Contact entity added with "Quick View" in a section with a telephonenumber inside.

[![View of the Opportunity Form w/ Contact Quick View marked in red][1]][1]

I think it can be accessed with the `telephone1` as well just not with `Xrm.page`

**Any ideas how i can grab the attribute from inside the "quick view"?**

I dont know if the "Quick view" window is a form of an iFrame. And if it is i have no clue how to access it with the `Xrm.Page.getAttribute("telephone1").getValue();`

function buttonBuzz(exObj) {
var phoneNumber;

// Here i store the "telephone1" Attribute from the current .page
phoneNumber = Xrm.Page.getAttribute("telephone1").getValue();

if (phoneNumber != null) { **Sends phonenumber** } ...




[1]:



RE: Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript - generate553 - 07-24-2023

Quick Views display data from a record selected in a lookup field, in this case a Contact. You can query data from related records using the OData endpoint.

You first need to get the Guid of the record selected:

var contactId = Xrm.Page.getAttribute("parentcontactid")[0].id || null;

You would then need to send a [SDK.REST][1] request, passing parameters for the Id of the record (`contactId`), `entityName` and the `columns`:

var entityName = "Contact";
var columns = "Address1_Telephone1, FirstName, LastName";

SDK.REST.retrieveRecord(contactId, entityName, columns, null, function(result) {
// Success, logic goes here.
var address1_Telephone1 = result.Address1_Telephone1;
}, function(e) {
console.error(e.message);
});


----------


As well as your JavaScript file, you would need to include the SDK.REST.js file that is included in the [MS CRM SDK download][2] within your Opportunity form libraries.


[1]:

[To see links please register here]

[2]:

[To see links please register here]




RE: Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript - melonmonger589775 - 07-24-2023

You can pull that field up from the Contact into the Opportunity by creating a Calculated Field, setting it equal to `parentcontactid.telephone1`

Put the field on the form, and you'll be able to `.getAttribute()` it like any other Opportunity field (being Calculated, it updates itself whenever the source changes).