Jump to content

Input special characters between field values


Fabian

Recommended Posts

Hi, how can I write a rule that will input " | " between values? There will be 15 fields available to use, but not all fields are used all the time. So an example would be:

 

Field1 | Field2 | Field3

or

Field1 | Field2 | Field3 | Field4 | Field5 | Field6

or

Field1

Link to comment
Share on other sites

return [
 Field('Field1'),
 Field('Field2'),
 Field('Field3'),
 Field('Field4'),
 Field('Field5'),
 Field('Field6'),
 Field('Field7'),
 Field('Field8'),
 Field('Field9'),
 Field('Field10'),
 Field('Field11'),
 Field('Field12'),
 Field('Field13'),
 Field('Field14'),
 Field('Field15')
].filter(String).join(' | ');

 

Or if your fields are really named "Field" + number, you could create the array with a for loop:

var fields = [];
for (var i = 1; i <= 15; i++) 
 fields.push(Field("Field" + i));
return fields.filter(String).join(' | ');

 

The '.filter(String)' method removes any elements in the array that aren't strings – any fields that aren't used. The '.join(" | ")' method joins the remaining elements in the array with a space, a pipe and a space.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...