Thanks for the quick reply.
So I have the JS code, but it is not running as it should. My entity which has the quick create form is Time Entry, the two entities I am working with is Account and Contract - both are individual entities and also exist in Time Entry entity as fields which look up to the main entities. Below is the schema name for all:
Account Entity: account
Field name in Account entity for name: name
Contract Entity: msdyn_project
Field name in Contract entity for name: msdyn_subject
Name of Account and Contract fields in Time Entry entity (where the quickcreate form is)
Account: new_account
Contract: msdyn_project
I will again point out that what I am looking to achieve is that in the quickcreate form, when the account is chosen (looked up to account entity), then the subsequent contract should be populated. Below is my JS Code. Can you please help me out with the Xrm.WebApi.retrieveMultipleRecords(....... and see if the rest of it is correct.
function new_populateContract(executionContext) {
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("new_account").getValue() !== null) {
// Get account id
var accountId = formContext.getAttribute("new_account").getValue()[0].id;
accountId = accountId.replace(/\{|\}/gi, "").toLowerCase();
// Retrieve associated contract of account
Xrm.WebApi.retrieveMultipleRecords("msdyn_project", "?$select=??????????).then(
function success(result) {
if (result.entities.length > 0) {
for (var i = 0; i < result.entities.length; i++) {
formContext.getAttribute("msdyn_project").setValue(result.entities[i]);
}
}
else {
// Clear contract field if no contract is associated with account
formContext.getAttribute("msdyn_project").setValue("");
}
},
function (error) {
console.log(error.message);
}
);
} else {
// Clear contract field if account is set to be null
formContext.getAttribute("msdyn_project").setValue("");
}
}