I have a ribbon button that retrieves data from api for the selected record and then opens the quick create form. How do i autofill this quick create form with the data retrieved from api?
I have a ribbon button that retrieves data from api for the selected record and then opens the quick create form. How do i autofill this quick create form with the data retrieved from api?
Hello,
Yes you can implement using "Xrm.Navigation.openForm" API. Just need some tweaks as per your logic.
First of all you need to have a trigger point because without it you will not able to open the form.
Then as you said you have the data from the API call, use this data and store it in an object and pass it to the "Xrm.Navigation.openForm" API.
This API will open the quick create form and populate the data in that form.
Lets say in below example you can see I have added a button on the account form and when a user will click on this button below JS will be called. This JS will open Contact quick create form and populate the data which I have provided(in your case replace this data with API data).
function setField() { var entityFormOptions = {}; entityFormOptions["entityName"] = "contact"; entityFormOptions["useQuickCreateForm"] = true; // Set default values for the Contact form var formParameters = {}; formParameters["firstname"] = "Sample"; formParameters["lastname"] = "Contact"; formParameters["fullname"] = "Sample Contact"; formParameters["emailaddress1"] = "contact@adventure-works.com"; formParameters["jobtitle"] = "Sr. Marketing Manager"; formParameters["donotemail"] = "1"; formParameters["description"] = "Default values for this record were set programmatically."; // Set lookup column formParameters["preferredsystemuserid"] = "279247f4-b5cd-ec11-a7b5-6045bd002bf6"; // ID of the user. formParameters["preferredsystemuseridname"] = " Admin user"; // Name of the user. formParameters["preferredsystemuseridtype"] = "systemuser"; // Table name. // End of set lookup column // Open the form. Xrm.Navigation.openForm(entityFormOptions, formParameters).then( function (success) { console.log(success); }, function (error) { console.log(error); }); }
Also it will only populate those fields which are present on the form(in my case owner was not present on the form. so it will be not populated but you can refer and check how you can populate the lookup)
docs.microsoft.com/.../openform
Thank you,
Amit katariya
Thanks, but I would like the fields to be automatically filled with the data retrieved from api.
Hello,
You can try below code to prefill some of the field while opening Quick create form -
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
entityFormOptions["useQuickCreateForm"] = true;
// Set default values for the Contact form
var formParameters = {};
formParameters["firstname"] = "Sample";
formParameters["lastname"] = "Contact";
formParameters["fullname"] = "Sample Contact";
formParameters["emailaddress1"] = "contact@adventure-works.com";
formParameters["jobtitle"] = "Sr. Marketing Manager";
formParameters["donotemail"] = "1";
formParameters["description"] = "Default values for this record were set programmatically.";
// Set lookup column
formParameters["preferredsystemuserid"] = "3493e403-fc0c-eb11-a813-002248e258e0"; // ID of the user.
formParameters["preferredsystemuseridname"] = " Admin user"; // Name of the user.
formParameters["preferredsystemuseridtype"] = "systemuser"; // Table name.
// End of set lookup column
// Open the form.
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
Holly Huffman
103
Muhammad Shahzad Sh...
96
Most Valuable Professional
Gerardo RenterÃa Ga...
51
Most Valuable Professional