Multiple barcode scanning in Now Mobile, not sending to WriteBackAction (Utah)

Paul Hegel
Mega Guru

I’ve developed several different Mobile App Builder Functions to scan barcodes.  I’ve successfully developed a function to consume inventory from the alm_consumable table. Using a single input of type Barcode and that is working.

Example Code in WriteBackFunction:

(function WriteBackAction(parm_input, parm_variable, actionResult) {

    // get input values

    gs.info('Consume Inventory Function: parm_input = ' + JSON.stringify(parm_input, null, '\t'));

 

})(parm_input, parm_variable, actionResult);

 

This is the output of the function in the system logs:

Consume Inventory Function: parm_input = {
"stockroom": "32c1ffd51bf17110a95611f8bc4bcb72",
"quantity": "1",
"site_location": "dc8f4ef4db6f8c50f76bda75ca961970",
"barcode": "CPM0003194"
}

The first method that I tried:

Configuring my Consume Multiple Barcodes function I used this reference: Configure input form screens with grouped scan barcode inputs (servicenow.com)

My configuration:

PaulHegel_0-1708713483563.png

 

 

Input form section:

PaulHegel_1-1708713483566.png

 

PaulHegel_2-1708713483567.png

 

Result

  1. that the barcode scanning works and will scan multiples barcodes:PaulHegel_3-1708713483573.png

     

    PaulHegel_4-1708713483575.png

     

    PaulHegel_5-1708713483576.png

     

  2. It appears to carry values back to main form:
  3. However, the submit doesn’t send all the input values.

 

Using this same code in my Consume Multiple Function:

(function WriteBackAction(parm_input, parm_variable, actionResult) {

    // get input values

    gs.info('Consume Multiple Function: parm_input = ' + JSON.stringify(parm_input, null, '\t'));

 

})(parm_input, parm_variable, actionResult);

 

I get this which is missing barcodes:

Consume Multiple Function: parm_input = {
"quantity": "1",
"stockroom": "3beabf471bbbf110a95611f8bc4bcb70"
}

Based on the documentation I’d expect it to look like this:

Consume Multiple Function: parm_input = {
"barcodes": {"inland_barcode": ["CPM0003647", "CPM0003647"]},
"quantity": "1",
"stockroom": "3beabf471bbbf110a95611f8bc4bcb70"
}

Then second I tried this method:

 Configure a grouped input for multiple scans (servicenow.com)

PaulHegel_6-1708715353275.png

 

But the barcode inputs did not show on  the Input Form Screen.  But the input shows up after I click submit.  The functionality appears to work ,  and it has the same output to the log files.

1 ACCEPTED SOLUTION

Paul Hegel
Mega Guru

My solution is to move away from using the Mobile version for multiple barcodes scanning and move to using portal pages/widgets and the cabrillo.getBarcode() methods and GitHub Example: K17-Service-Portal-And-Mobile/Lab 2/K17 Barcode Scanner.

I expanded on this concept, but the nice part is that you have control of scanning multiples using your widget code.

This only works in ServiceNow native mobile applications.  You can use the cabrillo.isNative to see if the page is just that a ServiceNow Mobile application (Now Agent, Now Mobile).

 

I added an array to the client side that captures multiple.  Once I've completed my code I'll try to put my example on GitHub.  

 

Note that a user could have a regular barcodes scanner which acts as keyboard entry, or they might only have the camera on their phone.  Cabrillo uses the camera on your phone to scan barcodes.

 

Thanks,

Paul

View solution in original post

6 REPLIES 6

Hi Paul, interesting to hear about using the newer cabrillo API for this.

I'm struggling with my own barcode scanning issue https://www.servicenow.com/community/mobile-apps-platform-forum/can-a-list-of-scanned-barcodes-be-ed...

Are you keeping users within the agent mobile app? Or are you running this in a web browser.

I'm struggling with what I consider a pretty simple ask, of editing the list of scanned assets if an error is thrown. I'd just like the barcodes which threw an error kept, which the user can then use to correct/rescan.

I'm trying to figure out if the actionResult object can help me, but the only documentation I can find is regarding actionResult.addAttachment or actionResult.setRedirectionInfo

How're you getting on with your work, anything you could share?

@Thomas Wright,

I've been able to complete my code and have a function mobile app that does multiple barcode scanning and keeps track of the list of scanned items.  I've made it work for a barcode scanner as well as for the using the Cabrillo framework.  I'm using the native Cabrillo in the Now Mobile custom application that uses a Page/Widget on our Inventory portal.  Here are a couple screenshots of the configuration:

NowMobile_Inventory_Configuration.png

As you can see, we have multiple icons that point to Mobile Web Screens component.  Here is how our Consume Inventory configuration that points to the inventory portal using the barcode page with a type of consume.  We use the same page to do consuming as well as reconciling inventory.

NowMobile_Inventory_Consume_Configuration.png

  

I only use the cabrillo to add the buttons as well as accessing the camera on the mobile device to do the barcode scanning.  Here is some of my Client Script code from my widget:  

    c.isNative = cabrillo.isNative();

    cabrillo.viewLayout.setBottomButtons([{
        title: 'Scan Code',
        enabled: true,
        backgroundColor: '#2d86d5',
        textColor: '#FFFFFF'
    }, {
        title: c.data.type + ' Items',
        enabled: true,
        backgroundColor: '#005EB8',
        textColor: '#FFFFFF'
    }], function(btnIndex) {
        switch (btnIndex) {
            case 0:
                c.getBarcode();
                break;
            case 1:
                c.submitItems();
                break;
        }

    });
    c.getBarcode = function() {
        cabrillo.camera.getBarcode().then(function(value) {
            c.data.entered_barcode = value;
            c.addBarcode();
        });
    };

This is only some of my code, but this should be enough to get you going.  The addBarcode function sues the entered_barcode to add to the barcode to a list on the page.  You might be able to do the same only capturing your error in the list. 

Hope this helps.