PingOne

Core library

You can perform basic conditional expressions using if-else and switch alternatives.

String Description

Any ifelse(Boolean <condition>, Any <value>, Boolean <elseifCondition<1…​10>>, Any <elseifValue<1…​10>>, Any <elseValue>)

where:

  • <condition> is the primary If conditional expression which should evaluate to a boolean value. If it is not boolean, every attempt will be made to convert it to a boolean value.

  • <value> is the value to use if the primary condition evaluates to true.

  • <elseifCondition<1…​10>> is an elseIf conditional expression which should evaluate to a boolean value. If it is not boolean, every attempt will be made to convert it to a boolean value. The elseIfValue should always follow the elseIf condition.

  • <elseifValue<1…​10>> is the value to use if the related elseIf condition evaluates to true.

  • <elseValue>> is the value to use if none of the conditions evaluate to true.

Library function for an If-Else statement. Expressions provided for If and elseIf conditions should evaluate to a boolean value and if not, every attempt will be made to convert the evaluated value to boolean.

If the condition evaluates to a Number, any value greater than 0 will be treated as True, or else false. If the condition evaluates to a String, the values true, on, y, t, yes are treated as true irrespective of the case, and otherwise false. If the condition evaluates to something other than Boolean, Number or String, it will be treated as false.

The If statement and elseIf statement is a pair: a condition and a value to be used if condition evaluates to true. The elseIf statements are optional, and can enter 0 to 10 elseIf statements as needed.

The elseValue to be used if no condition evaluates to true is also optional and is always the last parameter in the method.

Any switchExpr(Any <valueToFind>, Any <choiceToMatch1>, Any <valueToReturn1>, Any <choiceToMatch<2…​10>>, Any <valueToReturn<2…​10>>, Any <defaultValue>)

where:

  • <valueToFind> is the value against which all the choices are compared with to identify the match.

  • <choiceToMatch1> is the choice to match.

  • <valueToReturn1> is the value to use or return if the valueToFind matches the corresponding valueToMatch.

  • <choiceToMatch<2…​10>> are additonal and optional choices to match.

  • <valueToReturn<2…​10>> is the value to use or return if the valueToFind matches the corresponding choiceToMatch<n>.

  • <defaultValue> is the value to use if no matching choice is found for valueToFind. If this is not provided, null is returned.

Library function for a switch statement. A <valueToFind> is compared against 1 or more choices to match (<choiceToMatch<1…​10>>).

If a match is found, the value corresponding to the matched choice (<valueToReturn<1…​10>>) is returned. If no match is found, <defaultValue> is returned if provided, or else null.

<choiceToMatch<n>> and <valueToReturn<n>> are a pair and there should be a minimum of 1 pair and not exceed 10 pairs. A default value can be provided as the last parameter to the method.

Examples

String Input

Any ifelse(Boolean <condition>, Any <value>, Boolean <elseifCondition<1…​10>>, Any <elseifValue<1…​10>>, Any <elseValue>)

{
  user: {
    type: "User"
  }
}
#core.ifelse(user.type == 'Administrator', 'Full Access', user.type == 'User', 'Restricted Access', 'No Access')

returns Restricted Access

{
  user: {
    memberOfGroupIDs: ["User"],
    type: "Dev"
  }
}
#core.ifelse(#data.indexOf(user.memberOfGroupIDs, 'Administrator') >= 0, 'Full Access',
	#data.indexOf(user.memberOfGroupIDs, 'User') >= 0,
	#core.ifelse(user.type == 'SRE', 'Power Access', user.type == 'Dev', 'Debugging Access', 'Read Access'), 'No Access')

returns Debugging Access

Any switchExpr(Any <valueToFind>, Any <choiceToMatch1>, Any <valueToReturn1>, Any <choiceToMatch<2…​10>>, Any <valueToReturn<2…​10>>, Any <defaultValue>)

{
  user: {
    type: "Administrator"
  }
}
#core.switchExpr(user.type, 'Administrator', 'Full Access')

returns Restricted Access

{
  user: {
    type: "User"
  }
}
#core.switchExpr(user.type, 'Administrator', 'Full Access', 'User', 'Restricted Access', 'No Access')

returns Restricted Access