I have managed to upload and place an "on change" event using the javascript provided. I get a script error so its more than likely I have entered incorrect information into the code.
I will just extract the relevant table information below to see if I have understood the script and placed the correct values where they should be.
Table - Hire Equipment (Logical Name - pre_hireequipment)
Table Guid - pre_hireequipment_ID
Equipment Name - pre_name (Description of the Hire equipment e.g. 3 tomme dumper truck)
Hire Rate - pre-rate (Hire rate of equipment per day)
Table - Hire Quote
Table GUID - pre_hirequite_ID
Equipment - pre_equipment (Lookup column to the equipment name in the Hire table)
Qty - pre_qty (How many days hire required)
Unit Cost - pre_unitcost (Cost per day - to be populated by script from Hire table)
function onEquipamentChange(executionContext) {
var formContext=executionContext.getFormContext();
var equipamentId=formContext.getAttribute("pre_hireequipment_ID").getValue()[0].Id;
Xrm.WebApi.retrieveMultipleRecords("pre_hireequipment", "?$filter=pre_name eq '" + equipamentId + "'&$select=pre_rate").then((result)=> {
if(result.entities.length > 0) {
var taxRateValue=result.entities[0].fieldTaxRate;
formContext.getAttribute("pre_unitcost").setValue(taxRateValue);
}
})
}
Please advise where I have gone wrong - many thanks.