There are a number of common tasks that a lot of SYNTAQ Users need done on a regular basis. Rather than requiring each User to write their own Scripts to performs these functions, we have created a whole heap of them already!
You can use these functions by simply copying the relevant script into the Logic blocks for the field you want to write the value to.
The only changes you will have to make for most of these functions, will be to change the value of the 'input' variable to include your own field names. You will also need to change the reference from 'data' to 'row' if your input field is located inside a repeat.
Unless stated otherwise all Triggers should have their Container Type set to 'Javascript', and all Actions should have their Type set to 'Value'.
Get Gender
This piece of logic determines the gender of someone based on the answer to the Title sub-component of the Person Control, and sets this as a field value.
Trigger:
var input = data.person;
result = input !== undefined ? true : false;
Action:
var input = data.person;
if (input.Sal_cho === '' ) {
value = 'Unspecified';
} else if (input.Sal_cho === 'Mr' || input.Sal_cho === 'Dr(M)') {
value = 'Male';
} else {
value = 'Female';
}
Get Age
This piece of logic determines the age of a person based on the value of a date Form Field, and sets this as a field value.
Trigger:
var input = data.DOB_dt;
result = input !== undefined ? true : false;
Action:
var input = data.DOB_dt;
var age = (parseInt(moment().format('YYYYMMDD')) - parseInt(input.replace(/-/g, ''))) + '';
var dummy = age.replace(age.slice(- 4, age.length),'');
value = dummy === '' ? 0 : dummy;
Sum of Repeat Values
This piece of logic will calculate the sum of all instances of the input field inside the relevant repeat, and set this as a field value.
Trigger:
var rpt = data.Repeat_rpt;
result = rpt !== undefined ? true : false;
Action:
var rpt = data.Repeat_rpt;
var count = 0;
for (i=0;i<rpt.length;i++){
var input = rpt[i].Number_num;
if (input === '' || input === null || input === undefined) {input = 0}
count += parseInt(input);
}
value = count;
Build a Simple List from Repeat Values
This piece of logic will build a simple list of a repeated text field, and set this as a field's value.
Trigger:
var rpt = data.Repeat_rpt;
result = rpt !== undefined ? true : false;
Action:
var rpt = data.Repeat_rpt;
var Arr = [];
var string = '';
for (i=0;i<rpt.length;i++){
var input = rpt[i].Field_txt;
if (input !== '') {Arr.push(input)}
}
if (Arr.length>0) { string = Arr[0] }
if (Arr.length>1) {
for (i=1;i<Arr.length-1;i++) {
string += ', ' + Arr[i];
}
string += ' and ' + Arr[Arr.length-1];
}
value = string;
Comments
0 comments
Article is closed for comments.