Friday, December 31, 2021

D365 CE Field Service Mobile Tips: How fix CSS not loading issue in FS Mobile web resources

 

Microsoft recently introduce new their new field service mobile app and planned to retire their Resco based mobile app on June 2022. In new Field Service mobile app has set of limitations and documented them in following Microsoft document

https://docs.microsoft.com/en-us/dynamics365/mobile-app/mobile-offline-capabilities

According to the documentation CSS are not fully supported in offline mode.

How to fix: You have to add all CSS code in line with HTML to render CSS correctly in mobile offline mode.

Sunday, September 27, 2020

D365 CE Mobile Tips: Capturing image using D365 Mobile

 Microsoft provides a set of client APIs which can use to implement device-specific functionalities in D365 Mobile. Those client APIs provide device-specific functionalities like Capture Audio, Capture Image, Capture Video, Scanning Barcodes, Get Geo Position, and Upload Media File. Since D365 Mobile available on almost all major mobile platforms accessing device-specific functions may require native mobile programming. However, if developers use Microsoft provided client APIs then they can get rid of device-specific programming and implement device specific functionalities in Unified Interface with help of Microsoft XRM Client. For more details about XRM.Device APIs please refer to MSDN article.

 https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-device

 In this blog post will discuss how to use “Xrm.Device.captureImage” APIto capture images from the mobile devices and attached them as an annotation.

There are few image options that can set before capturing an image.

  • allowEdit– If this flag set to yes then the user can edit the image before confirming it. We experienced some issues in Android and will mention them below                
  • height– This will allow users to crop the image after its taken                
  • width –same as the height, the user can crop the captured image.
  • preferFrontCamera– if this flag set to yes then the system will switch to the front camera to capture image                
  • quality– this is a percentage that controls the quality of the image. Value should between0 to 100.

Following code will trigger as a result of button click in custom HTML file added as web resource in Unified Interface form.

function CaptureImage(event) {
    var parentRecordId = event.currentTarget.id;
    var fileName = parentRecordId + ":" + new Date().toLocaleString();
    var Client = globalContext.client.getClient();
    if (Client.toLocaleLowerCase() == "mobile") {
        var imgOptions = {};
        imgOptions.allowEdit = false;
        imgOptions.height = ImageHeight;
        imgOptions.width = ImageWidth;
        imgOptions.quality = ImageQuality;

        Xrm.Device.captureImage(imgOptions).then(
            function (imgData) {
                if (imgData != null && imgData != undefined && imgData.fileContent != null && imgData.fileContent != undefined && imgData.fileContent != "") {
                    var dataUri = imgData.fileContent;                    
                    var annotation = {};
                    annotation.documentbody = dataUri.replace("data:image/png;base64,", "");    
                    annotation.mimetype = "image/png";    
                    annotation["objectid_new_picture@odata.bind"] = "/new_pictures(" + parentRecordId + ")";
                    annotation.subject = "Attached Image : " + new Date().toLocaleString();
                    annotation.filename = fileName;
                    
                    //Create annotation using XRM
                }
            },
            function (error) {
                if (error != null && error != undefined && error != "" && error.message != null && error.message != undefined && error.message != "") {
                    Xrm.Navigation.openAlertDialog({ confirmButtonLabel: "Ok", text: error.message });                    
                } else {
                    Xrm.Navigation.openAlertDialog({ confirmButtonLabel: "Ok", text: error });
                }
            });
    }
}


As mentioned earlier, we end up with permission issue in Android when we set height, width, and allow edit image options (please refer below screenshot). Even we allow access camera, storage, and relevant components D365 client still popping up the same error. Once we removed image options it starts working without any issue. 



Once you remove image options from code then code will looks like following

function CaptureImage(event) {
    var parentRecordId = event.currentTarget.id;
    var fileName = parentRecordId + ":" + new Date().toLocaleString();
    var Client = globalContext.client.getClient();
    if (Client.toLocaleLowerCase() == "mobile") {
        Xrm.Device.captureImage().then(
            function (imgData) {
                if (imgData != null && imgData != undefined && imgData.fileContent != null && imgData.fileContent != undefined && imgData.fileContent != "") {
                    var dataUri = imgData.fileContent;                   
                    var annotation = {};
                    annotation.documentbody = dataUri.replace("data:image/png;base64,", "");   
                    annotation.mimetype = "image/png";   
                    annotation["objectid_new_picture@odata.bind"] = "/new_pictures(" + parentRecordId + ")";
                    annotation.subject = "Attached Image : " + new Date().toLocaleString();
                    annotation.filename = fileName;
                   
                    //Create annotation using XRM
                }
            },
            function (error) {
                if (error != null && error != undefined && error != "" && error.message != null && error.message != undefined && error.message != "") {
                    Xrm.Navigation.openAlertDialog({ confirmButtonLabel: "Ok", text: error.message });                   
                } else {
                    Xrm.Navigation.openAlertDialog({ confirmButtonLabel: "Ok", text: error });
                }
            });
    }
}


This work in both online and offline modes also both Android and iOS.

Saturday, August 22, 2020

D365 CE Tips: Enabling Mobile offline for users

 Microsoft provides details guide how to setup unified interface app for mobile and enabling offline capabilities. Please refer following Microsoft Document for setting up mobile capabilities for D365 CE.

 https://docs.microsoft.com/en-us/dynamics365/mobile-app/overview

However even after you complete all the steps users may not be able to enable offline capabilities of mobile CRM app. The main reason for that issue is, users may not have their offline profile configured in their user record. To fix that issue, you have to set Mobile Offline Profile for respective users. Following image shows how setting up Mobile Offline Profile for user.

After setting offline profile users should refresh their D365 Mobile app. After refreshing they can use D365 offline capabilities.




Friday, July 31, 2020

D365 CE Tips: Determine Mobile or Web in D365 CE using JavaScript

If you work with both CE Web and Mobile using Unified Interface, you may need to distinguish mobile client and web client inside your custom JavaScript. For example if you use single web resource for both CE web and CE mobile you have to distinguish both platforms to change your logic according to the platform.

Following code snippets will help you to distinguish platform based on the scenario.

Using GlobalContext

var globalContext = Xrm.Utility.getGlobalContext();
var Client = globalContext.client.getClient();


Using ExecutionContext

var Client = executionContext.context.client.getClient();

Value of Client variable will be “Web” or “Mobile” based on the platform. Hope this tip will be help. Enjoy 😊

Saturday, July 18, 2020

Resco Tricks: How to Fix Offline HTML Files not Updating issue in Resco Woodford Projects

If you use derived (hierarchical) Resco Woodford projects you may experience some time files are not updated even after you published all solutions. This article will help you to identify possible issues and resolve them.

For more details about Resco Woodford derived projects please refer following link


Scenario:
We have derived project structure like following
MSFieldService -> Survey -> ClientCustomizations


We have offline html file called “ReadOnlySurvey.htm” in survey solution. Due to an urgent production issue, development team replaced that offline html file directly in client customization Woodford project (top most project). However, in next production release development team deploy Survey Woodford project but after deployment they observed “ReadOnlySurvey.htm” file didn’t update and it did not contains all the changes did in development phase.


How to fix this issue:
Once offline html file manually override in the top most project without its own project, Woodford did not apply changes came through its original project any more. To apply changes from root project to top most project, files should be in “Inherited” state not in “Overridden” state.


To fix that before you import your root project (Survey project) to Resco, you have to restore the files you overridden before.
First you should open Woodford project which contains file you overridden before (in our case “ClientCustomization” project). Then select the relevant files and click restore button in the Woodford ribbon and save. Then system will restore the file from its root project. Then you can import your project (in our case Survey project) and publish them all.


This will fix your issue and apply changes to relevant files.