IMCScript supports rich library set, which can help user define custom logic with minimal lines of code using inbuilt functions and constants.

## Math Constants

Below are the constants, which can be used in script to make it more readable.

## Language Constants

For the reasons of utility, there are Language constants which helps to get standard language-country codes as per international norms. For time being, few frequently used language-codes have been exposed, eventually can be added more. Below are the examples.

## Standard Functions

### Summation (sum)

Finds summation of all values.

### Multiplication (mul)

Finds multiplication of all values.

### Absolute (abs)

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

### Maximum (max)

Returns greatest number from the provided numbers.

### Minimum (min)

Returns smallest from the provided numbers.

### Average (avg)

Finds average of the provided numbers.

Note: This function is same as Mean function under Statistic domain.

### Greatest Common Divisor (gcd)

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

### Least Common Multiplier (lcm)

Returns Least Common Multiplier (LCM) of the provided numbers.

## Convergence Functions

### Round (round)

Rounds the number to specified decimal digits.

Note: In absence of second argument, default decimal digits will be considered 2.

### Ceiling (ceil)

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

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

### Floor (floor)

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

## Statistical Functions

### Mean (mean)

Finds average of the numbers

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

### Median (median)

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

### 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).

## Exponential Functions

### Power (pow)

Finds n^{th} power of the number.

### Root (root)

Finds n^{th} root of the number. If multiple roots exist, function returns only positive root of it.

### 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).

### 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).

### 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).

## Trigonometric Functions

### Degree to Radian (rad)

Converts degree to radian and returns it.

### Radian to Degree (deg)

Converts radian to degree and returns it.

### Sine (sin)

Returns sine value of a double value.

### Cosine (cos)

Returns cosine value of a double value.

### Tangent (tan)

Returns tangent value of a double value.

### 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.

### 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.

### 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.

## 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.

### 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).

## Parsing Functions

Parsing functions helps to parse one data type into another.

## 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).

### isNan

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

## ExpressionBean Functions

### intersection

Applies intersection between ExpressionBean.

### substraction

Applies subtraction between ExpressionBean.

### union

Applies union between ExpressionBean.

### contains

Checks if an ExpressionBean contains specific element in it.

### indexOf

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

### equals

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

### 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”).

### distinct

Returns distinct elements of the ExpressionBean.

### 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”).

### size

Returns size (number of elements) of the ExpressionBean.

## 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.

### getGeoJSON

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

## 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.

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.

### 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.

### 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.

## 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.

### 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.

### 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.

### 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.

### 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.

### 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).

## System Functions

### log

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

### push

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

## List Functions

### add

Adds an element into the List.

### delete

Deletes an element from the List.

### deleteAt

Deletes an element at certain index from the List.

### contains

Checks if List contains specific element in it.

### indexOf

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

### equals

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

### sort

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

### distinct

Returns distinct elements of the list.

### size

Returns size (number of elements) of the list.

## Map Functions

### add

Adds a Key-Value pair into the Map.

### keys

Returns List of Keys from Map.

### values

Returns List of Values from Map.

### size

Returns size (number of pairs) of the Map.

## Comments

0 comments

Article is closed for comments.