Hi,
I am create model driven app and have two tables name as “Equipment” and “Equipment Order”.
Equipment table contain equipment, equipmentType, description, price etc.
Equipment Order table contain orderRef, equipment (lookup field), equipmentType etc.
My scenario is,
→Equipment Order; when I select equipment(lookup) then auto filled with its equipmentType value. How could I do this in model driven app using JavaScript?
I appreciate your kind support.
Thank you
#modeldrivenapp #powerapps
Hi @ryanspain ,
I have a similar problem I’m trying to solve, I think your solution might work for me too but I’m not sure. I’d really appreciate it if you could take a look
thanks
Hi @ryanspain
I have managed to add your code, however I am getting "web resource method does not exist" error. I have changed the field names accordingly and added to the form library and configured the event handler.
Hi @ShriniA
Have you got solution for your issue?
Hey @ShriniA,
I'm assuming that, when a user fills in the Equipment lookup on the new Equipment Order form, you want to simply map the Equipment Type from that selected Equipment to the new Equipment Order.
If my assumption is correct, you need to do a couple of things in your onEquipmentChanged JavaScript method. I've copied a code sample below with some inline comments explaining what is being done.
function onEquipmentChanged(executionContext){
// get the form context from the execution context
var formContext = executionContext.getFormContext();
// get the selected Equipment records Equipment Type using the Web API
var selectedEquipmentRef = formContext.getAttribute("equipment_field_name").getValue()[0];
var selectedEquipment = await Xrm.WebApi.retrieveRecord(
selectedEquipmentRef.entityType,
selectedEquipmentRef.id,
"?$select=equipment_type_field_name");
var selectedEquipmentType = selectedEquipment.equipment_type_field_name;
// set the Equipment Type field on the form
formContext.getAttribute("equipment_field_name").setValue(selectedEquipmentType);
}
The documentation pages I used to remember/verify the syntax were:
Take note that you'll need to replace the reference to the field names that I put in like equipment_type_field_name and equipment_field_name.
Hope this helped!
In Equipment table, equipmentType is a choice field. When I call it in Equipment Order table, I create equipmentType as a lookup field. Is that correct or what kind of field that I want to create it on Equipment Order table?
Ex:
function onEquipmentChanged(executionContext){
var formContext = executionContext.getFormContext();
formContext.getAttribute(“equipmenttype”).setValue();
}
Hey @ShriniA,
You can achieve this in a model-driven Power App using the below high-level steps:
Give it a shot!
Ryan