Sunday, 7 February 2021

What is Secure Vs Unsecure configuration of plugin in Dynamics 365 CRM

 While developing plugin for Microsoft Dynamics CRM, there are some scenarios where you required an input parameters or a configuration for the plugin execution which can be easily updated without having to re-compile or re-registering the plugin.


When you register a plugin step, there are fields where you can specify configuration parameters for the plugin execution.

In Microsoft Dynamics CRM there are two types of different configurations fields are available for plugin-

        1.       Unsecure configuration.
        2.       Secure configuration.

The main difference between these two settings is that, secure configuration is only viewable by CRM Administrators while the unsecure configuration is viewable by any CRM user. 

Another major difference is- the unsecure configuration will automatically move between environments with your CRM solutions.

How to use the plugin step configuration:

While registering the new step in plugin you can provide the configuration data with the Secured or Unsecured fields as show in the below screenshot-






When you provide the configuration details in XML format in the constructor of your plugin class you will get the configuration value which you can use later in the execution method.

Wednesday, 3 February 2021

How to prevent record from saving in Dynamics CRM using Javascript

 From time to time you might need to add some validation to the save event of an entity, this actually used to be an approach I would use on a regular basis but since the introduction of business rules have found myself doing this less and less. But still, knowing the ability is available is handy.

When you define the onsave event function, you must tick the “Pass execution contact as first parameter” option. (See below)



Having done that you can create an onSave function with code similar to the example I have shown below. Note forgetting the “(context)”, which will take the context parameter allowing you to prevent the save when needed.

function onSave(context) {
  var saveEvent = context.getEventArgs();
  if (Xrm.Page.getAttribute("telephone1").getValue() == null) {
    // *** Note: I am using an alert for testing a notification maybe better!
    alert("Put in a phone number!");
    saveEvent.preventDefault();
  }
}

Note: This simple example might be better achieved with a business rule but when you need complex validation that can’t be implemented with a business rule this approach is usefil.

Happy Code! J


Dynamics 365 CRM Interview Questions 2021

 1. What is filtered view?

2. Difference between secure and unsecure configuration?

3. What is Depth Variable, explain any scenario in Realtime usage of depth?

4. Power Portals, Power Bi, Logic Apps, Power Bi, Power Automate related questions?

5. What are actions in CRM?

6. How did you do the release management?

7. Plugin and Workflows in CRM?

8. Business rules in CRM?

9. What are Roll up and Calculated fields?

10. What is business process flows and how we can apply security on it?

11. How to create reports in SSRS? 

 

Thursday, 22 October 2020

How to Filter SubGrid Lookup view in Dynamics 365 CRM

How to Filter SubGrid Lookup view in Dynamics 365 CRM. 

Please check the comments in the below code and do follow the steps accordingly and call the filterSubGrid() funtion on onload.

var LastQuery = "";

function filterSubGrid() {
    debugger;
    setSubgridLookupFiltering();
}

function AddLookupFilter(entity_type, customFilter) {
    var subgridLookup = Xrm.Page.getControl("lookup_Contacts_Participants");
    subgridLookup.addCustomFilter(customFilter, entity_type);
}

function setSubgridLookupFiltering() {
    var subgridAddButtonId = "Contacts_Participants_addImageButton";
 
    //Try to get the element from both the current and the parent document.
    var subgridAddButton = document.getElementById(subgridAddButtonId) || window.parent.document.getElementById(subgridAddButtonId);
 
    //This script may run before the subgrid has been fully loaded on the form. If this is the case,
    //delay and retry until the subgrid has been loaded.
    if (subgridAddButton == null) {
        setTimeout(setSubgridLookupFiltering, 2000);
        return;
    }
 
    //Local function to retrieve the lookup control and apply the filter. We will queue this function in the click event handler of the
    //Add button's click event.
    var getSubgridLookupAndAddFilter = function() {
        var subgridLookup = Xrm.Page.getControl("lookup_Contacts_Participants");
 
        //Delay and retry until we can locate the lookup.
        if (subgridLookup == null) {
            setTimeout(getSubgridLookupAndAddFilter, 200);
            return;
        }
 
        //This is a custom property we are tagging on to the lookup control to ensure that we will
        //apply the custom filter only once when the Add button is first clicked.
        if (subgridLookup.customFilterAdded) {
            subgridLookup.removePreSearch(function () {
                subgridLookup.addCustomFilter(LastQuery, "contact");
                //AddLookupFilter("contact", LastQuery);
            });
        }

        var LookUp = Xrm.Page.getAttribute("jar_cliente").getValue();

        console.log(LastQuery);
 
        subgridLookup.addPreSearch(function() {
            //Standard logic to build up the filter query string
            var filterQuery = "<filter type='and'><condition attribute='parentcustomerid' operator='eq' value='" + LookUp[0].id + "' /></filter>";
            
//Set Global Variable to remove PreSearch
LastQuery = filterQuery; //Standard call to add filter to the lookup control subgridLookup.addCustomFilter(filterQuery, "contact"); }); //Mark the fact that we have already added the filter so that we won't do it again the next time the user clicks the Add button. subgridLookup.customFilterAdded = true; }; //Attach the function to retrieve the lookup and apply the filter to the Add button's click event. Remember that we //can only get the lookup after the user has clicked the Add button. subgridAddButton.addEventListener("click", function() { setTimeout(getSubgridLookupAndAddFilter, 200); }); }

Only a one problem, when the user change the principal lookup field, not work the filter, the function is called removePreSearch.

if (subgridLookup.customFilterAdded) {
            subgridLookup.removePreSearch(function () {
                subgridLookup.addCustomFilter(LastQuery, "contact");
                //AddLookupFilter("contact", LastQuery);
            });
        }
link: https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/261801/filter-new-record-subgrid-with-field

Monday, 11 May 2020

How To Retrieve All Files from SharePoint Library Folder & Send an Email Attachment using Microsoft Flows


msflowsmallicon In this blog I will explain how to retrieve all files from a specified SharePoint folder and send email as an attachment.

Every flow needs a trigger to start with so here I am using a manual trigger.

Next step I am using flow step SharePoint List Folder which returns files contained in a SharePoint folder.

The return response is array of BlobMetadata which contains the below details.

NamePathTypeDescription
ItemIdItemIdintegerThe value that can be used to Get or Update file properties in libraries.
IdIdstringThe unique id of the file or folder.
NameNamestringThe name of the file or folder.
DisplayNameDisplayNamestringThe display name of the file or folder.
PathPathstringThe path of the file or folder.
LastModifiedLastModifieddate-timeThe date and time the file or folder was last modified.
SizeSizeintegerThe size of the file or folder.
MediaTypeMediaTypestringThe media type of the file or folder.
IsFolderIsFolderbooleanA boolean value (true, false) to indicate whether or not the blob is a folder.
ETagETagstringThe etag of the file or folder.
FileLocatorFileLocatorstringThe filelocator of the file or folder.

Next, we need to collect the file name and contents. For this we need to declare a variable type array called FilesArray.

Next step we need to construct a loop for reading all the SharePoint list folder contents. List folder contents will have files and folders. So within the loop I am checking whether the content is a folder or not. See below image.

Next, we need to construct rest of the logic under the yes condition for getting all the file names & contents to array variable which we declared earlier. To get the file content use flow step Get file content using path. Path property is available from the above step using Blobmetadata content. Append to array will have two properties ContentBytes and Name. See format below.

The expression for file ContentBytes is as follows:

body(‘Get_file_content_using_path’).$content

Note: There is a property called FileContent available from the Dynamic content, but this will result in error for flow step send email. So it’s important to use the above expression for the contentbytes.

Finally, outside the apply each loop use the send email flow action for sending all the files as one attachment.


Below is the final preview of the flow solution which we discussed above.

Thank you for reading.

Ref: https://mydevexperience.wordpress.com/2019/10/12/microsoft-flow-retrieve-all-files-from-sharepoint-library-folder-send-email-attachment/

Saturday, 11 April 2020

How to fix “Undeclared Property Error” when setting the Lookups with Dynamics 365 Web API

A very quick note to remind you about something really important when working with the Dynamics Web API, it is one of those things that you always forget to check until you spent 3 hours trying to figure out why it isn’t working.
I was updating my code to create some related records after creating  a contact record and in one of the related entities I got this error:

“An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property ‘YOUR FIELD’ which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.”
This is caused because in my request I had the wrong field name, please remember always use the schema name for the lookups!

It is quite common for different people to create the fields in an entity and as I am sure you know Dynamics 365 tends to keep the characters in Capitals when it maps the schema name:

Some people would correct this and leave the schema name to be: mif_myfield
Others will just leave it like that.
Personally I tend to correct it and leave everything lower case but whatever works for you.
So my issue with my request was that I was using the Name of the field rather than the Schema Name:
This is wrong:
This is correct:

𝗣𝗼𝘄𝗲𝗿 𝗣𝗹𝗮𝘁𝗳𝗼𝗿𝗺 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 – 𝗕𝗲𝗴𝗶𝗻𝗻𝗲𝗿 𝘁𝗼 𝗘𝘅𝗽𝗲𝗿𝘁

  🔰 𝗣𝗼𝘄𝗲𝗿 𝗣𝗹𝗮𝘁𝗳𝗼𝗿𝗺 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 – 𝗕𝗲𝗴𝗶𝗻𝗻𝗲𝗿 𝘁𝗼 𝗘𝘅𝗽𝗲𝗿𝘁 🚀 🟢 𝗕𝗲𝗴𝗶𝗻𝗻𝗲𝗿 / 𝗝𝘂𝗻...