Combining strings

There are 3 ways of combining values in Orgvue into strings

  1. format()
  2. concat()
  3. join()

You want to add currency to total annual compensation by combining two existing properties; total annual compensation and ccy (currency)

Format

format() is the simplest and most efficient and so is recommended

It has the syntax node.format('x'), where x is the set of properties or other values you want to combine

The format() method allows you to combine as many values as you want without having to repeat node.

e.g. You want to add ‘years’ at the end of tenure years

Use format() and define the format you want to print out using {property name} and text

Putting the property name within { } returns the value for that property for the current node

You can define a desired format combining properties and words within double quotes – here one property and one word

node.format("{tenureyears} years")

A space between {tenureyears} and “years” prints out a space

image

format() method can work both for numbers and strings (text)

Other examples

Joining two properties

node.format("{firstName} {lastName}")

image

Joining property and text

node.format("{age} years old")

image

Joining number property and number text

node.format("{performanceRanking} / 10")

image

Notes: properties of the node need to be inserted in curly braces {}. Anything outside those braces will be treated as a value

  • A. Correct syntax node.format("{CurrentSalary} ({ccy})")
  • B. Incorrect Syntax node.format("{CurrentSalary} (ccy)")

image

All values you want to combine must be wrapped inside brackets () and single or double quotation marks

Concat

concat() is a more limited function because it only allows you to combine two values, e.g. value1.concat(value2)

You can get round this by chaining together multiple concat() expressions in the form value1.concat(value2).concat(value3) though it is a clumsy approach

Another issue is that concat does not allow you to specify any delimiters, so the values must be joined together as is

The advantage concat() has over format() is that it allows the values being combined to be at two different hierarchical levels

e.g. Join Node Full Name and Parent Node Department

String(node.fullname).concat(node.p.department)

image

If you are using a specified value, rather than a reference to a property, you cannot use this as the first value, and it must be wrapped in quotation marks within the concat() brackets

e.g.

String(node.fullname).concat(" Parent Department: ").concat(node.p.department)

image

Join

join() is a combination of the best parts of format() and concat()

Like format() it allows you to specify multiple values and include delimiters, but as with concat() it accepts these values being at different hierarchical levels

join() is applied at the end of an array enclosed in square brackets []

The delimiter used when combining the items in the array is then specified within the ("") after the .join

[value1, value2],join('delimiter')

e.g.:

[node.fullName, node.department, node.location].join(" - ")

image

Join with Conditional Logic

Another advantage of join() is that it allows you to make use of Conditional Logic when defining how to combine values e.g.:

[node.department, " (", String(node.grade) == "E" ? "Contractor / Other" : node.grade, ")",].join("")

image

results matching ""

    No results matching ""

    results matching ""

      No results matching ""