Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added note to log out to see changes in ReferenceData

Description

Excerpt

The most common control for customization. Adding

Add a new function with to the Main menu. "Header fields" and optional "Steps" to collect info based on the header request.

Note: "Unplanned Item Registration" is also known as "Adhoc". In the following, we will refer to it as "Unplanned".

Prerequisites

Please read up Unplanned Functions to ensure this flow suits your requirement.

This example

  • Will result in an Unplanned function accessible by an icon on the Main Menu.
  • Three : A date, a text and a decimal.
  • And three similar Steps

    This example gives you

    The unplanned workflow

    Make sure the Unplanned Workflow fits your requirement.


    Step 1: Defining a new Unplanned function 

    This part requires you to edit the Mobile Configuration Files


    Add this section in the <pages> tag.

    Code Block
    languagexml
    themeEclipse
    <!-- Custom -->
      <page id="MyUnplanned" type="UnplannedItemRegistration" icon="mainmenusettings">
        <title defaultValue="Titletext"/>
        <unplannedItemRegistrationConfiguration type="MyUnplanned" useRegistrationCollector="false">
          <header configurationKey="MyHeader" automaticAcceptOnOpen="true"/>
        </unplannedItemRegistrationConfiguration>
      </page>
    <!-- Custom -->


    Add this section to the <menuItems> tag.

    Code Block
    languagexml
    themeEclipse
    <!-- Custom -->
    <menuItem id="MyUnplanned" displayName="MyUnplanned" icon="mainmenusettings" alwaysEnabled="true"/>
    <!-- Custom -->


    Do you want this to be accesible from an existing page in the Action Menus

    Then add this section to the <actions> tag.

    Code Block
    languagexml
    themeEclipse
    <...>
    <actions>
      <!-- Custom -->
      <open icon="mainmenusettings" id="MyUnplanned" title="My Unplanned">
        <returnTransfer property="UnplannedItemRegistrationCompleted" to="RefreshOnResume"/>
      </open>
      <!-- Custom -->

    Step 2: Define Header and header fields

    Unplanned functions uses Header to determine which Steps to collect.

    In this step you must define which header fields you want the user to see.

    Subscribe to this event

    OnGetReferenceData_OnAddHeaderConfigurations

        // Step 2: Define Header and headerFields

        [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddHeaderConfigurations''', true, true)]
        local procedure MynGetReferenceData MyGetReferenceData_OnAddHeaderConfigurations(var _HeaderFields: Record "MOB HeaderField Element")
        begin
            _HeaderFields.InitConfigurationKey('MyHeader')// Identifier for new Header - replace by your own name

            // Add Header fields here
            _HeaderFields.Create_DateField(10'MyDate''Select date');

            _HeaderFields.Create_TextField(20'MyText''Enter text');
            _HeaderFields.Set_optional(true);

            _HeaderFields.Create_DecimalField(30'MyDecimal''Enter decimal');
        end;


    You must log out and in again: Headers are static data in Reference Data, meaning it is only sent to mobile during a login.


    Step 3: Return Steps to collect (Optional)

    When the header is accepted a new request is made for which Steps to collect, called  "GetRegistrationConfiguration".

    In this step you must read the values header fields and define the subsequent steps.


    If you want to collect steps you must set useRegistrationCollector="true" in Mobile Configuration Files.

    Code Block
    languagexml
    themeEclipse
    <page>
      <unplannedItemRegistrationConfiguration type="MyUnplanned" useRegistrationCollector="true"> 
    <..>


    You can use the already collected header fields values for:

    • defining the steps still needed to be collected
    • setting useful default-values on the steps 

    Subscribe to this event

    OnGetRegistrationConfiguration_OnAddSteps


        // Step 3: Define Steps (optional)

        [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Adhoc Registr.", 'OnGetRegistrationConfiguration_OnAddSteps''', true, true)]
        local procedure MyOnGetRegistrationConfiguration_OnAddSteps(_RegistrationType: Textvar _HeaderFieldValues: Record "MOB NS Request Element"; var _Steps: Record "MOB Steps Element"; var _RegistrationTypeTracking: Text)
        var
            MyDate: Date;
            MyText: Text;
            MyDecimal: Decimal;
        begin
            // Handle only your own Header name
            if _RegistrationType <> 'MyUnplanned' then
                exit;

            // Read the headerFields
            MyDate := _HeaderFieldValues.GetValueAsDate('MyDate');
            MyText := _HeaderFieldValues.GetValue('MyText');
            MyDecimal := _HeaderFieldValues.GetValueAsDecimal('MyDecimal');

            // Add steps
            // For illustration, re-use the headerField value as default values on the steps
            _Steps.Create_DateStep(10'MyDateStep');
            _Steps.Set_header('MyDateStep');
            _Steps.Set_defaultValue(MyDate);

            _Steps.Create_TextStep(20'MyTextStep');
            _Steps.Set_defaultValue(MyText);
            _Steps.Set_header('MyTextStep');

            _Steps.Create_DecimalStep(30'MyDecimalStep');
            _Steps.Set_defaultValue(MyDecimal);
            _Steps.Set_header('MyDecimalStep');
        end;


    Step 4: Handle posting

    When the Header has been accepted and Steps collected, a final request is made to "Post" the information ("PostAdhocRegistration")

    In this step you must read the collected values and post them to the database.


    Run your function fra Mobile and you can inspect the Post Request directly. See How-to: Inspect View Request and Response XML documentsYou might receive an error if your subscriber is not running. and Error Call Stack

    If you fail to perform Step 3, you will this error:


    Code Block
    languagexml
    themeEclipse
    titlePost Request
    <?xml version="1.0" encoding="utf-8"?>
    <request name="PostAdhocRegistration" created="2020-02-14T15:24:24+01:00" xmlns="http://schemas.microsoft.com/Dynamics/Mobile/2007/04/Documents/Request">
      <requestData name="PostAdhocRegistration">
        <MyDate>14-02-2020</MyDate>
        <MyText>2</MyText>
        <MyDecimal>4</MyDecimal>
        <MyDateStep>14-02-2020</MyDateStep>
        <MyTextStep>2</MyTextStep>
        <MyDecimalStep>4</MyDecimalStep>
        <RegistrationType>MyUnplanned</RegistrationType>
      </requestData>
    </request>


    Subscribe to OnPostAdhocRegistrationOnCustomRegistrationType

    • Both Header values and Steps values are available.
    • The values are extracted from the _RequestValues parameter using "GetValue "functions.


        [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Adhoc Registr.", 'OnPostAdhocRegistrationOnCustomRegistrationType''', true, true)]
        local procedure MyOnPostAdhocRegistrationOnCustomRegistrationType(_RegistrationType: Textvar _RequestValues: Record "MOB NS Request Element"; var _CurrentRegistrations: Record "MOB WMS Registration"; var _SuccessMessage: Textvar _RegistrationTypeTracking: Textvar _IsHandled: Boolean)
        var
            MyDate: Date;
            MyText: Text;
            MyDecimal: Decimal;
        begin
            if _RegistrationType <> 'MyUnplanned' then
                exit;

            if _IsHandled then
                exit;

            // Read _RequestValues
            MyDate := _RequestValues.GetValueAsDate('MyDateStep');
            MyText := _RequestValues.GetValue('MyTextStep');
            MyDecimal := _RequestValues.GetValueAsDecimal('MyDecimalStep');

            _SuccessMessage := StrSubstNo('Success %1 %2 %3', MyDate, MyText, MyDecimal);
            _RegistrationTypeTracking := 'Tracking info for the Document queue.';

            _IsHandled := true;
        end;


    For illustration, the steps-values are used in the success-message


    Step 5: Set tracking info (optional)

    The parameter _RegistrationTypeTracking can be used to make the Document Queue display additional information about your process.





    Common error messages



    "No document handler is available for GetRegistrationConfiguration::XYZ"

    Error occurs when Accepting the header.

    Solution

    No steps are returned.

    See Step 3.


    "No document handler is available for GetRegistrationConfiguration:XXX/XmlSteps"

    Solution

    No steps are returned.

    See Step 3.


    "No document handler is available for PostAdhocRegistrationConfiguration::XYZ"

    Error occurs when posting.

    Solution

    Posting is not handled.

    See step 4


    Filter by label (Content by label)
    showLabelsfalse
    showSpacefalse
    sorttitle
    titleMore examples
    excerptTypesimple
    cqllabel = "bc" and label = "example" and label = "unplanned"


    Icon in Main menu

    "MyUnplanned" is shown on the main main.


    Unplanned function Header

    Header and header fields.


    Unplanned function Steps

    First step

    Second step.


    3rd and final step.


    Posting

    Posting completed.
    Message is displayed.