MicroStrategy ONE

Trigger Document or Report Execution Via a Barcode Scan from an Android Device

Retail store managers and other employees may use a barcode scanner, such as Zebra, to check prices and other information about their retail products. You can customize MicroStrategy Mobile SDK to trigger the execution of a document or report when a retail product is scanned. When you scan the barcode, you apply a prompt answer to run the target document or report. This allows you to view additional details regarding that specific retail product within your document or report.

An example of using a Zebra barcode scanner to trigger document or report execution is illustrated below.

Enable Document or Report Execution Via a Barcode Scan

  1. In your Android SDK project, open the bools.xml file under main/res/values.
  2. Add the setting shown below to enable the functionality.

    Copy
    <!-- bool to enable/disable auto apply a new value prompt answer received through our public API -->
    <bool name="auto_answer_value_prompt">true</bool>

  3. Add the setting shown below to specify whether to hide the barcode scan icon on the prompt page.
  4. Copy
    <!-- bool to hide the clickable camera icon when auto answer value prompt is available -->
    <bool name="hide_camera_scan_icon">true</bool>

Create a JSON File to Specify Parameters for Document or Report Execution

This section illustrates how to set up your configuration to specify the target document/report and source document/report ID, as well as how to pass prompt selectors. An example JSON file is shown below. Using this configuration, the target document or report executes automatically when a user scans a product in a source document or report.

  1. In your SDK project, navigate to src/main/res/raw.
  2. Create a JSON file, similar to the one below, and name it link_config_on_value_prompt_new_answer.json.

    Copy
    [
        {
            "project_id": "C5F83622485CEAE876F3859C6094C49E",
            "source_ids": ["5382FB2E4B81A8CD4EAC3289B5BE269F", "5C34E3BD44D1F6A9B49DBC963C0FA8E0"],
            "target_id": "56B90BB9451848EA2678CBB56D15DC55",
            "target_prompt_id": "C2DEA1D244B96595AD4D0691920967FE",
            "pass_answers": true,
            "selector_mode": 1
        }
    ]
  3. Update the key/value pairs in the JSON file.

    Key Description Data Type Required?

    project_id

    The project ID of the source and target document/report. Your source and target document/report must be in the same project.

    string

    yes

    source_ids

    The ID of the source documents/reports that run the target document/report. Use an array of IDs surrounded by brackets.

    JSON array

    no

    target_id

    The ID of the target document/report that runs automatically.

    string yes

    target_prompt_id

    The ID of the prompt that receives the passed data. If there is no target_prompt_id, the first value prompt in the target document/report is used.

    string

    no

    pass_answers Specifies whether to pass prompt answers from the source to the target. The default value is false. bool no

    selector_mode

    0 - Selectors are not passed. This is the default value.
    1 - Match selectors by source attribute
    2 - Match selectors by control name

    If selector_mode is set to 1 or 2, the pass_answers value should be set to true.

    int

    no

Create the Ability to Trigger Document or Report Execution with a Barcode Scan

You can trigger document or report execution by calling the following API method exposed in the MstrApplication class, if value prompt answers are set to apply.

Copy
/**
 * handle new value prompt answer that should be applied, this is a public API for SDK project.
 * The new answer could be from different sources, such as infra-red hardware.
 * @param newAnswer the data to be applied as new answer
 */
public final void handleNewValuePromptAnswer(String newAnswer) 

The steps below illustrate how to trigger document or report execution by a barcode scan from a Zebra device when the barcode data is received as a prompt answer.

  1. Create a new DataWedge configuration for the device. This allows you to get scanning results through DataWedge.
  2. Create a customized application object that extends from MstrApplication and add customized logic to call the handleNewValuePromptAnswer API.

    In the code sample shown below, the Zebra system sends a broadcast with the barcode data as a new answer for prompts when the barcode is scanned.

    Copy
    public class MyApplication extends MstrApplication {
        // the EXTRA_INTENT_ACTION_NAME should be same as the action name defined in custom DataWedge configuration in zebra device
        private static final String EXTRA_INTENT_ACTION_NAME = "com.microstrategy.android.scan";
        private static final String EXTRA_DATA_STRING_NAME = "com.symbol.datawedge.data_string";
        @Override
        public void onCreate() {
            super.onCreate();
            // register a receiver to listen Zebra system broadcasts.
            ContextCompat.registerReceiver(this, new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            String newAnswer = intent.getStringExtra(EXTRA_DATA_STRING_NAME);
                            //TODO: SDK app can do some validation on the newAnswer to avoid always invoke the below API when unnecessary.
                            handleNewValuePromptAnswer(newAnswer); // call public API to handle new answer
                        }
                    }, new IntentFilter(EXTRA_INTENT_ACTION_NAME),
                    ContextCompat.RECEIVER_EXPORTED);
        }
    }
  3. Make sure the action you configure in the profile equals the action of the intent filter when registering the broadcast receiver. If you have other sources for prompt answers besides barcode scans, you can write code to retrieve new answers and then call the handleNewValuePromptAnswer method.

  4. In Androidmanifest.xml, look for the application tag that contains android:name.
  5. Replace the application class with the CustomApplication you previously defined.

    Copy
    <application android:name="com.microstrategy.android.MstrApplication"..>