Before you dive too deep in this I recommend you check out videos on how to install and use the Ribbon Workbench tool.
Click here for the link.
Also it is recommended to make changes through a Solution which I will not be covering either because there is a ton of information about that.
I will be adding more projects/examples as I verify the code is working properly.
Create button that will open quick create form
Let’s say I am in the Quote entity and I want to make a button that when clicked it opens the quick create form on a custom entity of mine (publisher_designrequest).
Here is the list of items I need to know:
Entities:
- quote
- publisher_designrequest (my custom entity)
Code:
function marketingdesignrequest(primaryControl) {
var thisAccount = {
entityType: "quote",
id: Xrm.Page.data.entity.getId()
};
var callback = function (obj) {
console.log("Created new " + obj.savedEntityReference.entityType + " named '" + obj.savedEntityReference.name + "' with id:" +
obj.savedEntityReference.id);
}
var setName = { };
Xrm.Utility.openQuickCreate("publisher_designrequest", thisAccount, setName).then(callback, function (error) {
console.log(error.message);
});
}
Step 1: Create a Web Resource
From CRM click the Setting icon in the right corner and click Advanced Settings
From there click Settings>Solutions
On the left find Web Resources then click New
Fill any identifying information you need then click Text Editor and past the above code in. Be sure to change your entityType and your entityLogicName to what you need.
Click Save and then Publish (I normally do this twice)
Step 2: Create the Button
Open Ribbon Workbench and load your solution
Select the quote Entity
Click the word Button and drag to where you want the button to be located
Click the + button on the right of command to add a command
Click Add Action>Javascript Action
Click Add parameter and select CRM Parameter
Next fill in the information:
- ID
- This can be named what you want
- Library
- Click the magnifying glass and find the Web Resource you created
- Function Name
- This is the name you used in the java script code above after the word Function on line 1
- CRM Parameter
- PrimaryControl is what I have in () on line one of the Javascript code. I will do some reading to see what this means.
Next click back to your button in the list under Buttons and fill in the info:
- ID
- The technical name you want for your button
- Command
- Select the command you created from the previous step
- Label
- This is friendly name the end user will see
- Image 16
- Click Magnifying glass and find an image
- Image 32
- Click Magnifying glass and find an image
- CommandCore
- I put the same name as the command name
At the top menu of Ribbon Workbench Click Publish and test
Now when I click on the Quotes entity I have a button that says Create DRF. When clicking it the Quick Create form comes up and Quote is automatically associated.
References:
https://carldesouza.com/opening-quick-create-javascript/
https://ribbonworkbench.uservoice.com/knowledgebase/articles/358664-create-a-command-bar-button-for-your-custom-acitiv