RAD function: index

A RAD function that returns the index or position number for the value of a specific element in an array or a character in a string. If the target value is not in the array or string, NULL is the return.

Function

index

Format

index(target value, $variable, starting position #)

Parameters

The target value variable is the value you are searching for in the array or string.

The $variable variable is the name of the variable to be searched.

The starting position # variable is the index in the array or position in the string where the search will begin. The default value is 1).

Factors

  • The index() function operates identically for arrays, regardless of the data type in the array.
  • If the array is composed of structures or of arrays, the target variable must exactly match the structure or array.

    For example, the function does not allow selecting a field from a structure.

  • You can use the index function to search for any value by converting both the value and the search variable to the same type.

    For example, if you want to search for the $problem.number variable on all forms, you could pass the following query to the select panel:

    index(“$problem.number”, str(field))

    The index function searches for the $problem.number variable in the field field of the format table.

  • When you use the index() function in a query, ITSMA Service Management evaluates the function based on database case sensitivity.

    For example, if you use the Expert Search option on the Incident Management search screen, and search for index(“Windows Server”, brief.description) > 0:

    • On a case insensitive database, the query returns all records where the brief.description field contains windows server or WINDOWS SERVER or Windows SERVER, and so on.
    • On a case sensitive database, the query only returns records where the brief.description field contains exactly Windows Server.
  • When you use the index() function in a RAD or JavaScript expression and not within a query, ITSMA Service Management evaluates it case sensitively (regardless of the database setting).

    For an example, consider the following RAD or JavaScript expressions:

    • The expression index(“Windows Server”, {“WINDOWS SERVER”, “windows server”}), returns 0.
    • The expression index(“Windows Server”, {“WINDOWS SERVER", “Windows Server”, “windows Server”}), returns 2.

Example

index(1,{1,2,3}) returns 1

index(2,{1,2,3}) returns 2

index(1,{1,2,3},2) returns 0

index(2,{1,2,3},2) returns 2