Hi guys
i have a form with a lookup. I want to autopopulate another field according to the value selected in lookup. i wrote a js to do this at onchange of the lookup field. i was able to get the guid of the lookup field. but i couldnt data from the lookup field table using this guid. i tried using webapi but the result data comes with the length zero. Below is my code:
$(document).ready(function() {
// Get the field that triggers the onchange event
var foodItemLookup = $("#md_fooditem");
var quantity = $("#md_quantity");
// Add an onchange event handler to the field
foodItemLookup.on("change", function() {
// Call the function to set the foodGuid of the other field
setfoodGuidToField();
});
quantity.on("change", function(event) {
// Call the function to set the foodGuid of the other field
setfoodGuidToField();
});
// Function to set the foodGuid of another field
function setfoodGuidToField() {
debugger;
// Get the foodGuid of foodItemLookup
var foodGuid = foodItemLookup[0].value;
var quantityOfFood = quantity.val();
if(foodGuid && quantityOfFood){
var data = function loadRecords() {
return appAjax('Loading...', {
type: "GET",
url: "hungryhubcustomerportal.powerappsportals.com/_api/md_foods("+ foodGuid +")?$select=md_price",
contentType: "application/json"
});
}
var fdprice = data.name;
var total = quantityOfFood * fdprice;
$("#md_price").val(total);
}
else{
$("#md_price").val("");
}
}
});
can anyone help me with this?