IMCScript built-in functions

Prev Next

IMCScript supports a rich library set to help you define custom logic. Use built-in functions and constants to minimize coding requirements.

Math constants

Use the following constants in scripts to make them more readable.
image.png

Language constants

Language constants help get standard language-country codes in accordance with international norms. At present, we support only a frequently used language-codes; for example:

image.png

Standard functions

Summation (sum)

Finds summation of all values.
image.png

Multiplication (mul)

Finds multiplication of all values.
image.png

Absolute (abs)

Gives absolute value (also called - mode) of the number.
image.png

Maximum (max)

Returns the greatest number of the provided numbers.
image.png

Minimum (min)

Returns the smallest number of the provided numbers.
image.png

Average (avg)

Finds the average of provided numbers.

This function is the same as the Mean function under Statistic domain.

image.png

Greatest common divisor (gcd)

Returns Greatest Common Divisor (GCD) of the provided numbers.
image.png

Least common multiplier (lcm)

Returns the least common multiplier (LCM) of the provided numbers.
image.png

Convergence functions

Round (round)

Rounds the number to specified decimal digits.
image.png

In the absence of a second argument, default decimal digits are two.

Ceiling (ceil)

Rounds a number up to the next largest whole number or integer.

Math.ceil(null) returns integer 0 and does not give a NaN error.

image.png

Floor (floor)

Returns the largest integer less than or equal to a given number.
image.png

Statistical functions

Mean (mean)

Finds the average of the numbers.

Note: This function is same as Average function given under general functions.
image.png

Median (median)

Finds the value separating the higher half from the lower half (or the middle value)
image.png

Mode (mode)

Finds the number which appears most often in a set of numbers.

Note: This method doesn’t guarantee any order of outcomes (modes).
image.png

Exponential Functions

Power (pow)

Finds nth power of the number.
image.png

Root (root)

Finds nth root of the number. If multiple roots exist, function returns only positive root of it.
image.png

Square (sq)

Finds square of a number.

Note: This is special case of Power method with exponent 2, hence it’s same as calling pow(n,2).
image.png

Square Root (sqrt)

Returns positive square root of a number.

Note: This is special case of Root method with root 2, hence it’s same as calling root(n,2).
image.png

Cube Root (cbrt)

Returns cube root of a number.

Note: This is special case of Root method with root 3, hence it’s same as calling root(n,3).
image.png

Trigonometric Functions

Degree to Radian (rad)

Converts degree to radian and returns it.
image.png

Radian to Degree (deg)

Converts radian to degree and returns it.
image.png

Sine (sin)

Returns sine value of a double value.
image.png

Cosine (cos)

Returns cosine value of a double value.
image.png

Tangent (tan)

Returns tangent value of a double value.
image.png

Arc Sine (asin)

Returns arc-sine value of a double value.

Note: arc-sin is nothing but inverse of Sine function, hence practically it returns radian for the provided value.
image.png

Arc Cosine (acos)

Returns arc-cosine value of a double value.

Note: arc-cosine is nothing but inverse of Cosine function, hence practically it returns radian for the provided value.
image.png

Arc Tangent (atan)

Returns arc-tangent value of a double value.

Note: arc-tan is nothing but inverse of Tangent function, hence practically it returns radian for the provided value.
image.png

Logarithmic Functions

Logarithm (log)

Calculates and returns logarithmic value of a number using provided base.

Note: In absence of second argument, default base will be considered e = 2.718281828459045, which is the base of natural algorithms.
image.png

Base 10 Logarithm (log10)

Calculates and returns logarithmic value of a number using base 10.

Note: This is special case of Logarithm method with base 10, hence it’s same as calling log(n,10).
image.png

Parsing Functions

Parsing functions helps to parse one data type into another.
image.png

Check Functions

isFinite

Checks if number is finite or not. It returns true if the argument is a finite value; returns false otherwise (For NaN and Infinity arguments).
image.png

isNan

Checks if number is NaN(not a number) or not. It returns true if the argument is a NaN; returns false otherwise.
image.png

ExpressionBean Functions

intersection

Applies intersection between ExpressionBean.
image.png

substraction

Applies subtraction between ExpressionBean.
image.png

union

Applies union between ExpressionBean.
image.png

contains

Checks if an ExpressionBean contains specific element in it.
image.png

indexOf

Finds an index of a specific element inside the ExpressionBean. In case element doesn’t exists, it returns -1. 
image.png

equals

Finds if both ExpressionBean (Single or Collection) are equivalent to each other or not. This is same as using Equality operator.
image.png

sort

Sorts ExpressionBean respect to IMCExpression (“this.salesItemPosition”) in given direction (Ascending: “ASC” or Descending: “DESC”).

In case of absence of IMCExpression, internally it uses ToString method to sort. In case of absence, default direction considered it Ascending: (“ASC”).
image.png

distinct

Returns distinct elements of the ExpressionBean.
image.png

filter

Filters ExpressionBean respect to IMCExpression (“this.salesItemPosition”) in given direction (Ascending: “ASC” or Descending: “DESC”).

In case of absence of IMCExpression, internally it uses ToString method to filter. In case of absence, default direction considered it Ascending: (“ASC”).
image.png

size

Returns size (number of elements) of the ExpressionBean.
image.png

ExpressionBean (SalesItem) Functions

There are special methods, which is an extension of ExpressionBean library, which has specific use case and they can only be called on SalesItem ExpressionBean. Such methods currently touch upon two different entities: Dynamic Attribute and GoogleMap.

Dynamic Attribute (DA) methods

DA specific methods are self-explanatory from given examples here.
image.png

getGeoJSON

Currently the only Google Map specific method available is shown below.
image.png

GeoJSON Functions

GeoJSON is a standardized format for encoding a variety of geographic data structures. In MX, this format is used to store the features drawn on the Google Map in a Quote.

Users can view the GeoJSON data of a map by clicking on the download button at the bottom left corner when opening the map window.
image.png

The downloaded file will have a json extension, which may be opened with a text editor. The content of the file will be of a similar format to the example shown below. The important features are:

  • Each feature drawn on the map (e.g. a marker, a line, or a polygon) will have a corresponding entry listed under “features”.
  • Each feature entry will include a description of its geometry (with all the coordinates of the points needed to construct it, in terms of their latitude and longitude and a list of custom properties it has.
  • In MX, a feature may be identified by either its id (only for predefined objects such as the normalized rectangle or the slope arrow) or by its assigned type.

image.png

isFeaturePresent

This function checks whether an expected feature has been drawn on the map. The expected input is either the id of the feature, or its type URI.
image.png

getProperty

This function retrieves the value of a custom property for the given feature. If the feature cannot be found or if it doesn’t have such a property, it will return an empty result. The properties that are available for each feature can be confirmed by looking at the downloaded json file.

Note that, only for point features (i.e. markers), it will also work with ‘latitude’ and ‘longitude’ as the property name (to retrieve the coordinate of the point), although these are not custom properties of the feature.
image.png

LookupTable Functions

table

This function sets the Lookup Table to retrieve data from. It returns the DBLookupTable again, thus allowing other methods to be chained after it.

This method must have been called before the search or searchOne function is called, or the script will end in failure.
image.png

addSelectFields

This function sets which lookup fields to retrieve. Any number of fields can be specified as input. It returns the DBLookupTable again, thus allowing other methods to be chained after it.

This method is optional, if not called, all lookup fields will be retrieved. Note that if the method is called for a second time, it will overwrite the previous setting.
image.png

addCondition

This function sets the condition for retrieving the data. It returns the DBLookupTable again, thus allowing other methods to be chained after it.

All Conditional Operators (Except Ternary) are supported. Using any unsupported operators will result in script failure.

This method is optional, if not called, all lookup records will be retrieved without restrictions. This method may be called multiple times, and the conditions will be chained together. The lookup records that are retrieved must meet all the conditions specified.
image.png

addOrderBy

This function sets how the resulting records should be sorted. It returns the DBLookupTable again, thus allowing other methods to be chained after it.

For sort_type, only ‘ASC’ or ‘DESC’ will be accepted.

This method is optional, if not called, the lookup records will be retrieved sorted by ID. This method may be called multiple times, and the conditions will be chained together. The lookup records that are retrieved will be sorted by each of the fields in turn, starting with the first one.
image.png

search

This function retrieves the data from the specified lookup table based on any conditions that has been set previously. It will return the data as a List, even if there is only 1 record that meet the criteria.
image.png

searchOne

This function retrieves the data from the specified lookup table based on any conditions that has been set previously. It will return the data as a Map. If there is more than 1 record that meet the criteria, it will only return the first one (based on the sort order).
image.png

System Functions

log

Logs message of appropriate type (ERROR/WARNING/INFO) under IMCScript Audit log.
image.png

push

Pushes notification of appropriate type (ERROR/WARNING/INFO) on UI.
image.png

List Functions

add

Adds an element into the List.
image.png

delete

Deletes an element from the List.
image.png

deleteAt

Deletes an element at certain index from the List.
image.png

contains

Checks if List contains specific element in it.
image.png

indexOf

Finds an index of a specific element inside the List. In case element doesn’t exists, it returns -1.
image.png

equals

Finds if both Lists are equivalent to each other or not. This is same as using Equality operator.
image.png

sort

Sorts List in given direction (Ascending: “ASC” or Descending: “DESC”). In case of absence, default direction considered it Ascending: (“ASC”).
image.png

distinct

Returns distinct elements of the list.
image.png

size

Returns size (number of elements) of the list.
image.png

Map Functions

add

Adds a Key-Value pair into the Map.
image.png

keys

Returns List of Keys from Map.
image.png

values

Returns List of Values from Map.
image.png

size

Returns size (number of pairs) of the Map.
image.png