Hi all ,
I have create a customer powerapps portal and I want set , with a default value , the field subject .
The Subject is a lookup field type . I create a basic form metadata , but the field not populated !
How I do it ?
Thanks
Solved! Go to Solution.
Hey Eagle,
Unfortunately you cannot set a lookup field in the "Prepopulate" area of the metadata record.
This is due to the fact that a lookup field is broken into 3 parts - ID, Name, and EntityType.
You will have to write Javascript to prepopulate the field on-load. In order to do this, you should be able to locate the Custom Javascript section on the Entity Form/Web Form itself (or web page depending on requirement) and add something in the following format:
$(document).ready(function(){
$("#" + Schema + "_name").val(Name);
$("#" + Schema).val(GUID);
$("#" + Schema + "_entityname").val(EntityName);
});
You will need to populate the Name of the record into the name field, the GUID of the record, as well as the entity name (schema name).
The easiest route is to pass these as parameters in your form request url and retrieve them in javascript. If that isn't an option, you can always hard-code them in, or use a FetchXml block in a web template to retrieve the associated record to populate.
If you need further clarification let me know!
Thanks!
Matt Bayes
Hi @Eagle0473
Are you using Basic Form or Advanced Forms?
Can you please let us know that subject lookup field is reference to which entity?
Please refer this blog:
Hey Eagle,
Unfortunately you cannot set a lookup field in the "Prepopulate" area of the metadata record.
This is due to the fact that a lookup field is broken into 3 parts - ID, Name, and EntityType.
You will have to write Javascript to prepopulate the field on-load. In order to do this, you should be able to locate the Custom Javascript section on the Entity Form/Web Form itself (or web page depending on requirement) and add something in the following format:
$(document).ready(function(){
$("#" + Schema + "_name").val(Name);
$("#" + Schema).val(GUID);
$("#" + Schema + "_entityname").val(EntityName);
});
You will need to populate the Name of the record into the name field, the GUID of the record, as well as the entity name (schema name).
The easiest route is to pass these as parameters in your form request url and retrieve them in javascript. If that isn't an option, you can always hard-code them in, or use a FetchXml block in a web template to retrieve the associated record to populate.
If you need further clarification let me know!
Thanks!
Matt Bayes
Hi Matt , thank for replay .
I insert this script in this position of the web form ?
Hi , thank you for replay .
I tryed this solution , but unfortunetly for subject field not work
You need to insert the script on the portal basic form JavaScript not as per your screenshot.
Another alternative is to use Web api as per the below article:
https://imperiumdynamics.com/blog/Populating-a-lookup-on-Power-App-Portals