Using Union function to remove duplicates – Power Automate / Dataverse


We recently got the below error in one of our cloud flows, the requirement was to fetch the distinct work orders that have notes with attachments associated with them.

A resource of type ‘Microsoft.Dynamics.CRM.annotation’ was found in a resource set that otherwise has entries of type Microsoft.Dynamics.CRM.msdyn_workorder’. In OData, all entries in a resource set must have a common base type.

This occurs if we try using the aggeration in the Fetch XML queries in the List rows action.

The solution was to rewrite the fetch xml query without using aggregation.

And then next if we want to get the distinct values, we can use the Union function for that.

Here,

we are first adding the GUIDs to the varLstWorkOrderGUID array variable using Append to array variable action

And then applying the Union function – to remove the duplicate from the array.

union(variables(‘varLstWorkOrderGUID’), variables(‘varLstWorkOrderGUID’))

The result –

More on Fetch XML Query

Hope it helps..

Advertisements

Fixed- The XRM workflow table row could not be found error (Power Automate)


Recently while trying to open one of our cloud flows we got the below error.

Error: The XRM workflow table row could not be found.

Inside the Power Automate maker portal for the new designer, we got the below error

We could see our flows were in the OFF status.

We switched ON the flows, and this fixed the issue for us.

We were able to edit our flow then.

As we recently restored the environment (was deleted), because of which the corresponding ‘Callback Registration’ records might be incorrect or missing. So enabling the flows would have created new entries in the Callback registration records for our flows, which fixed the error.

Please refer- https://rajeevpentyala.com/2021/01/30/callback-registration-expander-system-jobs-waiting-for-resources/

Hope it helps..

Advertisements

How to – use booking rules for validation checks in Dynamics 365 Field Service


Through booking rules, we can specify custom JavaScript methods, that can be used to run validation checks, before creation or update of a bookable resource booking record. Based on the result of the validation checks we can either warn the user or cancel the booking create or update event.

Booking rules are triggered when a resource is booked or a bookable resource booking record is either created or updated using the schedule board, schedule assistant, or booking form.

The booking rules are not triggered if the booking form has business process flow enabled. We can also disable the booking rule to be triggered on the save of the booking form by enabling the setting – msdyn_DisableProcessBookingRulesOnSaveBookingForm

Let us see it in action.

Below is our JavaScript method to be used as a Booking Rule.

function Validate(sbContext) {
  
    var url = Xrm.Page.context.getClientUrl();
    var ruleResult = {
        IsValid: false,
        Message: '',
        Type: 'error'
    };
  
    var isScheduleBoard = sbContext.newValues.ResourceScheduleSource;
    var isUpdate = sbContext.isUpdate;

    if (isScheduleBoard === '690970001' && isUpdate === true) {
        ruleResult.IsValid = false;
        ruleResult.Message = 'Booking cannot be updated from the Schedule Board';
        ruleResult.Type = 'error';
    }
    else {
        ruleResult.IsValid = true;
        ruleResult.Message = '';
        ruleResult.Type = '';
    }     

    return ruleResult;
}

To create a Booking Rule, navigate to Resources >> Booking Settings >> Booking Rules inside the Dynamics 365 Field Service app and create a new booking rule, specifying the web resource and the method inside it.

Let us try to update a booking from the schedule board.

This will trigger our booking rule and will pass the context object, which contains details like whether it is a create or update event, and details around old values and new values for start time, end time, resource details, etc. for that booking.

We can use these values passed in the context, fetch more details about the corresponding resource or work order, have our validation logic defined there, and finally pass the ruleResult object.

If we want to cancel the event, we can set IsValid as false, specify the error message, and set Type as an error in the ruleResult object. Similarly, if it passes the validation, we can set IsValid as true.

This is how the error message shows up, and the event is canceled inside the schedule board.

Below we can see the same booking rule being triggered from the Booking Resource Booking form.

We can deactivate the booking rule record created if we do not want it to trigger.

Get all the details here – Booking Rule

Hope it helps..

Advertisements

Force Sync users from Azure AD Security Group / Microsoft 365 Group to Dataverse environment – Power Automate


For Microsoft 365 Group we can use – List Group members action of Office 365 Group connector.

Also check – https://nishantrana.me/2022/06/23/how-to-force-user-sync-power-platform-dynamics-365/

Hope it helps..

ILMerge / Dependent Assemblies in Plugin – System.IO.FileNotFoundException: Could not load file or assembly ‘System.Memory.Data’ – Dynamics 365 / Dataverse


Recently in one of our Plugins, which was using Azure.Storage.Blobs and Azure.Storage.Common libraries to move attachments from notes to Azure Blob Storage suddenly started throwing the below exception. The Plugin had been working fine and had been deployed long back to the production environment.

System.TypeInitializationException: The type initializer for ‘Azure.Response’ threw an exception. —> System.IO.FileNotFoundException: Could not load file or assembly ‘System.Memory.Data, Version=1.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ or one of its dependencies. The system cannot find the file specified.

We raised the Microsoft Support for it and were informed that the reason for this was there was a platform update over that particular weekend to stop loading the “System.Memory.Data” assembly on the plugin server. And as we hadn’t included that assembly in our package (ILMerge), we started getting the exception.

Also as per Microsoft Docs


So the quick fix at that time was to include (set Copy Local as True) for that System.Memory.Data along with Azure assemblies.

Also now we can look into using Plugin Package to package the dependent assemblies.

Hope it helps..

Advertisements

The plug-in execution failed because the Sandbox Worker process crashed. This is typically due to an error in the plug-in code – Dataverse / Dynamics 365


Recently we got the below exception for one of our plugins.

Message: The plug-in execution failed because the Sandbox Worker process crashed. This is typically due to an error in the plug-in code. Please refer to this document: https://go.microsoft.com/fwlink/?linkid=2189390
Microsoft.Xrm.RemotePlugin.Grpc.ExceptionHandlers.SandboxFabricWorkerCommunicationException: Error communicating with SandboxFabric Worker —> Grpc.Core.RpcException: Status(StatusCode=”DeadlineExceeded”, Detail=”Deadline Exceeded”

If we refer to Microsoft Documentation below seems to be the cause of the issue in our case.

In our scenario, we had a Plugin that was Asynchronous and it was triggered on the Post Update of Work Order Service task. The plugin will fetch all the attachments (to notes associated with inspection attachments > inspection response > work order service task). There were many Service Tasks having more than 20 attachments exceeding 100 mb size total.

We were doing bulk updates which triggered the plugin creating too many requests eventually leading to that error.

Get more details – Error “Sandbox Worker Process Crashed”

Also, check – https://cloudblogs.microsoft.com/dynamics365/it/2017/02/20/microsoft-dynamics-365-online-asynchronous-service-quotas/

Hope it helps..

Advertisements