How to add an Order Product to an Order using the Barcode Scanner with Resco Mobile CRM

This article will go into how you can use the JSBridge for Resco to streamline and automate processes. This example will demonstrate how you can add Order Products to an Order just by scanning products within the CRM system. I will assume that you already know how to create custom commands and also how to call JavaScript within the Woodford Configurator.

Below is the Offline Html code which will do the following:

  1. Runs the Barcode Scanner when the Scan Command is pressed.
  2. Stores the Barcode number into a variable.
  3. Fetches the Order ID from the Order Record.
  4. Fetches the Product with the matching UPC Code using a query.
  5. Creates the Order Detail Record against the current Order with the productid we fetched and adding it with a quantity of 1.
<!DOCTYPE html>
<html lang="en" xmlns="">

    <meta charset="utf-8" />
    <title>Barcode Scanner to Order Detail</title>
    <meta http-equiv='X-UA-Compatible' content='IE=edge' />
    <meta name='viewport' content='initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no'>
    <script type='text/javascript' src='JSBridge.js'></script>

    <script type="text/javascript">
        var barcode;
        var entityid;
        var productid;
        var ordernumber;
        var quantity = 1;

            function(entityForm) {

                var entity = entityForm.entity;
                    function(res) {
                        if (!res || res.length <= 0) {
                            sayError("No barcode");
                        } else {
                            barcode = res[0];
                    function(err) {

        function storeBarCode(code) {
                function(entityForm) {
          ["productnumber"] = code;
                    ordernumber =["ordernumber"];
                function(err) {

        function fetchRecord() {
            var entity = new MobileCRM.FetchXml.Entity("product");

            entity.filter = new MobileCRM.FetchXml.Filter();
            entity.filter.where("msdyn_upccode", "eq", barcode);

            var fetch = new MobileCRM.FetchXml.Fetch(entity);
                function(result) {
                    for (var i in result) {
                        var results = result[i];
                        productid = results[0];

                        createRecord(productid, quantity);
                function(error) {
                    alert("Error has occurred " + err);

        function createRecord(productid, quantity) {
            var productRef = new MobileCRM.Reference("product", productid);
                function(orderDetail) {
                    /// <param name="orderDetail" type="MobileCRM.DynamicEntity"/>
          ['new_quantitybyseries'] = quantity;

                        function(err) {
                            if (err)
                                MobileCRM.bridge.alert("Product has been added to Order '" + ordernumber + "'");


The first thing you need to do is add the UPC Code to the products you wish to scan. In this case we are using the ‘Lithium Battery’. You can find these numbers under any old barcode.

I have created a new Order within my CRM and now I want to start scanning my items. Within my Order form on the Field Service App, I will tap the top right button with the 3 lines.

I have named my new custom command as ‘Scan’. I will go ahead a tap on this command to run the barcode scanner.

I scanned the barcode and my JavaScript has thrown me a message confirming that an order product has been added to my Order.

As you can see, the Lithium Battery has been added to my Battery Order.

Here are the details of that Order Product.

I hope you have found this post helpful. Go ahead and take my sample code and expand it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *