<SOLVED> Script needs to set Form Field,then auto save Form

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

<SOLVED> Script needs to set Form Field,then auto save Form

Post by Jaymer »

on a form, in a HTML cell, lets say I have a <SCRIPT>. and it calculates a value. Whats the best way to get that value into a field on the aware form?

I'd really like to ALSO Save the Form (automatically), now that the value is in that field.

The script gets called by a button on the form - its in a HTML cell and just calls the function that's inside the other HTML cell. Its a barcode scanner. Once a valid scan is returned, I want to stuff that value. They can cancel the scan, and manually type in the value also. Then they would SAVE the form. So I figured if the scan is good (its a warehouse location) I just stuff it and and start the SAVE (which starts BO Rules)
THIS IS RUNNING IN Native Aware on cell phone. Android APK
Attachments
SaveBarcode.PNG
SaveBarcode.PNG (7.53 KiB) Viewed 4029 times
Last edited by Jaymer on Sun Nov 17, 2019 6:14 pm, edited 1 time in total.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
aware_support
Posts: 7523
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: HTML script needs to set FormField,then auto save Form.

Post by aware_support »

First of all you need a "parser" object for the form. You can get it if you have any HTML element that belongs to the form:

var parser = AwareApp.getFormParserFromHtmlElem (htmlElem);

Once you have the parser you can use it to get any "attribute field" on the form:

var field = parser.getField ("AttributeName");

You can set a value into the attribute field like this:
field.setValue (value);

You can get an existing value from a field like so:
var value = field.getValue ();

Finally you can save the form like so:
parser.saveForm ();
Aware IM Support Team
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

SOLUTION

Post by Jaymer »

Thank you, this was very helpful.
Below is the contents of a HTML cell on a Form.
This is for Aware Native app to run on Android.
A user finds an Inventory item & this form is presented to capture the location from a barcode label on the shelf.
The Cordova Plugin from Build.PhoneGap activates the native camera, and the scanned value is returned upon scan success and inserted into the Aware field.

Code: Select all

<script>
function StartScan() {  
  cordova.plugins.barcodeScanner.scan(
    function (result) {
      if(!result.cancelled) { 
var parser = AwareApp.getFormParserFromHtmlElem (btn1);
var field = parser.getField ("tmp_ShortCode");
field.setValue (result.text);
parser.saveForm ();
	}
  },
  function (error) {alert("Scanning failed: " + error);
  },      {
          preferFrontCamera : true, 
          showFlipCameraButton : true, 
          showTorchButton : true,
          torchOn: true, 
          saveHistory: false, 
          prompt : "Place a barcode inside the scan area", 
          resultDisplayDuration: 500,
          formats : "CODE_39", 
          orientation : "portrait", 
          disableAnimations : true, 
          disableSuccessBeep: false 
      }
);
}
</script>

<button onclick="StartScan()">Scan Location</button>
--> JaymerTip
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Post Reply