Migrating Advanced Find/Personal Views in Dynamics 365 with XrmToolBox
This is the second part of our tutorial. In the first part, we discussed how to create a view in Dynamics 365 and share it with different teams or users (link here). Here, we will focus on migrating personal views created using Advanced Find from one environment to another using the XrmToolBox.
Refer to this video for a detailed implementation guide-
Understanding Views in Dynamics 365
Views in Dynamics 365 are essentially filtered lists of records. By default, Dynamics 365 provides several views such as Active Contacts and Inactive Contacts. These views display selected fields like Full Name, Email, and Company Name. While you can create general views using the maker portal in Power Apps, this post focuses on creating a personal view using Advanced Find and sharing it with other users or teams.
We have two types of views in Dynamics 365:
1. Out-of-the-box (OOB) views: These can be created directly in the Power Apps maker portal. However, these views have a limitation - they cannot be shared with specific users or teams.
2. Advanced Find personal views: These are custom personal views created using the Advanced Find feature. Unlike OOB views, these can be shared with other users or teams.
In this blog post, we will focus on migrating personal views created using Advanced Find from one environment to another (e.g., from a development environment to a production environment) using the XrmToolBox. Check below snapshot for visual representation of same -
Prerequisites
Before we start, ensure you have the following:
- XrmToolBox installed on your machine. You can download it from the XrmToolBox official website (https://www.xrmtoolbox.com/).
- Appropriate permissions in both the source and target Dynamics 365 environments.
- A user account with the necessary privileges to create and share views in Dynamics 365.
Step-by-Step Guide
Step 1: Connect to Your Source Environment
1. Open XrmToolBox.
2. Click on the "Connect" button to establish a connection with your Dynamics 365 environment.
Once connected, go to the "Tool Library" and search for the "Personal View Migration Tool". We need to install this tool in XrmToolBox to migrate views between environments.
3. Click on "Open Tool Library."
Search for "Personal View Migration Tool," select it, and click on the install button.
Once installed, go to the tool and open "Personal View Migration Tool."
Click on the "Connect Source" button to establish a connection with your source environment.
Click on the "Connect Target" button again, this time connecting to your target Dynamics 365 environment.
Click on Load user button to load all the users and teams
Now, click on "Load Views" to retrieve the views from the source environment.
Locate the personal view you want to migrate. Personal views are typically listed under the user's name who created them.
Click on Load sharing button to see if the personal views are shared to any user or team.
Select the desired views and click on "Migrate" button
Once the migration is done, you'll see "Migration Completed" message
Now, connect to Your Target Environment.
Navigate to the relevant entity and check if the personal view appears under "Views"
Additional Notes
- Backup Your Views: Always keep a backup of your views before making any changes.
- Test in a Sandbox: Before migrating views to production, test the migration process in a sandbox environment.
- Permissions: Ensure the user account used for the migration has appropriate permissions in both environments.
- Sharing Views: After migrating, you may need to share the view with other users or teams in the target environment.
Troubleshooting - Users and Teams: The users or teams in the source environment may differ from those in the target environment. Ensure that you reassign the views to the appropriate users or teams after migration.
Conclusion
Migrating personal views between Dynamics 365 environments using XrmToolBox is a straightforward process. By following the steps outlined in this guide, you can ensure a smooth transition of custom queries, helping maintain consistency and efficiency across different Dynamics 365 environments.
How to Create and Share a Personal View to User or Team in Microsoft Dynamics 365
Hello everyone, welcome back to our Dynamics 365 series. In this post, we'll delve into creating and sharing personal views in a model-driven app. Unlike OOB views, personal views are custom views created using the Advanced Find feature, tailored to your specific needs. Let’s walk through the process step-by-step.
Refer to this video for a detailed implementation guide-
Understanding Views in Dynamics 365
Views in Dynamics 365 are essentially filtered lists of records. By default, Dynamics 365 provides several views such as Active Contacts and Inactive Contacts. These views display selected fields like Full Name, Email, and Company Name. While you can create general views using the maker portal in Power Apps, this post focuses on creating a personal view using Advanced Find and sharing it with other users or teams.
We have two types of views in Dynamics 365:
1. Out-of-the-box (OOB) views: These can be created directly in the Power Apps maker portal. However, these views have a limitation - they cannot be shared with specific users or teams.
2. Advanced Find personal views: These are custom personal views created using the Advanced Find feature. Unlike OOB views, these can be shared with other users or teams.
In this blog post, we will focus on Creating and Sharing a Personal View to User or Team in Microsoft Dynamics 365
Step-by-Step Guide to Creating a Personal View
1. Open Advanced Find:
- Navigate to the Advanced Find feature in Dynamics 365. You can find this option in the settings or by clicking on the funnel icon.
2. Build Your Query:
- Choose the entity you want to create a view for (e.g., Accounts or Contacts).
- Add conditions to filter the data as needed. For instance, you can filter accounts where the "Account Number" is not empty.
3. Select Columns to Display:
- Click on "Edit Columns" to select which columns you want to display in your view. You can add, remove, or rearrange columns as required.
4. Save the View:
- Once your query is set, click on "Save As" to save the view.
- Give your view a descriptive name (e.g., "June 18a View").
5. Access the Saved View:
- The saved personal view will be available under "My Views" in the Advanced Find menu.
Sharing the Personal View
1. Navigate to Saved Views:
- Go back to the Advanced Find menu and select "Saved Views".
- Choose the view you want to share.
2. Share the View:
- Click on the "Share" button (represented by a share icon).
In the sharing window, click on “Add User/Team” to select the users or teams you wish to share the view with.
If you want to share the view to a team then simply select Team from the "Look for" field dropdown and select your team.
3. Assign Permissions:
- Assign the necessary permissions such as Read, Write, Delete, Assign, or Share.
- Confirm by clicking "Share".
4. Verify Shared View - Log in with the user account you shared the view with to ensure they have access to the view.
Limitations and Workarounds
A key limitation of personal views created using Advanced Find is that they cannot be imported directly into a solution for deployment. To transfer personal views from one environment to another (e.g., from development to production), you can use tools like the XRM Toolbox.
1. Using XRM Toolbox:
- Install and open the XRM Toolbox.
- Connect to both the source and target environments.
- Use the “View Transfer Tool” to migrate personal views between environments.
Creating and sharing personal views in Microsoft Dynamics 365 CRM enhances data accessibility and collaboration within teams. While there are some limitations, tools like XRM Toolbox provide effective workarounds for transferring views across environments. If you have any questions or need further assistance, feel free to comment below.
For more insights and tutorials on Dynamics 365, visit our YouTube channel and blog for detailed articles and videos. link here
How to Use JavaScript to Lock a Field on an Editable Subgrid in Dynamics 365
In this blog post, I'll demonstrate how to use JavaScript to lock a specific field on an editable subgrid within a Dynamics 365 form. This ensures that users cannot update its values directly within the subgrid. For this example, we'll focus on the "Contacts" subgrid and lock the "emailaddress1" field.
Refer to this video for a detailed implementation guide
--Steps to Implement Field Locking with JavaScript--
Step 1: Create a JavaScript Web Resource
First, you need to create a JavaScript web resource that contains the code to lock the field.
Navigate to your Dynamics 365 solution.
Go to Web Resources and create a new JavaScript (JS) web resource.
Add the following code to the web resource and save it.
JavaScript c0de below -
function onGridRowSelected(context) {
console.log("Function Triggerred for Locking subgrid field...");
Step 2: Add the JavaScript Web Resource to the Form
Next, you'll add this JavaScript web resource to the form that contains the editable subgrid.
Open the Main Form for the entity (e.g., Account) that contains the subgrid.
Click on Form Properties .
Under the Form Libraries section, click Add and select the JavaScript web resource you created.
Click OK to add the web resource to the form.
Step 3: Attach the JavaScript Function to the Subgrid Event
Now, you'll attach the `onGridRowSelected` function to the OnRecordSelect event of the subgrid.
Select the subgrid on the form.
In the right-hand pane, find the Events section.
Click Add to add a new event.
Choose OnRecordSelect as the event.
In the Library dropdown, select the JavaScript web resource you added earlier.
In the Function field, enter `onGridRowSelected`.
Ensure that Pass execution context as first parameter is checked.
Click OK to save the event configuration.
Step 4: Publish
Finally, publish all customizations to apply the changes.
Click Save and Close on the form editor.
In the solution, click Publish All Customizations .
# Testing the Implementation
To verify that the field locking functionality works correctly:
Navigate to the form containing the Contacts subgrid.
Select a row in the subgrid.
Attempt to edit the "emailaddress1" field.
You should notice that the "emailaddress1" field is now disabled and cannot be edited, ensuring the values remain unchanged.
# Conclusion
By following these steps, you can effectively lock a specific field in an editable subgrid using JavaScript in Dynamics 365. This approach can be particularly useful for maintaining data integrity by preventing users from altering critical information directly within subgrids.
Stay tuned for more tips and tricks on optimizing your Dynamics 365 experience! If you have any questions or need further assistance, feel free to leave a comment.
How to Convert a Subgrid on a Form to an Editable Subgrid in Dynamics 365
In this blog, I will show you how to convert a sub-grid on a form to an editable sub-grid in Dynamics 365. This feature allows users to edit records directly within the sub-grid, enhancing the user experience by eliminating the need to navigate to a different screen.
Understanding the Scenario
Let's take a look at an example to understand the requirement better. Imagine you have an "Investment" form with a sub-grid displaying contacts. Currently, this sub-grid is not editable in-line, meaning you have to open each record individually in a new form to make changes. This process is cumbersome and time-consuming. The goal is to make the sub-grid editable in-line, directly on the form.
Refer to this video for a detailed implementation guide
Steps to Convert Sub-grid to Editable
Step 1: Access the Main Form
Navigate to your solution in Dynamics 365.
Go to the Investment entity and select Forms .
Open the Main Form that contains the sub-grid you want to edit.
Step 2: Edit the Form
Once the form is open, you will see the sub-grid you want to make editable.
Select the sub-grid. On the right-hand side, you will find the Properties pane with three sections: Display , Formatting , and Component .
Step 3: Add Editable Grid Component
In the Component section, click on Add Component and choose Editable Grid .
This will open a small screen where you can configure the editable grid settings.
Step 4: Configure the Editable Grid
Select the sub-grid view and specify which table it is connected to. In this case, it connects to the "contacts" table.
Choose the view you want to display in the editable grid.
Configure additional options such as filtering, grouping, and device compatibility.
Click Done to finalize the configuration.
Step 5: Publish the Form
Publish the form to apply the changes.
After publishing, refresh the form to see the editable sub-grid in action.
# Testing the Editable Sub-grid
Once the form is published and refreshed, navigate back to the Investment form to test the editable sub-grid:
1. Open the form and find the contacts sub-grid.
2. Click on a cell to edit the value directly in-line.
3. Make changes such as updating relationship types, verifying statuses, or changing contact information.
4. If you double-click, it will open the record. To edit in-line, just click once.
5. The changes will be auto-saved when you move out of the row, or you can manually save using the Save button.
# Additional Configurations
Grouping and Filtering
- You can enable grouping by specific fields such as name or contact.
- Filtering options allow you to narrow down the records displayed in the sub-grid.
# Conclusion
By following these steps, you can enhance the functionality of your Dynamics 365 forms by making subgrids editable.
Convert Currency/Amount field to Words in Dynamics 365
Introduction:
In many business scenarios, displaying currency amounts in words is crucial for clarity and compliance. Dynamics 365 doesn't offer a built-in feature for this conversion. In this blog, we'll walk through the process of implementing a solution to automatically convert currency amounts to words in Dynamics 365 (e.g., 1075 becomes "One Thousand and Seventy Five").
Refer to this video for a detailed implementation guide for converting amount to words-
Requirements:
Access to Dynamics 365 environment with customization privileges.
Basic understanding of JavaScript and Dynamics 365 customization.
-----Steps------
Step 1: Create Custom Fields and place these field on the main form
Create two custom fields:
- Amount (Currency) : This field will store the currency amount.
- Amount in Words (Single Line of Text) : This field will display the currency amount in words.
Step 2: Write Conversion Logic
Write JavaScript functions to convert the numeric currency amount to words. Below is the code snippet for the conversion logic:
function convertAmountToWordsDemo() {
// Get the numeric value from the new_amount field
var amount = Xrm.Page.getAttribute("new_amount").getValue();
// Check if the amount is not null or undefined
if (amount != null && amount !== undefined) {
// Convert the numeric value to words
var amountInWords = convertNumberToWords(amount);
// Set the value in the new_amountinwords field
Xrm.Page.getAttribute("new_amountinwords").setValue(amountInWords);
}
}
// Function to convert a numeric value to words
function convertNumberToWords(n) {
if (n < 0)
return false;
var singleDigit = ['', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'];
var doubleDigit = ['Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen'];
var belowHundred = ['Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'];
if (n === 0) return 'Zero';
// Separate the integer and decimal parts
var integerPart = Math.floor(n);
var decimalPart = Math.round((n - integerPart) * 100); // Convert decimal to cents
function translate(n) {
var word = "";
if (n < 10) {
word = singleDigit[n] + '';
} else if (n < 20) {
word = doubleDigit[n - 10] + ' ';
} else if (n < 100) {
var rem = translate(n % 10);
word = belowHundred[(n - n % 10) / 10 - 2] + ' ' + rem;
} else if (n < 1000) {
var remainder = translate(n % 100);
word = singleDigit[Math.trunc(n / 100)] + ' Hundred ' + remainder;
} else if (n < 1000000) {
var remainder = translate(n % 1000);
word = translate(Math.trunc(n / 1000)) + ' Thousand ' + remainder;
} else if (n < 1000000000) {
var remainder = translate(n % 1000000);
word = translate(Math.trunc(n / 1000000)) + ' Million ' + remainder;
} else {
var remainder = translate(n % 1000000000);
word = translate(Math.trunc(n / 1000000000)) + ' Billion ' + remainder;
}
return word;
}
// Create the words for the integer part
var integerWords = translate(integerPart).trim();
// Create the words for the decimal part
var decimalWords = (decimalPart > 0) ? 'and ' + translate(decimalPart).trim() + ' cents' : '';
// Construct the final result
var result = (integerWords + ' ' + decimalWords).trim();
return result;
}
Code Logic
The convertAmountToWordsDemo function triggers when needed (e.g., on record save).
It retrieves the amount value from the new_amount field.
It calls the convertNumberToWords function to convert the numeric value to words.
Finally, it sets the converted text in the new_amountinwords field.
The convertNumberToWords function handles the core conversion logic:
It defines arrays for representing digits, teens, and tens.
It translates the number part by place value (hundreds, thousands, millions, etc.).
It handles decimals by converting them to cents and translating them separately.
It constructs the final result by combining the integer and decimal words.
Step 3: Attach Script to Currency Field
Navigate to your entity customization in Dynamics 365.
Go to the "Forms" section depending on where you want the functionality.
Edit the desired form.
Within the form editor, add a new web resource and paste the JavaScript code.
Attach the `convertAmountToWordsDemo` function to the onchange event of the currency field on the form. This ensures that whenever the currency amount changes, the conversion function is triggered.
Save and Publish the form.
Step 4: Test
Test the solution thoroughly to ensure accurate conversion and proper functionality. Consider scenarios such as different currency amounts, decimal places, and negative values.
Conclusion:
By following these steps, you can implement a solution to automatically convert currency amounts to words in Dynamics 365. This enhancement improves the clarity of displayed currency amounts and ensures compliance with business requirements.
Hello everyone, welcome back. So, this is going to be a short video. I'm just going to show you how you can enable or disable any plugin which is in Dynamics 365 for a short period of time. Let's say you have created a plugin and you want to disable it to check some other functionality. That time, some people do not know, they may just go and remove the plugin assembly in the plugin registration tool, but that's not the best way to do that. In the previous video, I have already created one plugin.
Refer to this video for a detailed implementation guide for creating Plugin-
So when you register it, it's not going to be stored in your current solution. It's going to be stored in the main solution only, like the main customize. Whenever you go to, let's say, this is, go to the setting Advanced setting. Now, I'm going to show you how you can enable or disable your plugin.
First of all, I have a solution. So, I would like to first add that plugin into this solution. So, for that, go to Add existing. We have the option of one second plugin assembly. And here, we should have the plugin assembly duplicate. Okay, here you can see this one. So, first of all, we are going to add the assembly, then the SDK message. Both in the current solution. Either you can go to the main solution and from there also, you can disable it. But I prefer it to have in a particular solution. So, from here, I should be able to control everything. And now, I'm going to add the SDK messages, which is duplicate this one. Okay, so now, once this one is added, let's go to that SDK message.
Here, include it. It may take some time. Okay, now this is done. So, let's go to the SDK processing message. We have two plugins written here. So, I'm just going to select the second one, click on this, and click on deactivate or activate. Let's say if you want to activate it, click on the activate. Right now, I want to deactivate it. So, it's going to take some time. It'll ask you for the confirmation. And just deactivated. From here itself, you can control. So, this is how you can enable or disable any plugin in Dynamics 365. If you have any doubt, you can post in the comment. Thank you so much.
Duplicate Detection in Power App using Plugin - Dynamics 365 / Power Platform
Introduction:
This blog will show you how to create Plugin in Dynamics 365 to stop users from saving records and display error messages. While you could use Out of the Box Duplicate detection rule but it won't prevent from saving the record. We can also use Duplicate Detection using Keys Click here to see Video.
Scenario:Create a plugin(Pre-Validation) for checking duplicate driving license on case form. Within the Case main form, there exists a text field named driving license. I've developed a plugin designed to restrict users from creating a new case if a duplicate driving license value already exists in any driving license record. Upon providing a driving license value during case creation, the plugin retrieves records from the driving license entity where the driving license attribute matches the entered value.
Refer to this video for a detailed implementation guide for creating Plugin-
What is Plugin?
A plugin is defined as a custom business logic that can be installed in Microsoft Dynamics CRM to make customizations or to enhance the standard behavior of the platform. Plugins help in handling various events and each plugin executes a specific event. In general, the Plug-ins are written in VB or C# can run an asynchronous or synchronous mode.
Before creating the plugin, ensure you have the following prerequisites in place-
JavaScript Code for showing custom message in dialog box-
Create a Visual Studio project for the plug-in
Open Visual Studio and open a new Class Library (.NET Framework) project using .NET Framework 4.6.2
The name used for the project is also the name of the assembly. This tutorial uses the name DuplicateDrivingLicencePlugin.
In Solution Explorer, right-click the project and select Manage NuGet Packages… from the context menu.
Select Browse and search for Microsoft.CrmSdk.CoreAssemblies and install the latest version.
You must select I Accept in the License Acceptance dialog. Note - Adding the Microsoft.CrmSdk.CoreAssemblies NuGet package will include these assemblies in the build folder for your assembly, but you will not upload these assemblies with the assembly that includes your logic. These assemblies are already present in the sandbox runtime.
In Solution Explorer, right-click the Class1.cs file and choose Rename in the context menu.
Rename the Class1.cs file to DuplicateDrivingLicence.cs.
When prompted, allow Visual Studio to rename the class to match the file name.
Paste below plugin code -
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace DuplicateDrivingLicence
{
public class DuplicateDrivingLicencePlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
// Check if the plugin is running in the pre-operation stage and for the intended entity
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity targetEntity = (Entity)context.InputParameters["Target"];
// Check if the target entity is the "incident" entity and contains the "new_drivinglicence" field
if (targetEntity.LogicalName == "incident" && targetEntity.Contains("new_drivinglicence"))
{
// Retrieve the driving licence value from the case record
string drivinglicenceValue = targetEntity.GetAttributeValue<string>("new_drivinglicence");
// Check for duplicate driving licence records
if (IsDuplicateDL(service, drivinglicenceValue))
{
throw new InvalidPluginExecutionException("Duplicate driving licence value found. Cannot create the case.");
}
}
}
}
catch (Exception ex)
{
tracingService.Trace($"Exception: {ex.Message}");
throw;
}
}
private bool IsDuplicateDL(IOrganizationService service, string drivinglicenceValue)
{
// Query to retrieve driving licence records with the provided value
QueryExpression query = new QueryExpression("new_drivinglicence")
{
ColumnSet = new ColumnSet("new_drivinglicence"),
Criteria = new FilterExpression()
{
Conditions =
{
new ConditionExpression("new_drivinglicence", ConditionOperator.Equal, drivinglicenceValue)
}
}
};
EntityCollection results = service.RetrieveMultiple(query);
// If there are any matching records, it's a duplicate
return results.Entities.Count > 0;
}
}
}
About the code
The above plugin, 'DuplicateDrivingLicencePlugin', aims to prevent duplicate driving license entries when creating case records in Dynamics 365.
1. Main Logic: It checks if the plugin is triggered in the pre-operation stage for case records containing the "new_drivinglicence" attribute.
2. If so, it retrieves the driving license value from the case record.
3. It then queries the "new_drivinglicence" entity to check for duplicates using the `IsDuplicateDL` method.
4. The `IsDuplicateDL` method constructs a query to find records with matching driving license values.
5. If duplicates are found, the plugin throws an exception, preventing the creation of the case.
6. Exception handling ensures graceful error management with tracing for debugging purposes.
7. This approach ensures data integrity by validating driving license entries before case creation.
Build plug-in
In Visual Studio, press F6 to build the assembly. Verify that it compiles without error
Sign the plug-in
In Solution Explorer, right-click the DuplicateDrivingLicencePlugin project and in the context menu select Properties.
In the project properties, select the Signing tab and select the Sign the assembly checkbox.
In the Choose a strong name key file: dropdown, select <New…>.
In the Create Strong Name Key dialog, enter a key file name, and deselect the Protect my key file with a password checkbox.
Select OK to close the Create Strong Name Key dialog.
In the project properties Build tab, verify that the Configuration is set to Debug.
Press F6 to build the plug-in again.
Using windows explorer, find the built plug-in at: \bin\Debug\DuplicateDrivingLicencePlugin.dll.
Register plug-in
To register a plug-in, you'll need the Plug-in Registration tool.
Connect using the Plug-in Registration tool
After you have downloaded the Plug-in registration tool, click the PluginRegistration.exe to open it.
Click Create new Connection to connect to your instance.
Make sure Office 365 is selected.
If you are connecting using a Microsoft account other than one you are currently using, click Show Advanced and enter your credentials. Otherwise, leave Sign-in as current user selected.
If your Microsoft Account provides access to multiple environments, select Display list of available organizations.
Click Login.
If you selected Display list of available organizations, select the organization you would like to connect to and click Login.
After you are connected, you will see any existing registered plug-ins, custom workflow activities and data providers.
Register your assembly
In the Register drop-down, select New Assembly.
In the Register New Assembly dialog, select the ellipses (…) button and browse to the assembly you built in the previous step.
For Microsoft 365 users, verify that the isolation mode is set to sandbox and the location to store the assembly is Database.
Click Register Selected Plug-ins.
You'll see a Registered Plug-ins confirmation dialog.
Select OK to close the dialog and close the Register New Assembly dialog.
You should now see the (Assembly) DuplicateDrivingLicencePlugin assembly, which you can expand to view the (Plugin) DuplicateDrivingLicencePlugin plugin.
Register a new step
Right-click the (Plugin) DuplicateDrivingLicencePlugin and select Register New Step.
In the Register New Step dialog, set the following fields
Setting
Value
Message
Create
Primary Entity
account
Event Pipeline Stage of Execution
PostOperation
Execution Mode
Asynchronous
Select Register New Step to complete the registration and close the Register New Step dialog.
You can now see the registered step.
Test plug-in
Open a your app and create a new case record with existing driving licence