Tuesday, May 19, 2020

Implement multi level project approval for D365 PSA

In D365 PSA, we do not get the multi level approval functionality in the OOB time/expense approval process.
But I know some of our customers need to have multi level approvals for some of their daytoday business process(specially for expense approval).

When we click the approve button in project approval records(Either using the home ribbon button or form ribbon button), it invokes below OOB msdyn actions accordingly.

Expense approval
  • msdyn_ExpenseEntriesPendingApproval
  • msdyn_ExpenseEntriesApprove
Time Approval
  • msdyn_TimeEntriesPendingApproval
  • msdyn_TimeEntriesApprove

Below is my solution for extending the OOB project approval functionality to enable multi level approvals for PSA. In this article my main intention is just to give you an idea about how to extend above actions to implement multi level approvals. Hence you can use that concept and implement your own extended solution.

Solution:
  1. Create your own setting entity to configure and enable multi level approval("Approval Rule" is my entity). 
  2. Create your own entity to configure approval hierarchy("Approval Hierarchy" is my entity).
    • Has a 1:N relationship with Approval Rule entity.
    • Contains the approvers and the hierarchy.
  3. Create your own entity or add new fields to Project Approval entity to track your current approver and the status. (I prefer to use a new entity "Approval Tracking")
  4. Create a new plugin for post create event in Project Approval entity and create new approval tracking record/s accordingly.
  5. Create pre execute plugins accordingly for above mentioned msdyn actions and implement below logic.
    • In Pending Approval action
      • Remove the id/s form approval action unless it has passed through the hierarchy. (I have explain id removal process below under tips to remove ids form approval and the example.)
    • In Approve action
      • If the project approval record is not in the last approval stage according to the hierarchy, assign the project approval record to the next approver in the hierarchy.
      • Update relevant Approval Tracking entity record with the current stage.
      • Remove the id/s form approval action unless it has passed through the hierarchy. (I have explain id removal process below under tips to remove ids form approval  and the example)
Tips to remove ids form approval :
  • In expense approval actions, the entries for approval are passed to the actions as a string and the input parameter "ExpenseEntryIds" holds the value. 
  • In time approval actions, the entries for approval are passed to the actions as a string and the input parameter "TimeEntryIds" holds the value.
  • From home ribbon button click, it sends all the selected record ids as a comma separated string and from form ribbon button click it just send the relevant record id as a string.
Example :
Step 1: Write a new plugin for msdyn_ExpenseEntriesApprove action.
// Get the entry ids to process from input parameters. var entryIdsToProcess = localContext.PluginExecutionContext.InputParameters["ExpenseEntryIds"].ToString(); // Implement your own method with custom logic to remove expense ids which are not in final stage of the approval process. var newEntryIdsToProcess = RemoveEntryIds(localContext, entryIdsToProcess); // Update ExpenseEntryIds with newEntryIdsToProcess. localContext.PluginExecutionContext.InputParameters["ExpenseEntryIds"] = entryIdsToProcess;

Step 2: Register your plugin for for the pre operation of msdyn_ExpenseEntriesApprove action.


I hope using above steps, you can implement your own, multi level approval solution for PSA.
If you face any issue while implementing, please add a comment or send me a direct message. I'm happy to help you.

Happy coding 😊


Monday, March 2, 2020

Add event on subgrid refresh - Dynamics CRM.

You may need to execute some custom action on your parent form, when you add some records using quick create forms. As an example you may need to disable a field on work order form when you add work order incidents using quick create form.

In this case, you can add a subgrid event listener to your subgrid to perform your logic.
  1.  Create a javascript file as a web resource and add below functions to your javascript file.
  2. function AddSubgridEvents(executionContext) {
      var formContext = executionContext.getFormContext(); 
    
      addSubgridEventListener(formContext);
    } 
    
    function addSubgridEventListener(formContext){
      var gridContext = formContext.getControl("SUBGRID_ID");
      
      //ensure that the subgrid is ready…if not wait and call this function again
      if (gridContext == null){
         setTimeout(function () { addSubgridEventListener(formContext); }, 500);
         return;
      }
      
      //bind the event listener when the subgrid is ready
      gridContext.addOnLoad(subgridEventListener);
    }
    
    function subgridEventListener(gridContext){
        // Gets the form context using subgird context
        var formContext = gridContext.getFormContext();
    
        // Implement your logic here...
    }
  3. Include your javascript file in form libraries.
  4. Add your "AddSubgridEvents" function to Form Onload event handler and pass the execution context as a parameter.
Happy coding 😎

Monday, August 26, 2019

RetrieveMultiple plugins for both Unified Interface and classic UI in D365


I hope you have experience with writing plugins on RetrieveMultiple message. Even though you do not have experience with writing plugins on RetrieveMultiple message, this will help you when you write a new plugin.

Before the Unified Interface for Dynamics 365 comes in to play, it used the QueryExpression in RetrieveMultiple. But the Unified Interface Dynamics 365 uses FetchExpression. Meanwhile classic UI  uses the QueryExpression as usual.
So if your system already have plugins for RetrieveMultiple message, it won't work for UCI. Hence you may need to modify those to work for both UCI and classic UI.

Following sample code snippet will help you to write/update your plugins on RetrieveMultiple message.

if (context.MessageName == "RetrieveMultiple" && context.Stage == 20 context.Mode == 0 && context.InputParameters.Contains("Query") && ((context.InputParameters["Query"] is QueryExpression) || (context.InputParameters["Query"] is FetchExpression)))
{
 // For QueryExpression (For Classic UI)
 if (context.InputParameters["Query"] is QueryExpression)
 {
  var  queryExpression = context.InputParameters["Query"] as QueryExpression;
  var queryExpressionToFetchXmlRequest = new QueryExpressionToFetchXmlRequest()
  {
   Query = queryExpression
  };
  var queryExpressionToFetchXmlResponse = (QueryExpressionToFetchXmlResponse)service.Execute(queryExpressionToFetchXmlRequest);
 }
 // For FetchExpression (For UCI)
 else if(context.InputParameters["Query"] is FetchExpression)
 {
  var  fetchExpression = context.InputParameters["Query"] as FetchExpression;
  var fetchXmlToQueryExpressionRequest = new FetchXmlToQueryExpressionRequest()
  {
   FetchXml = fetchExpression.Query
  };
  var fetchXmlToQueryExpressionResponse = (FetchXmlToQueryExpressionResponse)service.Execute(fetchXmlToQueryExpressionRequest);
 }
}

You can change the code inside the block as you wish to implement your logic and enjoy 👍


Thursday, June 6, 2019

Voice of the Customer : Script Error in UCI

If you use Voice of the Customer app, you may have experienced following script error, when you edit and save the colors of a theme in UCI.
If you use Dynamics 365 — custom application. You won't get this error. But it is not the fix for this 😏

If you have this issue, when you open the theme in UCI, you may see the them as below.


Then after you edit the colors of the theme and save, it will give you a script error as below.


Since editing a themes is core function of the Voice of the Customer app you need to have the correct privilege in order to change the proprieties of the themes.

So in order to correct this please follow below steps. 
  1. Go to Settings-> Security -> Users
  2. Select the user
  3. Click Manage Roles button in the ribbon.
  4. Add the following security role:

After this your issue should be fixed and you will see the survey template as below.



UCI is not a daemon, enjoy it 😎

Tuesday, May 14, 2019

Microsoft Dynamics CRM Reporting Authoring Extension Setup - Error

If you get the following error(Setup cannot continue because there is a pending restart required) while you installing Microsoft Dynamics 365 Report Authoring Extension, you can follow below steps to overcome the issue. (Please do not forget to restart and see will the issue be fixed, if not try this  😏)

  1. Open the log file in the error message.
    (Eg : C:\Users\Thusitha\AppData\Roaming\Microsoft\MSCRM\Logs\BIDSExtensionsSetup.log)
  2. Check for the registry path and delete it.
     (Eg : Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce)

Tip: To open registry editor follow below steps.
  1. Open the Run box with the keyboard combination Windows key + r.
  2. In the Run line, enter “regedit” (without quotes)
  3. Click “OK”

This will fix your problem and will allow you to install Microsoft Dynamics 365 Report Authoring Extension.

Thursday, February 7, 2019

Refresh your Freshsales data from Dynamics CRM using Microsoft Flow

Freshsales is another popular CRM and you may need to update existing Freshsales data when customers are migrating to Dynamics CRM or using both CRMs. 
You can integrate MS CRM and Freshsales CRM easily using Microsoft Flow and Freshsales REST API.

Following image is a sample of lead creation in Freshsales when a lead is created in Dynamics CRM.
You can create a flow to send a HTTP request to Freshsales API from  Microsoft Flow. 


With this approach, you may able to refresh your Freshsales data from Dynamics CRM using Microsoft Flow with less effort.

Tuesday, January 29, 2019

Plugin Registration Tool : Not working properly


I believe you may use following options to download the Plugin Registration Tool.
  1. Download the Dynamics 365 SDK Tool Set as a single Zip file from https://xrm.tools/SDK
  2. Download using PowerShell
    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/download-tools-nuget#download-tools-using-powershell
  3. Download using nuget package manager or nuget package manager console
    https://www.nuget.org/packages/Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool
  4. Install tools via npm
    https://xrm.tools/SDK
  5. Use the plugin registration tool in XRM toolbox.
    https://www.xrmtoolbox.com/plugins/Xrm.Sdk.PluginRegistration/
If you download the Zip file and use it, sometimes you may experience that the popups are not working when you try to preform the operations(Register/Unregister/Update plugins, Debug, etc.).
But the most confusing thing is the plugin registration tool is connecting and you can preform other operations as usual.


As well as you may have experienced an issue with the plugin registration tool in XRM toolbox. Sometimes it gives the message that the dll is updated even though it is not actually updated the dll in CRM. 

So my recommendation is to use other options without downloading the zip file or using the plugin registration tool in XRM toolbox. When the plugin registration tool is download using other three options(2,3,4), it works properly.