We’ve added new expressions

We’ve added a bunch of new expressions to our forms designer. They’re supported in the mobile applications for all of our platforms, but please make sure you’re running the latest versions of the apps.

New Date Time Expressions:

These are available in the forms designer for working with dates and times.

Creating dates and times for use within expressions:

  • date(year, month, day)
  • time(hour, minute, second)
  • datetime(year, month, day, hour, minute, second)

Accessing parts of an existing date/time:

  • year(datetime)
  • month(datetime)
  • day(datetime)
  • hour(datetime)
  • minute(datetime)
  • second(datetime)

Manipulating date/times:

  • addYears(datetime, number_of_years_to_add)
  • addMonths(datetime, number_of_months_to_add)
  • addDays(datetime, number_of_days_to_add)
  • addHours(datetime, number_of_hours_to_add)
  • addMinutes(datetime, number_of_minutes_to_add)
  • addSeconds(datetime, number_of_seconds_to_add)

(Use negative values to subtract rather than add, and as always, the parameters can be constants in the expression or values from answers within the form.)

Other functions:

  • now() – returns the current datetime
  • ‘datetimeA – dateTimeB’ will return the number of seconds difference between A and B

Some quick examples:

  • ‘addYears(MY_BIRTHDATE_QUESTION, 21) < NOW()’  will be true if the person is 21 years or older, false otherwise
  • ‘(TIME_WORK_ENDED – TIME_WORK_STARTED) / 3600 * HOURLY_RATE’ will calculate the cost of work done

If-Then-Else:

We’ve also added support for if-then-else expressions. They take the form:

  • if(SOME_CONDITION, RESULT_IF_TRUE, RESULT_IF_FALSE)

As an example, if you wanted to calculate the cost of some work done, and it depended on whether you’d originally give an fixed quote, or were going to charge for hours worked:

  • IF(PRICE_IS_FIXED_QUESTION, ORIGINAL_QUOTED_PRICE, HOURS_WORKED * HOURLY_RATE)

If you have issues getting these to work for you, or if we’ve missed anything, please let us know.

Subscribe to News & Updates from Device Magic

Join the growing force of contractors, inspectors, delivery companies and service providers learning to make their business more efficient every day.

  • Hi!

    I’m having some dificulties in writing a simple function that calculates a data+time field in a form. What i want to acomplish is to have one field were i manually write the data+time a other that calculate that data+time plus 4 hours. Is that possible?

    PS: I’m working with an Android Jelly Bean Phone.

  • mikew

    Hi João,

    Yes, this is possible. If you have a date+time question (e.g. MY_DATE_TIME), then add another calculated question, and set the formula to:

    addHours(MY_DATE_TIME,4)

    (You can use the expression editor to help you get it right.)

    This will add 4 hours to whatever value you’ve entered in MY_DATE_TIME.

    Mike

  • Michael

    I tried using your example Mike W. But when I save the form it will not transfer to my mobile device. I get a message on my mobile that says “form cannot be read”. Same is true when I try to use any functions such as ‘addYears’. I am on an HTC One X running ICS on at&t (update 4.0.4)

    Thanks for any help.

    Michael

  • mikew

    Hi Michael,
    My apologies for this issue.
    Could you please confirm you’re running the latest version of the Forms app on that device?
    If you are, please post a support issue at devicemagic.zendesk.com with your organization and form details, and we’ll get it resolved.
    Kind Regards
    Mike

Mobile Forms & Surveys enable Offline Data Collection

Start Free Trial
Mobile Forms for iPhone, iPad, Android, and BlackBerry

Email Newsletter

Get Updates from Device Magic

Product Tour

See how Device Magic can help your business go paperless and get organized.

View Features »