We can use Xrm.Navigation.openForm to open a Quick Create using JavaScript.
Let’s say we want to open the Account quick create form on a Contact record in the Unified Client Interface / Unified Interface. Let’s go to a contact record:
To simply open the quick create without setting any field values, we can use the code:
var entityFormOptions = {}; entityFormOptions["entityName"] = "account"; entityFormOptions["useQuickCreateForm"] = true; Xrm.Navigation.openForm(entityFormOptions, null).then( function (lookup) { console.log("Success"); }, function (error) { console.log("Error"); } );
Hitting F12 to run this code in developer tools, we see the quick create is open:
To set the values of fields, we can pass a 2nd parameter with the fields:
var entityOptions = {}; entityOptions["entityName"] = "account"; entityOptions["useQuickCreateForm"] = true; var formParameters = {}; formParameters["name"] = "Test account"; Xrm.Navigation.openForm(entityOptions, formParameters).then( function (lookup) { console.log("Success"); }, function (error) { console.log("Error"); } );
This defaults the name to Test Account on the account quick create:
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL
Hey Carl..
How can i open quickCreateform from html webresource on click.
Hi Nik,
Yes, you can call the same code from an HTML web resource, you can put it into a JS function and call the function onclick or ondblclick.
Hey Carl,
I have several Quick Create form for any reason, how can open a specific form?
By default, it opens another Quick Create form.
Thanks
Hi Carl,
Using formParameters is it possible to set a lookup? For example I want to set the regarding field of a task to an opportunity record.
I had this working in the classic interface but It no longer works in the UI.
Hi Jason,
Please see if this helps, it’s working for me (replace your GUID and Name 🙂 ):
var entityOptions = {};
entityOptions[“entityName”] = “account”;
entityOptions[“useQuickCreateForm”] = true;
var formParameters = {};
formParameters[“primarycontactid”] = “{25a17064-1ae7-e611-80f4-e0071b661f01}”;
formParameters[“primarycontactidname”] = “Abraham McCormick”;
Xrm.Navigation.openForm(entityOptions, formParameters).then(
function (lookup) { console.log(“Success”); },
function (error) { console.log(“Error”); }
);
Hi Carl,
Thank you for your reply it worked great however i did have to add an additional variable for the entity.
function TaskLaunch(executionContext)
{
var formContext = executionContext.getFormContext();
{
var formParameters = {};
//Pass the regarding value
var regardingObjectId = formContext.data.entity.getId();
var projectName = formContext.getAttribute(“new_name”).getValue();
formParameters[“regardingobjectid”]=regardingObjectId;
formParameters[“regardingobjectidname”]=projectName;
formParameters[“regardingobjecttypecode”]=”new_projects”;
formParameters[“subject”]=”Record Deactivated”;
// Define the entity name to open the form
var entityFormOptions = {};
entityFormOptions[“entityName”] = “task”;
entityFormOptions[“useQuickCreateForm”] = true;
var eventArgs = executionContext.getEventArgs();
if (eventArgs.getSaveMode() == 5) //Deactivate
{
// Open the form
Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
function (success) {
console.log(success);
},
function (error) {
console.log(error);
});
}
}
}
Nice! Glad it worked, Jason!
Hi, will it be possible to change the main (if one has to different contact forms) form on the enitity based upon field value – with Unified interface?
How would I pass parameter if I click on “+” button of subgrid?
Hi Carl,
Is it possible to trigger the new Enhanced Email form to create an email activity from JS in similar fashion?
Thanks
Ash