JavaScript Reference

JavaScript Reference



Note: Global variables do not work consistently across all platforms. We do not recommend using global variables. In cases where global variables are needed, you can use a hidden region to store a value that can be used like a global variable in your script. To hide a region, right click on the region and choose "Remove from Page".


Form

The Form class is the root node in the form object tree. There is a global instance called Form that is the object for the user's current eForm.

Form_Started()

Event raised when the user starts work on a new form.

  1. function Form_Started() {
  2.      var randomNum = Math.floor((Math.random() * 100) + 1);
  3.      Form.getRegion("Page1@Group").setValue(randomNum);
  4. }


Form_Validating(objValidationLog)

Event raised when the form data validation rules are being evaluated. This usually happens immediately before a user sends the form. If the log records any error messages then the user cannot send the form.

  1. function Form_Validating(objValidationLog) {
  2.      var rgnOtherCheck = Form.getRegion("Page1@OtherCheck");
  3.      var rgnOtherText = Form.getRegion("Page1@OtherText");
  4.      if(rgnOtherCheck.getChecked() == true && rgnOtherText.getValue() == "") {
  5.           objValidationLog.addRegionErrorMessage(rgnOtherText, "Please specify a value");
  6.      }
  7. }



Form_Sending()

Event raised after the user specifies that the form is ready to be sent. Be cautious about script in the Sending event. You generally should not make changes to form data because the user may not have a chance to see and validate the new values. If the user opens and resends a form (for example, as part of a workflow), the Sending event will be raised again. Users may also have an option to resend a form without opening it, in which case the Sending event may not be raised before re-transmitting form data. The Sending event may also be raised multiple times before sending the form if the client gives the user a way to cancel the transmission after the event has already been raised. 

  1. function Form_Sending() {
  2.      var timestamp = new Date();
  3.      Form.getRegion("Page1@Timestamp").setValue(timestamp.toDateString());
  4. }

 

Form_DataChanged(objArgs)

Event raised when the value changes in any region on the form.

  1. function Form_DataChanged(objArgs) {
  2.      var strRegionName = objArgs.getRegion().getName();
  3.      if(strRegionName.indexOf("Source") >= 0) {
  4.           var lineIdxStr = strRegionName.slice(7);
  5.           var pgNum = objArgs.getRegion().getOwningPage().getUserPageNumber();
  6.           var destRgn = Form.getRegion("Page" + pgNum + "@AutoCopy" + lineIdxStr);
  7.           destRgn.setValue(objArgs.getRegion().getValue());
  8.      }
  9. }


Note: When adding script to the Form_DataChanged event, you may encounter data processing errors if you have a large number of regions with initial values. The error message may display something similar to "Line 0: Error invoking Form_DataChanged: Exception from HRESULT" etc. In order to avoid this error and unnecessary data processing, you should create IF statements to narrow down the targeted regions before manipulating region values. For example, notice in the script above, that the "lineIDxStr", "pgNUm", and "destRgn" variables are defined inside the body of the IF statement, as opposed to being globally declared within the Form_DataChanged event.


Form.getName()

Returns the name of this form template.

Platform Notes: tested and works in Preview mode, Web Client, iOS, Android.
  1. function displayFormName() {
  2.      var strFormName = Form.getName();
  3.      Form.getRegion("Page1@FormName").setValue(strFormName);
  4. }


Form.getPagesCount()

Returns the number of pages in the form.

Platform Notes: tested and works in Preview mode, iOS, Android but not in Web Client.
  1. function Page1_AddPhotoPage_Click() {
  2.      var pgPhotoPage = Form.getPageByUserPageNumber(2);
  3.      var pgNewPhotoPage = pgPhotoPage.duplicateTemplate();
  4.      Form.insertPage(pgNewPhotoPage, Form.getPagesCount());
  5. }


Form.getPaymentAccount()

Returns the Payment Account setup on the Form for use with Credit Card Payments.

  1. function displayPaymentAccount() {
  2.      var strPaymentAccountName = Form.getPaymentAccount();
  3.      Form.getRegion("Page1@PaymentAccountLabel").setValue(strPaymentAccountName);
  4. }


Form.setPaymentAccount(strAccount)

Sets the Payment Account for the Form for use with Credit Card Payments.

  1. function updatePaymentAccount() {
  2.      var strPaymentAccountName = Form.getRegion("Page1@PaymentAccountLabel").getValue();
  3.      Form.setPaymentAccount(strPaymentAccountName);
  4. }

 

Form.getPageAtIndex(pgNum)

Returns the Page at the given position in the pages collection.

Platform Notes: tested and works in Preview mode, Web Client, iOS, Android.
  1. function Page1_Sample_Click() {
  2.      var pgFirstPage = Form.getPageAtIndex(0);
  3.      var firstPageUserPageNumber = pgFirstPage.getUserPageNumber();
  4.      var firstPageIndex = Form.getPageIndex(pgFirstPage);
  5.      Form.getRegion("Page1@UserPageNumber").setValue(firstPageUserPageNumber);
  6.      Form.getRegion("Page1@FormPageIndex").setValue(firstPageIndex);
  7. }


Form.getPageByUserPageNumber(pgNum)

Returns the Page with the given user-assigned page number.

Platform Notes: tested and works in Preview mode, Web Client, iOS, Android.
  1. function ClearFirstPage2() {
  2.      var pgFirstPage = Form.getPageByUserPageNumber(1);
  3.      pgFirstPage.GetRegion("Name").setValue("");
  4.      pgFirstPage.GetRegion("Address").setValue("");
  5.      pgFirstPage.GetRegion("Phone").setValue("");
  6. }


Form.getPageIndex(page)

Returns an integer of the index of the given page, which is the 0-based position of the page in the form. Note that the index, unlike the user page number, will change if a page is inserted before it.

Platform Notes: tested and works in Preview mode, iOS, Android but not in Web Client.
  1. function Page1_Sample_Click() {
  2.      var pgFirstPage = Form.getPageAtIndex(0);
  3.      var firstPageUserPageNumber = pgFirstPage.getUserPageNumber();
  4.      var firstPageIndex = Form.getPageIndex(pgFirstPage);
  5.      Form.getRegion("Page1@UserPageNumber").setValue(firstPageUserPageNumber);
  6.      Form.getRegion("Page1@FormPageIndex").setValue(firstPageIndex);
  7. }


Form.getRegion(rgnName)

Returns the Region.

Platform Notes: tested and works in Preview mode, Web Client, iOS, Android.
  1. function ClearFirstPage3() {
  2.      Form.getRegion("Page1@Name").setValue("");
  3.      Form.getRegion("Page1@Address").setValue("");
  4.      Form.getRegion("Page1@Phone").setValue("");
  5. }


Form.insertPage(page, pgIndex)

Inserts a page into the form at the given index.

Platform Notes: tested and works in Preview mode, Web Client, iOS, Android.
  1. function Page1_AddPhotoPage_Click() {
  2.      var pgPhotoPage = Form.getPageByUserPageNumber(2);
  3.      var pgNewPhotoPage = pgPhotoPage.duplicateTemplate();
  4.      Form.insertPage(pgNewPhotoPage, Form.getPagesCount());
  5. }


Form.lockRegionValues()

Locks all Regions in the Form.

Platform Notes: tested and works in Preview mode, Web Client, iOS, Android.
  1. function Page1_Done_ValueChanged(objArgs) {
  2.      if(Form.getRegion("Page1@Done").getChecked() == true) {
  3.           Form.lockRegionValues();
  4.      } else {
  5.           Form.unlockRegionValues();
  6.      }
  7. }


Form.unlockRegionValues()

Unlocks all Regions in the Form.

Platform Notes: tested and works in Preview mode, Web Client, iOS, Android.
  1. function Page1_Done_ValueChanged(objArgs) {
  2.      if(Form.getRegion("Page1@Done").getChecked() == true) {
  3.           Form.lockRegionValues();
  4.      } else {
  5.           Form.unlockRegionValues();
  6.      }
  7. }




Page

The Page class is a container for Regions.

 

Page.getName()

Returns the name for this page.

Platform Notes: tested and works in Preview mode, Android and Web Client.
  1. function GetPageName() {
  2.      var pgFirstPage = Form.getPageAtIndex(0);
  3.      var firstPageName = pgFirstPage.getName();
  4.      Form.getRegion("Page1@PageName").setValue(firstPageName);
  5. }


Page.setName(newName)

Sets the name for this page.

Platform Notes: tested and works in Preview mode, Android and Web Client.
  1. function SetPageName() {
  2.      var customPageName = Form.getRegion("Page1@CustomerName").getValue() + " - " + Form.getRegion("Page1@CustomerID").getValue();
  3.      var pgPage1 = Form.getPageAtIndex(0);
  4.      pgPage1.setName(customPageName);
  5. }


Page.getUserPageNumber()

Returns the user-assigned page number for this page.

Platform Notes: tested and works in Preview mode, Android and Web Client. Need further testing on iOS.
  1. function Page1_Sample_Click() {
  2.      var pgFirstPage = Form.getPageAtIndex(0);
  3.      var firstPageUserPageNumber = pgFirstPage.getUserPageNumber();
  4.      var firstPageIndex = Form.getPageIndex(pgFirstPage);
  5.      Form.getRegion("Page1@UserPageNumber").setValue(firstPageUserPageNumber);
  6.      Form.getRegion("Page1@FormPageIndex").setValue(firstPageIndex);
  7. }


Page.getVisible()

Returns boolean for whether or not the user can see this page.

Platform Notes: tested and works in Preview mode, Android, iOS and Web Client. Returns 0 or 1 on iOS, True or False on all other platforms.
  1. function Page1_Details_ValueChanged(objArgs) {
  2.      // Show the details page if the details checkbox is selected
  3.      var boolDetails = Form.getRegion("Page1@Details").getChecked();
  4.      if(boolDetails == true && Form.getPageAtIndex(1).getVisible() == false) {
  5.           Form.getPageAtIndex(1).setVisible(true);
  6.      }
  7. }

 

Page.setVisible(boolean)

Controls whether or not the user can see this page.

Platform Notes: tested and works in Preview mode, Android, iOS and Web Client.
  1. function Page1_Details_ValueChanged(objArgs) {
  2.      // Show the details page if the details checkbox is selected
  3.      var boolDetails = Form.getRegion("Page1@Details").getChecked();
  4.      if(boolDetails == true && Form.getPageAtIndex(1).getVisible() == false) {
  5.           Form.getPageAtIndex(1).setVisible(true);
  6.      }
  7. }


Page.duplicateTemplate()

Returns a copy of the page template but does not copy page data.

  1. function Page1_AddPhotoPage_Click() {
  2.      var pgPhotoPage = Form.getPageByUserPageNumber(2);
  3.      var pgNewPhotoPage = pgPhotoPage.duplicateTemplate();
  4.      Form.insertPage(pgNewPhotoPage, Form.getPagesCount());
  5. }

 

Page.getRegion(rgnName)

Returns a Region specified by its short name.

  1. function ClearFirstPage() {
  2.      var pgFirstPage = Form.getPageByUserPageNumber(1);
  3.      pgFirstPage.getRegion("Name").setValue("");
  4.      pgFirstPage.getRegion("Address").setValue("");
  5.      pgFirstPage.getRegion("Phone").setValue("");
  6. }

 

Page.lockRegionValues()

Locks all Regions on the Page.

  1. function Lock_Page2() {
  2.      var pgPageTwo = Form.getPageByUserPageNumber(2);
  3.      pgPageTwo.lockRegionValues();
  4. }


Page.unlockRegionValues()

Unlocks all Regions on the Page.

  1. function Unlock_Page2() {
  2.      var pgPageTwo = Form.getPageByUserPageNumber(2);
  3.      pgPageTwo.unlockRegionValues();
  4. }



Region

The Region class represents form fields. It has properties and methods for manipulating region data.

 

PageNum_Region_ValueChanged(objArgs)

Event raised when a region's value changes.

  1. function Page1_FirstName_ValueChanged(objArgs) {
  2.      var lastName = Form.getRegion("Page1@LastName").getValue();
  3.      var rgnFullName = Form.getRegion("Page1@FullName");
  4.      rgnFullName.setValue(objArgs.getRegion().getValue() + " " + lastName);
  5. }


PageNum_Region_DoneInking(objArgs)

Event raised 3 seconds after a user stops inking in a region. 

Platform Notes: tested and works in Web Client, iOS, Android. Does not work in Preview.
  1. function Page1_AutoProcess_DoneInking(objArgs) {
  2.      objArgs.getRegion().process();
  3. }


Region.getChecked()

Returns a boolean of checkbox region is currently checked or not. It is an error to try getting the getChecked property on a non-checkbox region.

  1. function Page1_ShippingAddressIsDifferent_ValueChanged(objArgs) {
  2.      var blnShipping = objArgs.Region.getChecked();
  3.      Form.getRegion("Page1@ShipToCity").setIsRequired(blnShipping);
  4.      Form.getRegion("Page1@ShipToState").setIsRequired(blnShipping);
  5.      Form.getRegion("Page1@ShipToZip").setIsRequired(blnShipping);
  6. }


Region.setChecked(boolean)

Sets a checkbox region is checked or unchecked.

  1. function Page1_EnteredAmount_ValueChanged(objArgs) {
  2.      if(objArgs.getRegion().getValue() > 10) {
  3.           Form.getRegion("Page1@RequiresSignature").setChecked(true);
  4.           Form.getRegion("Page1@Signature").setIsRequired(true);
  5.      }
  6. }


Region.hasDatasourceList()

Returns boolean of whether the Datasource Region has a drop down list or not. It is an error to try using the HasDatasourceList property on a region that is not a Datasource.

  1. function Form_Validating(objValidationLog) {
  2.      var rgnDatasource = Form.getRegion("Page1@Animals");
  3.      if(rgnDatasource.hasDatasourceList() && (rgnDatasource.getValue() == " ") {
  4.           objValidationLog.addRegionErrorMessage(rgnDatasource, "Select an animal");
  5.      }
  6. } 


Region.getDatasourceList()

Returns an array of the region's Datasource List.

  1. function ShowRegionDropDownList() {
  2.      var rgnDatasource = Form.getRegion("Page1@Datasource1");
  3.      rgnDatasource.setValue(rgnDatasource.getDatasourceList());
  4. }

 

Region.setDatasourceList(array)

Set the region drop down list for Datasource Regions. This function requires an array of string values as the parameter.

  1. function Page1_FirstName_ValueChanged(objArgs) {
  2.      var rgnAnimals = Form.getRegion("Page1@Animals");
  3.      rgnAnimals.setDatasourceList(["cat", "dog", "bird"]);
  4. }


Region.getHasImage()

Returns a boolean of whether a camera region has an image or not. It is an error to try using the getHasImage method on a non-camera region.

  1. function Form_Validating(objValidationLog) {
  2.      var rgPhoto = Form.getRegion("Page1@Photo");
  3.      var rgCaption = Form.getRegion("Page1@Caption");
  4.      if(rgPhoto.getHasImage() && rgCaption.getValue() == "") {
  5.           objValidationLog.addRegionErrorMessage(rgCaption, "Include a caption.");
  6.      }
  7. }


Region.loadImage(path)

Loads an image file into a camera region. It is an error to try using LoadImage on a non-camera region.

  1. function BtnLoadImage_Click() {
  2.      var path = "C:\Sample Pictures\sunset.jpg";
  3.      Form.getRegion("Page1@Photo").loadImage(path);
  4. }


Region.clearImage()

Removes the current image from a camera region. It is an error to try using clearImage on a non-camera region.

  1. function BtnClearImage_Click() {
  2.      Form.getRegion("Page1@Photo").clearImage();
  3. }


Region.getHasStrokes()

Returns a boolean if pen regions contain ink or not. It is an error to try using the hasStrokes property on a non-pen region.

  1. function Form_Validating(objValidationLog) {
  2.      var rgnSignature = Form.getRegion("Page1@Signature");
  3.      if(rgnSignature.getHasStrokes()) {
  4.           objValidationLog.addRegionErrorMessage(rgnSignature, "You must sign the form.");
  5.      }
  6. }

 

Region.clearStrokes()

Removes ink from a pen region. It is an error to try using clearStrokes on a non-pen region.

  1. function BtnClearSignature_Click() {
  2.      Form.getRegion("Page1@Signature").clearStrokes();
  3. }


Region.isRequired()

Returns a boolean for whether or not the region is required.

  1. function Page1_EnteredAmount_ValueChanged(objArgs) {
  2.      if (objArgs.getRegion().isRequired()) {
  3.           Form.getRegion("Page1@Signature").setIsRequired(true);
  4.      }
  5. }


Region.setIsRequired(boolean)

Sets whether or not the region is required.

  1. function Page1_EnteredAmount_ValueChanged(objArgs) {
  2.      if(objArgs.getRegion().getValue() > 10) {
  3.           Form.getRegion("Page1@RequiresSignature").setChecked(true);
  4.           Form.getRegion("Page1@Signature").setIsRequired(true);
  5.      }
  6. }


Region.getName()

Returns the region's name.

  1. function ShowRegionName() {
  2.      var rgnText1 = Form.getRegion("Page1@Text1");
  3.      rgnText1.setValue(rgnText1.getName());
  4. }

 

Region.getOwningPage()

Returns the Page that this region belongs to.

  1. function ClearNotesForRegion(objPenRegion) {
  2.      var pgPage = objPenRegion.getOwningPage();
  3.      pgPage.getRegion("Notes").ClearValue();
  4. }


Region.getType()

Returns the region type. (eg Text, Numeric, Pen, etc.). Works on Android but does not work on iOS or preview mode. Returns a number in web client: 2 for text

  1. function ShowRegionType() {
  2.      var rgnText1 = Form.getRegion("Page1@Text1");
  3.      rgnText1.setValue(rgnText1.getType());
  4. }

 

Region.getValue()

Returns the region's value.

  1. function Page1_FirstName_ValueChanged(objArgs) {
  2.      var rgnLastName = Form.getRegion("Page1@LastName");
  3.      var rgnFullName = Form.getRegion("Page1@FullName");
  4.      rgnFullName.setValue(objArgs.getRegion().getValue() + " " + rgnLastName.getValue());
  5. }


Region.setValue(newValue)

Sets the region's value.

  1. function Page1_FirstName_ValueChanged(objArgs) {
  2.      var rgnLastName = Form.getRegion("Page1@LastName");
  3.      var rgnFullName = Form.getRegion("Page1@FullName");
  4.      rgnFullName.setValue(objArgs.getRegion().getValue() + " " + rgnLastName.getValue());
  5. }


Region.clearValue()

Clears the region value. This method can be used on all region types except for Calculation and Mirror regions.

  1. function ClearFirstPage4() {
  2.      Form.getRegion("Page1@Name").clearValue();
  3.      Form.getRegion("Page1@Address").clearValue();
  4.      Form.getRegion("Page1@Phone").clearValue();
  5. }


Region.getIsLocked()

Returns a boolean showing whether the Region is locked or not.

  1. function Form_Validating(objValidationLog) {
  2.      var rgnSign = Form.getRegion("Page1@Signature");
  3.      if(rgnSign.isLocked() == false) {
  4.           objValidationLog.addRegionErrorMessage(rgnSign, "Signature is not locked.");
  5.      }
  6. }


Region.lockValue()

Locks the Region.

  1. function LockGPSLocation() {
  2.      Form.GetRegion("Page1@Location").lockValue()
  3. }


Region.unlockValue()

Unlocks the Region.

  1. function UnlockGPSLocation() {
  2.      Form.getRegion("Page1@Location").unlockValue()
  3. }


Region.takeLatestCoordinate()

Takes the user's most recent known location as the value for a GPS region. The new region value will be a best guess of the user's location. It may be a stale value if the form has stopped receiving location updates. It may also not take any value if the form has not yet received any location updates.

  1. function GetLocation() {
  2.      Form.getRegion("Page1@Location").takeLatestCoordinate();
  3. }


Region.process()

Processes a region. For regions that accept ink input, this performs handwriting recognition (Windows only). It forces a re-evaluation for calculation and datasource regions. In general, the form will keep track of region dependencies and perform automatic processing for calculated regions. You shouldn't generally need to make explicit calls to Process. The only time this should be called is if a reliant region like a calculation, mirror, or datasource is referenced in the current function.

  1. function Page1_Total_ValueChanged(objArgs) {
  2.      var rgnTax = Form.getRegion("Page1@TaxCalculation");
  3.      rgnTax.process();
  4.      var statistic = (Form.getRegion("Page1@Total).getValue() + rgnTax.getValue()) / 1000;
  5.      Form.getRegion("Page1@EstimatedValue").setValue(statistic * 1.25);
  6. }


Region.getCoordinates() 

This method only works with GPS regions. Returns an object containing the latitude, longitude, elevation, and timestamp. Only latitude and longitude are guaranteed to be present; elevation and timestamp may be null. When timestamp is present, it is a UTC value formatted as an ISO 8601 string.
Note: This method only works in eForm Template Version 7.0 and higher
  1. function Page2_GPS1_ValueChanged(objArgs) {
  2. var gps = objArgs.getRegion().getCoordinates();
  3. Form.getRegion("Page2@Latitude").setValue(gps.latitude);
  4. Form.getRegion("Page2@Longitude").setValue(gps.longitude);
  5. Form.getRegion("Page2@Elevation").setValue(gps.elevation);
  6.         Form.getRegion("Page2@Timestamp").setValue(gps.timestamp);
  7. }


ValidationLog

The Validation Log records problems discovered during form validation. If the log contains any entries then the form cannot be sent. This method will only work in the Form_Validating() function, but can be used in a helper function that is called inside Form_Validating() as long as objValidationLog is passed as an argument to the helper function.

 

objValidationLog.addRegionErrorMessage(region, strMessage)

Adds a validation error message to the region. Tablet users will see the error message attached to the region and will not be able to send the form.

  1. function Form_Validating(objValidationLog) {
  2.      var rgnEmail = Form.getRegion("Page1@Email");
  3.      if(rgnEmail.getValue() == "") {
  4.           objValidationLog.addRegionErrorMessage(rgnEmail, "You must enter your email");
  5.     }
  6. }


 


View

The View class exposes control features for an eForm editing view. There is a single global instance called View that lets script access the client's currently active view if there is one. If a client supports more than one open eForm view then this instance will manipulate whichever view the client has specified as the active view, which may change as the user works with the form.

 

View.showDialog(strMessage, intDialogType, callback)

Shows a popup message box with a message and a chosen button configuration. The button configuration specifies which buttons are available for the user to select.

Platform Notes: tested and works in Preview mode, iOS, Android. OK button configuration is currently the only configuration available for Web Client and it does not return a value.

Possible button configurations are:
0 OK
1 OK, Cancel
3 Yes, No, Cancel
4 Yes, No

The return value indicates which button the user chose. Values are:
1 OK
2 Cancel
6 Yes
7 No

  1. function showMessage() {
  2.      View.showDialog("Are You Sure?", 4, "dialogResultHandler");
  3. }
  4. function dialogResultHandler(result){
  5.      var returnValue;
  6.      if(result == 1) {
  7.           returnValue = "OK";
  8.      } else if(result == 2) {
  9.           returnValue = "Cancel";
  10.      } else if(result == 6) {
  11.           returnValue = "Yes";
  12.      } else if(result == 7) {
  13.          returnValue = "No";
  14.      }
  15. }


View.openURL(strURL)

Opens up a URL in a web browser. For web sites, the URL string must include the "http://" or "https://" for the method to run correctly. The default browser will be used to open the URL specified.

  1. function TestOpenURL() {
  2.      var strWebSite = Form.getRegion("Page1@WebSiteURL").getValue();
  3.      View.openURL(strWebSite);
  4. }


View.showUserPageNumber(pgNum)

Changes the current page in the active view if the client has specified one.

  1. function ShowPage2() {
  2.      View.showUserPageNumber(2);
  3. }


 


Field2Base

The Field2Base class provides information about the current F2B user's session. There is a single global instance called Field2Base.

 

Field2Base.getProjectId()

Returns the Unique ID for the form's Folder.

  1. function ShowProjectID() {
  2.      var projId = Field2Base.getProjectId();
  3.      Form.getRegion("Page1@ProjectID").setValue(projId);
  4. }


Field2Base.getProjectName()

Returns the Name for the form's Folder.

  1. function ShowProjectName() {
  2.      var projName = Field2Base.getProjectName();
  3.      Form.getRegion("Page1@ProjectName").setValue(projName);
  4. }

 

Field2Base.getUsername()

Returns the Username of the User filling out the Form.

  1. function ShowUserName() {
  2.      var userName = Field2Base.getUsername();
  3.      Form.getRegion("Page1@UserName").setValue(userName);
  4. }


Field2Base.getUserFirstName()

Returns the First Name of the User filling out the Form.

  1. function ShowFirstName() {
  2.      var firstName = Field2Base.getUserFirstName();
  3.      Form.getRegion("Page1@FirstName").setValue(firstName);
  4. }


Field2Base.getUserLastName()

Returns the Last Name of the User filling out the Form.

  1. function ShowLastName() {
  2.      var lastName = Field2Base.getUserLastName();
  3.      Form.getRegion("Page1@LastName").setValue(lastName);
  4. }

 

Field2Base.getUserPhoneNumber()

Returns the Phone Number of the User filling out the Form.

There is no validation on the Phone Number field in the User Profile so other information (employee ID, etc...) can be used to be pulled into forms.
  1. function ShowPhone() {
  2.      var phoneNum = Field2Base.getUserPhoneNumber();
  3.      Form.getRegion("Page1@Phone").setValue(phoneNum);
  4. }


Field2Base.getUserEmail()

Returns the E-Mail Address of the User filling out the Form.

  1. function ShowEmail() {
  2.      var email = Field2Base.getUserEmail();
  3.      Form.getRegion("Page1@Email").setValue(email);
  4. }


Field2Base.send()

Sends the current draft. This initiates validation and other send processing. Calling this method is equivalent to the user clicking Send in the UI. All validation and on-send processing occurs as it normally would. The user may end up canceling the send process. This method returns and does not interrupt script processing. Any further script will run normally. However, the ordering and synchronization of send operations with the running script is not defined.

Platform Notes: Tested and works in Preview mode, Web Client, iOS, Android. You cannot name the function Send() (lowercase will work) in iOS in version 6.5 or earlier.
  1. function sendForm() {
  2.      Field2Base.send();
  3. }


Field2Base.closeDraft(boolPrompt)

Closes the current Form Draft and uses the Boolean parameter passed in to show the Save Draft Prompt (true = show, false = do not show). If using 'false', the draft is automatically discarded. This function cannot be called from the Form_Sending Event, and it does not factor in the Save Draft Prompt config; it uses the Boolean parameter instead, overriding the Save Draft Prompt config.

  1. function closeDraftWithNoPrompt() {
  2.      Field2Base.closeDraft(false);
  3. }


  1. function closeDraftWithPrompt() {
  2.      Field2Base.closeDraft(true);
  3. }



Environment and Locale

The Environment class provides information about the current environment where the app is running. The Locale class provides the platform's language and country information.


Environment.getCurrentLocale()

Return the current Locale object of the Environment which can only be used in conjunction with the Locale properties (Code, Language, and Region).
  1. function ShowPlatformLanguage() {
  2.      var lang = Environment.getCurrentLocale().getLanguage();
  3.      Form.getRegion("Page1@Language").setValue(lang);
  4. }


Environment.getCurrentLocale().getCode()

Returns the full language and territory code of the Locale instance. Typically, the two letter language code and the two letter territory code that will be separated by a hyphen or an underscore. For example, a device running the US English Language would have a code of "en_us" or "en-us". The codes returned are dependent on the Operating System so it is NOT recommended as the best way to determine a User's Language due to the lack of uniform returned values.

  1. function ShowPlatformCode() {
  2.      var code = Environment.getCurrentLocale().getCode();
  3.      Form.getRegion("Page1@Code").setValue(code);
  4. }


Environment.getCurrentLocale().getLanguage()

Returns the language code of the Locale instance. Typically, the two letter language code will be returned for this property. For that reason, this is the recommended way to determine a User's Language.

  1. function ShowPlatformLanguage() {
  2.      var lang = Environment.getCurrentLocale().getLanguage();
  3.      Form.getRegion("Page1@Language").setValue(lang);
  4. }


Environment.getCurrentLocale().getRegion()

Returns the region (or territory) code of the Locale instance. Typically, the two letter territory code will be returned for this property so values like "US" for the United Sates or "GB" for Great Britain will be returned.

  1. function ShowPlatformRegion() {
  2.      var reg = Environment.getCurrentLocale().getRegion();
  3.      Form.getRegion("Page1@Region").setValue(reg);
  4. }




    • Related Articles

    • Calling a REST API Web Service in Form Script

      This article will walk you through how to call a Web Service in your Form via the Field2Base JavaScript Library. To initialize a call, you will need to assign the endpoint for your Web Services provider. ...
    • Creating Buttons

      Overview Buttons can be used to navigate between pages of the Form, show embedded images, link to a web page or kick off a function from your form script. This article describes how to add buttons to your Forms.   Adding a Button 1. Open your Form in ...
    • Forms Designer Quick Start Guide

      Overview Field2Base Forms Designer is the proprietary software application that allows your existing Forms to be quickly converted to an active, online, smart Form available to your end users via our Mobile Device and Web-based Applications. This ...
    • SQL Datasource Regions

      Overview This article describes how to set up a SQL Datasource Region in Forms Designer. A SQL Datasource allows you to pull data from external Form Data Files (Excel or Access files) into your Form. This is a convenient option when you need to make ...
    • Creating Regions

      Overview A Region is a field on your company's Form. Regions are the individual fields you define on top of the Form background image and allow the user to provide necessary and relevant data. Regions come in all shapes and sizes, including include ...