Enable +New button in the Lookup view of the Dynamics 365 portal.
Views (1422)
Hello Everyone,
I have been seen a lot of people were finding a way or solution to add a custom button or 'New' button inside Lookup dialog in order to create a new record directly from Portal if not found in lookup Search result.
Here are the few links where it has been asked:
https://community.dynamics.com/crm/f/117/t/244076
https://community.dynamics.com/crm/f/117/t/246265
Here is the code I have written to achieve the same:
// Calling of Function
AddNewButton_InLookupDiaog('customerid','Select','customeridNewBtnId','Add New','~/create-account','Authenticated');
// lookupfieldScehmaName = schema name of lookup field
// NewButtonPosition = Position, where you want to place the 'New' Button inside Lookup Window
// NewButtonId = Id of New Button, Make sure this should be unique
// NewButtonText = text to display of New Button
// NewButtonActionURL = Provide webpage partial URL or the page where you want to redirect the user in order to create new record
// Webrole = Role to which 'New' button should be visible. If passed 'Authenticated' then 'New' would be visible to Authenticated Users only.
// Function Definition
function AddNewButton_InLookupDiaog(lookupfieldScehmaName,NewButtonPosition, NewButtonId,NewButtonText,NewButtonActionURL,Webrole){
var loggedInUserRole = '{{user.roles}}';
if(loggedInUserRole.indexOf(Webrole) == -1){
return;
}
var elementId = lookupfieldScehmaName+"_lookupmodal";
$("#"+elementId).closest('table').on("loaded", function ()
{
var IsAddNewButtonAdded = $("#"+NewButtonId).length;
// If button is not added then add the button
if(IsAddNewButtonAdded == 0)
{
$("#"+elementId).find('button:contains("'+NewButtonPosition+'")').before('<button id="'+NewButtonId+'" aria-label="New" class="primary btn btn-primary" tabindex="0" title="New" type="button" onclick="NewButtonAction('+"'"+NewButtonActionURL+"'"+')">'+NewButtonText+'</button>');
}
});
}
function NewButtonAction(redirectionURL)
{
window.open(redirectionURL,'_blank');
}
Demo:
Log in to CRM Portal :
We are going to add a 'Add New' button in 'Customer' Lookup Dialog:
Press F12 or Inspect to get the Schema name of the lookup field. You can check the schema name of the field from CRM also from Form Customization :
Add code to Add Add 'New' button in Customer Lookup Dialog :
Open Web page > Go to Advanced Tab > Custom Javascript and paste the given code as mentioned below:
Output :
Once clicked on 'Add New'
Let's have a look all the Parameters one by one:
Parameter 1 - lookupfieldScehmaName:
For Example, It's value = 'customerid'
Parameter 2 - NewButtonPosition:
For Example, It's value = 'Select'
Parameter 3 - NewButtonId:
For Example, It's value = 'customeridNewBtnId'
Parameter 4 - NewButtonText:
For Example, It's value = 'Add New'
Parameter 5 - NewButtonActionURL:
For Example, It's value = '~/create-account'
Parameter 6 - Webrole:
For Example, It's value = 'Authenticated'
Note -
- To add 'New' button in multiple lookups on the form, you just need to call the function again with required parameters of each lookup. The Function definition will remain same.
- Make sure you are providing the unique Id for each button ('New') for every lookup dialog.
Please do not forget to share your feedback:
Cheers
This was originally posted here.

Like
Report
*This post is locked for comments