Sunday, April 14, 2019

Dynamic CRM Unified Interface Tricks – Retrieve data parameters in web resources

As all of you know Microsoft announce “getQueryStringParameters()” function is deprecated (https://docs.microsoft.com/en-us/dynamics365/get-started/whats-new/customer-engagement/important-changes-cominghttps://docs.microsoft.com/en-us/dynamics365/get-started/whats-new/customer-engagement/important-changes-coming) and they asked to use form context instead of passing parameters. However if you use single web resource with multiple parameters in multiple places (multiple entities or multiple fields in same form) you have to depend it on parameters or have to have mechanism to distinguish execution context. 

We face similar kind of issue, we have single web resource as data inputs for different fields. Each field has different properties and based on that web resource behavior should change. Previously it completely handled by parameters and once “getQueryStringParameters” become obsolete we have to move to some other solution.


We follow following approach and it will reduce our amount of code change.

  • Get the current window URL
    • Using “this.URL” can retrieve current url of the web resource without accessing window object.
  • Set Parameters in form
  • In current situation we defined field name as parameter to distinguish what the field current web resource is referring to


    • Decode url and remove data component from the url
    • Then use regex based function to extract query string (function taken after google search :) ). 
    You can place following code snippet on page on load or inside relevant functionality.

     if (this != null && this != "undefined")
    {
        var decodedUrl = decodeURIComponent(this.URL);
        decodedUrl = decodedUrl.replace("data=",'');
      
        var parameterValue = getQueryString("FieldName", url);  
    }

    function getQueryString ( field, url ) {
        var href = url ? url : window.location.href;
        var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
        var string = reg.exec(href);
        return string ? string[1] : null;
    };

    Saturday, March 2, 2019

    Dynamics CRM Field Service Journey 4 – Automate IoT Alerts to Work Orders using Microsoft Flow

    Connected field service is come in handy if your company use IoT devices to monitor larger machineries or factories etc. Using connected field service so many things you can achieve.

    For example: If company selling cooling system then they can integrate IoT device within it to monitor the cooling measurements and alert if cooling system failures. Once system install in customers facility it will become customer asset and selling company need to do regular maintenance and also repair the cooling system if it has some failures. In old days human interaction is highly involving with such failure checks. There are technicians who visit cooling system facilities daily or hourly and monitor status and report it. In IoT era those daily routine checks did automatically without human interactions. Modern IoT devices are more capable than their early stages. There are some IoT devices can perform some specific tasks rather than working as reporter. Dynamic 365 Field Service use that capabilities to maintain customer assets remotely. Using Connected Field Service users can monitor output from the IoT devices and perform some basic checks of some actions like reset cooler fan speed etc. In Dynamic CRM it records those IoT readings in IoT alerts. There is no inbuilt IoT alert to work order conversion process in connected field service. We can use Microsoft Flow to fulfil that requirement.


    Steps to create Microsoft Flow to automate IoT alert to work order
    In following scenario we use IoT device located in cooling system and it communicating with CRM via connected field service. Company need to check content of the IoT alert and make decision based on the temperature it reports and create work order

    Step 1: Choose record creation trigger from MS Flow and configure it to trigger when IoT Alert record create









    Step 2: Use data operation called “Parse JSON” to parse Alert Data in the IoT alert record. After parsing the data you can use properties of the data to check the conditions. In this case I use reading value and if that value exceed 90 I will create work order automatically.
    Parse JSON provide capability to generate schema using existing data. You can copy paste existing Alert data from CRM and generate schema from it. 


    You can search json in action search box and it will show the Parse JSON action in Actions pane.



    Extract JSON from IoT Alert record




    Used that JSON to generate schema


    Note: In this case it generate schema for Reading and Threshold properties as integer but it is not integer. I have to change them to number instead of integer

    Step 3: Use condition to check reading value and retrieve relevant data to create work order
    Check reading value is exceed 90 or not.




    Step 4: Generate Work Order

    To generate work order you need following mandatory information. Based on your requirement you can fill more fields in work order record.
    We filled following fields


    • Service Account – Extract from Customer Asset record
    • Work Order Type – Extract from CRM
    • Incident Type – Extract from CRM
    • Work Order Number – Generate inside Flow
    • Price List – Extract form Work Order Type record
    • System Status – hardcode inside the flow (Open Unscheduled)

    Retrieve Customer Asset Record using IoT alert

    Retrieve Work Order Type record – retrieve work order type named “Install or replace” this can change based on requirement


    Retrieve Incident Type record - retrieve incident type named “Unit Overheating” this can change based on requirement



    Generate Work Order number – this should be unique number to the system. For demonstration we simply retrieve all work orders and count them but it will be a performance hit in live environment. You can use work orders with prefix to identify the customers and IoT alerts. However if you create work order from CRM it will auto generate number for you it is unfortunate it will not filled when you creating it via API or Flow.

    There is a blog post describe how to count records and please refer that for more information


    Dynamics CRM Field Service Journey 3 – Get Records Counts using List Records action in Flow


    Generate work order using previously retrieved data

    You can fill relevant lookup data using previously retrieved records like following example show how to fill price list from work order type. If your field is not showing in the list you can click on show more and set the field


    Completed work order





    Monday, February 25, 2019

    Dynamics CRM Field Service Journey 3 – Get Records Counts using List Records action in Flow

    When field service IoT Alert automation we create work order automatically using MS Flow without coding. In that record creation implement mechanism to set work order number (number should be unique) by Flow. We retrieve existing work orders list based on filter criteria and generate work order number based on the number of records retrieved by list action.

    Follow following steps to get count of records using List records control



    Note: User can change filter condition to meet requirement otherwise flow will become less performance if retrieve all the work order records

    Use Length function on lookup records body values then add 1 to get next number


    add(length(body('Get_Last_Work_Order_Number')?['value']),1)



    How to automate IoT Alert to work order will be posted in next blog post

    Saturday, February 16, 2019

    Dynamics CRM Field Service Journey 2 – Fix “lack of permission, In order to use an Azure subscription” issue

    When we start configuring connected field service it needs Azure subscription to retrieve messages from IoT devices and after run the logic app it will create appropriate work orders to continue work in CRM.

    There is descriptive installation steps for connected field service in following link.

    Beginning of the connected field service: https://docs.microsoft.com/en-us/learn/modules/get-started-with-connected-field-service/1-connected-field-service-overview

    Setting up azure subscription: https://docs.microsoft.com/en-us/learn/modules/get-started-with-connected-field-service/3-install-connected-field-service


    There are two different options in the Azure subscription setup window,

           1. Configure existing Azure subscription: In this configuration you can use your existing Azure subscription for connected field service

           Tip: when adding existing subscription: use account in “onmicrosoft” tenant otherwise it will give you error message your account is not in onmicrosoft tenant.


            2. Create Azure subscription using onmicrosoft account and use it for connected field service
    Most of trial users use this method to create azure subscription and use it for connected field service.

             In this method you have to create azure subscription using onmicrosoft account which used for Dynamic CRM.

    When you setting up the azure subscription you may end up with following error message

    “Lack of permissions. In order to use an Azure subscription to deploy Connected Filed Service solution you need to have Owner access level”




    How to setup Azure subscription to use for connected field service. There are several ways to add ownership to the Azure subscription. You can follow following steps to configure ownership before configuring connected field service

    Step 1: Go to Azure portal (https://portal.azure.com/) and create free account using your onmicrosoft account


    Step 2: Start trial – go the Azure portal and then Security Center (left menu) then go the “Getting started” and click on “Start trial” button




    Step 3: Install Agents – After you start trail you can see there is another tab enable getting started called “Install Agents” (if you cant see the tab refresh and navigate back). Select your subscription and click on “Install agents” button.



    Step 4: Go to Identity & Access – After install agents refresh the page and go to "Security Center" then "Identity & Access (preview)"




    Step 5: Click on “Designated more than one owner on your subscription” then click on “Free Trial





    Step 6: Then click on “Role assignments” tab and click on “Add” button. Then select “Owner” as role and select your account as member then “Save”.



    Step 7: Then go back to connected field service wizard and select your CRM organization, then select Azure subscription after that select “Resource group location” and give “Resource group name” and complete the setup.








    You can complete device registration after following Microsoft tutorial in below link.

    https://docs.microsoft.com/en-us/learn/modules/get-started-with-connected-field-service/1-connected-field-service-overview

    Monday, February 4, 2019

    Dynamics CRM Field Service Journey 1 – Change Field Service Mobile Filters

    Dynamic CRM field service has rich mobile component which helps users who need mobility like maintenance service employees. They can install Dynamic CRM Field Service mobile app on their mobile and perform most of the field service related tasks using mobile device such as complete work orders, get customer signatures, create follow-up tasks/work orders etc. Field service mobile app facilitate users to use it in both online and offline. After user add relevant credentials and sync with Dynamic CRM it load relevant data in to the mobile local storage. Then users can perform their actions in offline mode as well. That helps users who travel and working on-site.


    Field service mobile app completely based on the Resco Mobile CRM and they use woodford project to store mobile customizations. For more details about woodford projects and Resco Mobile CRM visit following reference (Resco Mobile CRM: https://www.resco.net/mobilecrm/ , Woodford: https://www.resco.net/support/guides/woodford/)


    Standard Field Service mobile app is pre-customized woodford project which runs on Resco Mobile CRM platform. Standard Field Service mobile app used lots of filters to reduce the data which synced from CRM to mobile device. Sometime it may not show relevant work orders due to those filters. In such cases we have to change sync filters in woodford project. According to the latest Field Service woodford project it use following conditions filter work orders.



    1. Status = Active
    2. Word order status = Open-Unscheduled,  Open-Completed, Open-In Progress, Open-Scheduled
    3. Bookable resource booking should be in Active status
    4. Resource of the bookable resource booking should be current user (who logged in to the Field Service Mobile App)
    5. Booking status = In Progress, On Break, Scheduled, Traveling
    6. Start time should be on Today or within next 7 days
    7. End time should be on Today or within next 7 days



    Example: Users need to sync work orders based on sub status and sync work orders today or within current month (30 days). Then we have to modify the sync filters to achieve that requirement.

    How to modify the sync filters


    Step 1: Open woodford project using woodford. Resco introduce new html 5 based woodford editor and they keep their old siverlight based woodford editor as well. You can navigate to the woodford in following way.


     Navigate to the CRM Settings and navigate to the Mobile CRM section then woodford










    I used legacy woodford editor in rest of the configurations users can use one of these editors for project editing.





    Step 2: Navigate to work order entity and open Sync Filter








    Step 3: Using Add condition you can add the condition (Tip: before you click on add condition select existing condition then it will place to the correct place). You can perform delete unwanted conditions, group conditions, change existing conditions and may more actions. After you complete the changes you have to save the filter














    Step 4: Publish the project. You have to instruct the users re sync again after you did the modifications to the project otherwise it will not affect (if there are any sync errors you have to delete data and sync again)


    Tip: If you have any other filtering issues you can follow same steps to change those filters as well