Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Using Tap Forms 5 › Add ( or ) in IF statement
- This topic has 4 replies, 2 voices, and was last updated 6 years, 1 month ago by
Victor Warner.
-
AuthorPosts
-
April 7, 2019 at 4:06 AM #34311
Victor WarnerParticipantI am having a problem adding a ( or a ) in quoted text in an IF statement which is contained within an IFEQUAL statement in a calculation field.
The IFEQUAL statement is as follows (which works):
`IFEQUAL([Number of pages ];”1″;(if ([Extract from document] = 1;”of an extract the front of the first page\, comprising ” + ([Number of pages ] + ” A4 sheet of paper”;”comprising ” + ([Number of pages ] + ” A4 sheet of paper”)); “(comprising ” + ([Number of pages ] + ” A4 sheets of pages)”)’
However if I add an ( or an ) in any of the quoted text the calculation no longer produces any result. For exaple: Instead of “of an extract the front of the first page\, comprising ” I change it to “of an extract (the front of the first page\, comprising ”
Escaping a ( or a ) also does not work.
The IF statement alone with ( or ) in quoted text also works.
Is there a solution to this?
Tap Forms 5.3.6 – macOS 10.14.4
Attachments:
You must be logged in to view attached files.April 7, 2019 at 12:39 PM #34315
BrendanKeymasterIt would seem that the
(
and)
characters are being interpreted by the Math parser as parentheses for the functions and order of operations even when they’re within double-quotes. I would need to add support to let you escape them like you can a comma, semi-colon, or double-quote.A workaround for now I would suggest is to use a Script Field instead of a Calculation field to do the same thing. It will also be easier to read in JavaScript than in the formula.
April 7, 2019 at 3:22 PM #34316
Victor WarnerParticipantBrendan,
Could you help me if how to do an IF statement within an IF statement in JavaScript based on the code I set out in my original post? I have tried based on the code for the Calculation field but it does not appear to work (most probably because of lack of knowledge of Javascript).
[Number of pages] is a text field.
[Extract from document] is a Check Mark field.Any help would be very gratefully received (even if it is just the basic outline of how to construct the JavaScript).
April 7, 2019 at 7:18 PM #34319
BrendanKeymasterWell you can do nested
if
statements really easily in JavaScript.if (numberOfPages == 1) { if (extractFromDocument == 1) { // do something } }
But this is also the equivalent of:
if (numberOfPages == 1 && extractFromDocument == 1) { // do something }
April 8, 2019 at 6:09 AM #34336
Victor WarnerParticipantBrendan,
Thank you for the examples (and after a lot of examination at https://www.w3schools.com) I think I have found the JavaScript equivalent:
var number_of_pages_id = 'fld-b6882198382f4b368dccfa874e69a563'; var number_of_pages = record.getFieldValue('fld-b6882198382f4b368dccfa874e69a563'); var extract_from_document_id = 'fld-e3540b375b0f43cb97f4ea84a2705885'; var extract_from_document = record.getFieldValue('fld-e3540b375b0f43cb97f4ea84a2705885'); result = ''; if (number_of_pages == 1 && extract_from_document == 1) { result = "of an extract (the front of the first page, comprising " + record.getFieldValue(number_of_pages_id) + " A4 sheet of paper)"; } else if (number_of_pages == 1 && extract_from_document == 0) { result = "(comprising " + record.getFieldValue(number_of_pages_id) + " A4 sheet of paper)"; } else if (number_of_pages > 1 ) { result = "(comprising " + record.getFieldValue(number_of_pages_id) + " A4 sheets of paper)"; } else { result = ''; } result;
-
AuthorPosts
You must be logged in to reply to this topic.