As a Dynamics AX Upgrade Factory and ISV Development Center we encounter various questions and concerns from Microsoft Partners surrounding mobile device developments. As a result, we’ve created a four-part blog series to address the most common questions, concerns and share WHS mobile device development best practices. In part 1 we’ll be discussing how to replace or insert field values.

Throughout the development of a warehouse mobile device, the need to automate standard processes is quite common. Typically, this means that you need to auto-fill a field in a mobile device. In the first part of our Dynamics 365 Finance and Supply Chain Management WHS mobile device series, we’re going to investigate this task to determine the best practice approach.

Empty mobile device field that can be automatically filled

Extend WHSWorkExecuteDisplay.displayForm() method

The first step in order to successfully insert or replace mobile device data is to implement your functionality after the WHSWorkExecuteDisplay.displayForm() method. This method is important as it’s the core of mobile device framework and it’s responsible for all logic needed for a particular step. It receives a container sent by a mobile device which is then processed and a response container is created. This is basically the last place where the container that will be sent to the mobile device is modified so it’s the ideal place to modify it and insert a field value.

We are unable to extend the WHSWorkExecuteDisplay.displayForm() method since it is an abstract method and these cannot be extended. To get around this, it’s important to figure out which process you need to implement your changes to and then find its child class (for example WHSWorkExecuteDisplayUserDirected). Once you’ve figured that out, then you should implement some logic to determine if it is a correct time (step) to enable your functionality. After this, you can modify the returned container by finding the correct control and setting its data element.

In this example we will set the license plate value to ‘ReplacementData’:

[ExtensionOf(classStr(whsWorkExecuteDisplayUserDirected))]

final class TestWHSWorkExecuteDisplayUserDirectedDataReplacement_Extension

{

    container displayForm(container _con, str _buttonClicked)

    {

        #WHSRF

 

        boolean   canReplace;

        container returnedCon;

       

        // Parameters might vary according to your requirements

        canReplace = TestHelper::replaceFieldValue(pass, _con, step, workLine);

 

        returnedCon = next displayForm(_con, _buttonClicked);

 

        if (canReplace)

        {

            int lpIndex = this.indexOfBuildControlFromContainer(returnedCon, #WHSWorkLicensePlateId);

 

            // Check if needed control exists

            if (lpIndex > 0)

            {

                //insert your data for the field

                returnedCon = this.setControlDataFromContainer(returnedCon, #WHSWorkLicensePlateId, 'ReplacementData');

            }

        }

 

        return returnedCon;

    }

}

 

class TestHelper

    // Do a check according to your specification

    public static boolean replaceFieldValue(WHSRFPassthrough _pass, container _con, int _step, WHSWorkLine _workLine)

    {

        boolean ret;       

 

        if (_pass && _pass.hasValue(#MenuItem) && _pass.exists(#BatchVerification) && _pass.lookup(#BatchVerification) == ''

            && !_pass.exists(#TargetLicensePlateId) && _step == #Pick)

        {

            const int BV = 10;

 

            WHSRFMenuItemTable  menuItemTable = WHSRFMenuItemTable::find(_pass.lookup(#MenuItem));

            InventBatchId       batchId       = conPeek(conPeek(_con, BV), #data);

            Name                elementName   = conPeek(conPeek(_con, BV), #name);

 

            ret = menuItemTable.TestReplaceLPData == NoYes::Yes && elementName == #BatchVerification && batchId != '';

        }

        else

        {

            ret = _workLine && WHSWorkLine::isPutBefore(_workLine.WorkId, _workLine.LineNum);

        }

       

        return ret;

    }

}

 

We hope you’ve found these insights useful and are feeling more confident when it comes to replacing or inserting field values in your mobile device developments. Don’t hesitate to get in touch by emailing the team at: services@1ClickFactory.com if you have any questions.

Stay tuned for the next blog in this four-part series on Dynamics 365 Finance and Supply Chain Management WHS mobile device development tips.