RE: Javascript to get parentid on customeraddress
Hi Ben,
What is "the parentid field"?
If you want to retrieve fields data of parent record(lookup as per my understanding), you could run Xrm.WebAPI request at OnLoad event of the form to query the parent record.
var parentEntity = formContext.getAttribute('parent_fieldid').getValue()[0];
var parentEntityId = parentEntity.id.replace(/\{|\}/gi, "").toLowerCase();
var parentEntityName = parentEntity.entityType;
var filter = "";
Xrm.WebApi.retrieveRecord(parentEntityName, parentEntityId, filter).then(
function success(result) {
console.log(result);
},
function (error) {
console.log(error.message);
}
);
If "the parentid field" is a field of current entity and is not able to be added to form, you could also run Xrm.WebAPI request to get its value directly.
var id = formContext.data.entity.getId().replace(/\{|\}/gi, "").toLowerCase();
var etn = formContext.data.entity.getEntityName();
Xrm.WebApi.retrieveRecord(etn, id).then(
function success(result) {
console.log(result);
},
function (error) {
console.log(error.message);
}
);