# startScanner

App allows users to scan barcodes or QR codes with **startScanner** function. It takes two parameters: control id, it is used to identify on which control the code value will be assigned, and options object in which we pass the boolean value for continuous mode. Continuous mode, if true, provides the ability to keep the scanner open after reading code otherwise it will close. The process of reading codes consists of two steps. First step is to use this function. This function needs to be placed under a "Scanner" or "Wedge scanner" controls. When an event is triggered, this function will be called and it will access the camera of the device(if available). Now when it will read a code, this value will be assigned to scanner control in an app. In the second step, we can use this value by using **getFieldValue** function . It will be used to identify the object depending upon the code and a value Starts scanning QR or barcodes with the given scannerControl.

```javascript
   app.startScanner("myScannerControl");
```

## Parameters

1. controlId(String) - The control id of the scanner control (Check scanner control properties in an app).
2. scanOptions(JSON Object) - This is a json object with the scanner parameters(Used to specify the scanner functionality):
   * continuousMode(Boolean - Optional - Default: false) - If true, it will keep the scanner open, after reading a code.

## Example Usages

### Start scanner with JSON options

```javascript
   app.startScanner("myScannerControl", {
      continuousMode: true
   });
```

Here we are scanning a simple bar code with a value of '12345678'.

![Picture of a scanner control](https://4275956601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOvU7jyPAQ0DefSlDf98E%2Fuploads%2Fgit-blob-4ec98751eb5793a4ceb63830c5e2311142dd3006%2Fimage_scanner_1.png?alt=media)

After scanning the code successfully, the value will be assigned to the scanner control present in current app. Now there are many ways to use this value e.g conditionals (if statements). For this tutorial, we will just show the scanned value as a notification by using the code snippet given below. As soon as the scanner scans the code it triggers an "onScan" event. In this event, we can add our customized code.

### Code when onScan Event get triggered

```javascript
   app.showMessage({
       content: app.getFieldValue("myScannerControl")
   });
```

As we can see, it is showing the scanned value of '12345678'.

![Picture of a message](https://4275956601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOvU7jyPAQ0DefSlDf98E%2Fuploads%2Fgit-blob-7320aec5b4dbece3eaad953801b8420841a444fc%2Fimage_scanner_2.png?alt=media)

### Return Values

Function does not explicitly produce return value.
