Library of System Functions for Custom Scripts

When you're creating your custom scripts, you can use a feature that enables you to use System Functions that auto-populate APIs into your script. Type Control + Space, scroll down to the System Functions section, and you'll see a list of APIs that you can use. Here are more details about the System Functions and their related classes.

System Functions

These are the System Functions that are available:

Method Signature

Definition

Usage

getCurrentRow()

Returns the current row.

For information about the Row class methods, refer to the table below.

const taskRow = getCurrentRow();
const statusCode = taskRow.getColumn('StatusCode');

getCurrentChildRow()

Returns the current child row if we are in context of a child row, else it returns null.

Refer to the Row class methods in the next table.

const optyRow = getCurrentRow();
const childRev = getCurrentChildRow();
childRev.setColumn('RevnAmountCurcyCode', optyRow.getColumn('CurrencyCode'));

createNewRow(isChild: boolean, featureName: string, childType: string)

Creates new row or child row for the given resource and child type. Only supported in AfterSave event.

Refer to the Row class methods in the next table.

const opptyRow =  createNewRow(false, "Opportunity", null);
opptyRow.setColumn("Name","New oppty");
Note: The use of this API is recommended for creating a row for the top level resource only. For creating a child of a top level resource, please refer to addNewChildRow under Row class.

query(resource: string)

Returns Query object for the given resource. This can be used to query rows of the given resource by setting query parameters. This function only queries for data stored locally on the device.

Refer to the Query class methods in the next table.

const currentRow = getCurrentRow();
const userPrefProvider = getUserPreferences();
const resourceQuery = query('resources');
resourceQuery.setParameters('PartyId', userPrefProvider.getPartyId());
let cxCoreLogger = getCXCoreLogger().getLogger();
try {
const resourceResponse = resourceQuery.execute();
if (resourceResponse && resourceResponse.length > 0) {
currentRow.setColumn('JobName',resourceResponse[0].getColumn('JobMeaning'));
}
} catch (e) {
//failed to get resource response
cxCoreLogger.error("Query on resources failed");
}
Note: This API is for querying on the basis of primary key only. To query using any other field please refer to the queryWithParameters API below.

getUserPreferences()

Returns UserPreferences object. This can be used to retrieve different user preferences.

For information about the UserPreferences class methods, refer to the table below.

const row = getCurrentRow();
const userPrefProvider = getUserPreferences();
const closeDate = userPrefProvider.getProfileOptionValue(
'MOO_DEFAULT_CLOSE_WINDOW'
);

getDeviceInformation()

Returns DeviceInformation object. This can be used to retrieve different device related information.

Refer to the DeviceInformation class methods in the next table.

const deviceInfo = getDeviceInformation();
const os = deviceInfo.getOs();

getCXCoreLogger().getLogger()

Returns an instance of CXCoreLogger which can be used for logging info, error, warnings, and so on.

Refer to the CXCoreLogger class methods in the next table.

const currentRow = getCurrentRow();
const userPrefProvider = getUserPreferences();
const resourceQuery = query('resources');
resourceQuery.setParameters('PartyId', userPrefProvider.getPartyId());
let cxCoreLogger = getCXCoreLogger().getLogger();
try {
const resourceResponse = resourceQuery.execute();
if (resourceResponse && resourceResponse.length > 0) {
currentRow.setColumn('JobName',resourceResponse[0].getColumn('JobMeaning'));
}
} catch (e) {
//failed to get resource response
cxCoreLogger.error("Query on resources failed");
}

getParentRow()

Returns the parent object from which the current object was accessed. Only to be used in context of top level objects being visited via another top level object.

Note: This function doesn't return the parent for a child row.

Refer to the Row class methods in the next table.

/*Appointments - OnCreate*/
const row = getCurrentRow();
const parentRow = getParentRow();

if (parentRow && parentRow.getResourceName() === 'leads') {
row.setColumn(
'LeadId',
parentRow.getColumn('LeadId')
);
row.setColumn(
'LeadName',
parentRow.getColumn('Name')
);
if (parentRow.getColumn('PrimaryContactId')) {
row.setColumn(
'PrimaryContactId',
parentRow.getColumn('PrimaryContactId')
);
row.setColumn(
'PrimaryContactName',
parentRow.getColumn('PrimaryContactPartyName')
);
}
if (parentRow.getColumn('CustomerId')) {
row.setColumn(
'AccountId',
parentRow.getColumn('CustomerId')
);
row.setColumn(
'AccountName',
parentRow.getColumn('CustomerPartyName')
);
}
}

getLovDataProvider()

Returns local list of values (LOV) data provider. The LOV data can be fetched using this provider.

const row = getCurrentRow();
const userPrefProvider = getUserPreferences();
const territory = userPrefProvider.getTerritory();
const lovProvider = getLovDataProvider();
const countryCodeLov = lovProvider.getLovData('WorkPhoneCountryCode');
if (countryCodeLov) {
  let locale;
  for(let i =0 ; i < countryCodeLov.length ; i++) {
    if(countryCodeLov[i].TerritoryCode === territory) {
     locale = countryCodeLov[i];
    }
  }
  if(locale) {
    if (row.getColumn('MobileCountryCode') == null || row.isNew()) {
          row.setColumn('MobileCountryCode', locale.PhoneCountryCode);
    }
    if (row.getColumn('WorkPhoneCountryCode') == null || row.isNew()) {
           row.setColumn('WorkPhoneCountryCode', locale.PhoneCountryCode);
    }
   }
}

queryWithParameters (resource: string, dynamicParams: array)

Used to query for records by passing dynamic fields, operator, and values.

let currentRow = getCurrentRow();
let q = queryWithParameters('opportunities', [{'field': 'Name', 'operator': 'contains', 'value': 'testQ'}]);
let rows = q.execute();
if(rows && rows.length > 0) {
    let account = rows[0].getColumn('TargetPartyId');
    currentRow.setColumn('TargetPartyId',account);
}

Class Methods

Here are the class methods for the System Functions outlined in the previous table and examples of how you can use them.

  • Row Class Methods:

Method Signature

Definition

Usage

setColumn(name: string, value: string)

Used to set value of a particular column of the row.

const optyRow = getCurrentRow();
const childRev = getCurrentChildRow();
childRev.setColumn('RevnAmountCurcyCode', optyRow.getColumn('CurrencyCode'));

getColumn(name: string)

Used to get value of a particular column of the row.

const taskRow = getCurrentRow();
const statusCode = taskRow.getColumn('StatusCode');

isNew(): boolean

Returns true if the row is new else it returns false.

const taskRow = getCurrentRow();
const isNew = taskRow.isNew();

getResourceName(): string

Returns the resource to which the row belongs.

const parentRow = getParentRow();
const res = parentRow.getResourceName()

setColumnMandatory(name: string, value: boolean)

Used to set value of mandatory property for a particular column.

Note: Use this function instead of the CX Cloud Mobile function if you're copying your CX Cloud Mobile script.
const optyRow = getCurrentRow();
const childRev = getCurrentChildRow();
childRev.setColumnMandatory('UnitPrice', true);

setColumnUpdatable(name: string, value: boolean)

Used to set value of updatable property for a particular column.

const optyRow = getCurrentRow();
const childRev = getCurrentChildRow();
childRev.setColumnUpdatable('RevnAmountCurcyCode', canEditCurrency === 'Y');

setColumnVisible(name: string, value: boolean)

Used to display/hide a particular column.

const row = getCurrentRow();
row.setColumnVisible('ReasonWonLostCode', false);

addNewChildRow(childName: string)

Adds new child to the row.

const row = getCurrentRow();
const resources = row.addNewChildRow('ActivityAssignee');
resources.setColumn('AssigneeName', userPrefProvider.getPartyName());
resources.setColumn('AssigneeId', userPrefProvider.getPartyId());

setColumnDisplayType(fieldName: string, DisplayType.TEXT | DisplayType.TEXTSCAN | DisplayType.NUMBER)

Used to change the display type of a field to text, scan or number.

let row = getCurrentRow();
row.setColumnDisplayType("MyCustomSerialNumber",DisplayType.TEXTSCAN);

disableAction(action: string, disable: boolean)

Used to disable or enable the save action in the edit view.

let optyRow = getCurrentRow();
optyRow.disableAction('Save',true);

getOriginalValues()

Used to get the original values of a field before it was modified.

const row = getCurrentRow();
let oriVal = row.getOriginalValues();
let oriName = oriVal.Name;
let currName = row.getcolumn('Name');
  • Query Class Methods:

Method Signature

Definition

Usage

getParameters()

Used to get all available parameters for this query.

let oracleCxmOutcome = new Result('');
let currentRow = getCurrentRow();
let id = currentRow.getColumn('OptyId');
let qT = query('opportunities');
let param = qT.getParameters()[0];
qT.setParameters(param,id);
let rows = qT.execute();
if(!rows || rows[0].getColumn('OptyId') !== id) {
oracleCxmOutcome.setErrorMessage("Query on current row failed");    
} else {
    oracleCxmOutcome.setMessage("MESSAGE_TYPE_SUCCESS","","Query successful");
}

setParameters(name: string, value: string)

Used to set value of a particular query parameter.

const resourceQuery = query('resources');
resourceQuery.setParameters('PartyId', userPrefProvider.getPartyId());

execute()

Used to perform the query. It returns the set of rows that satisfy the query criteria.

const resourceQuery = query('resources');
resourceQuery.setParameters('PartyId', userPrefProvider.getPartyId());
try {
const resourceResponse = resourceQuery.execute();
if (resourceResponse && resourceResponse.length > 0) {
resources.setColumn(
'JobName',
resourceResponse[0].getColumn('JobMeaning')
);
}
} catch (e) {
//failed to get resource response
}
  • UserPreferences Class Methods:

Method Signature

Definition

Usage

getUserSettings()

Returns user settings.

const userPref = getUserPreferences();
const userSettings = userPref.getUserSettings();

getUserName()

Returns the user name for the current user.

const  userPref  = getUserPreferences();
const userName = userPref.getUserName();

getPartyName()

Returns name of the current user.

const  userPref  = getUserPreferences();
const partyName = userPref.getPartyName();

getDateFormat()

Returns date format set by the current user.

const  userPref  = getUserPreferences();
const dateFormat = userPref.getDateFormat();

getPartyId()

Returns ID of the current user.

const  userPref  = getUserPreferences();
const partyId = userPref.getPartyId();

getCurrency()

Returns currency set by the current user.

const  userPref  = getUserPreferences();
const currency = userPref.getCurrency();

getTimezone()

Returns time zone set by the current user.

const  userPref  = getUserPreferences();
const timeZone = userPref.getTimezone();

getNumberFormat()

Returns number format set by the current user.

const  userPref  = getUserPreferences();
const numberFormat = userPref.getNumberFormat();

getLanguage()

Returns language set by the current user.

const  userPref  = getUserPreferences();
const language = userPref.getLanguage();

getRoles()

Returns roles assigned to the current user.

const  userPref  = getUserPreferences();
const roles = userPref.getRoles();

getProfileOptions()

Returns all the profile options for the current user.

const  userPref  = getUserPreferences();
const profileOptions = userPref.getProfileOptions();

getProfileOptionValue(profileOption)

Returns profile option value of the specified profile option for the current user if the profile option exists, else it returns null.

const  userPref  = getUserPreferences();
const profileOptionValue = userPref.getProfileOptionValue($PROFILE_OPTION_STRING)

isRoleAssigned(role)

Returns true if the specified role is assigned to the current user else it returns false.

const  userPref  = getUserPreferences();
const isRoleAssigned = userPref.isRoleAssigned($USER_ROLE_STRING);

getDefaultBU()

Used to fetch the default BU of the current user. Refer to the Business Unit Class Method below.

let userPrefProvider = getUserPreferences();
let defaultBU = userPrefProvider.getDefaultBU();
  • DeviceInfo Class Methods:

Method Signature

Definition

Usage

getCurrentPosition(maximumAge : Number ,timeout : Number ,enableHighAccuracy : Boolean)

Returns the location of the device.

Parameters:

  • maximumAge: The time in milliseconds that's acceptable for cached position. Enter 0 if a cached position isn't acceptable.

  • timeout: The maximum length of time (milliseconds) that's allowed to pass from the call to navigator.geolocation.getCurrentPosition until the corresponding geolocationSuccess callback executes. If the geolocationSuccess callback isn't invoked within this time, the geolocationError callback is passed a PositionError.TIMEOUT error code.

  • enableHighAccuracy: Provides a hint that the application needs the best possible results. By default, the device attempts to retrieve a 'Position' using network-based methods. Setting this property to 'true' tells the framework to use more accurate methods, such as satellite positioning.

const deviceInfo = getDeviceInformation();
const position = deviceInfo.getCurrentPosition(3000,5000,true);    
const latitude  = position.coords.latitude;
const longitude = position.coords.longitude;

getOs()

Returns the operating system name for the device.

const deviceInfo = getDeviceInformation();
const os = deviceInfo.getOs();

getPlatform()

Returns platform name of the device.

const deviceInfo = getDeviceInformation();
const platform = deviceInfo.getPlatform();

getVersion()

Returns device version.

const deviceInfo = getDeviceInformation();
const version = deviceInfo.getVersion();

getModel()

Returns device model name.

const deviceInfo = getDeviceInformation();
const model = deviceInfo.getModel();

isDeviceOnline()

Returns true if the device is online, else false.

const deviceInfo = getDeviceInformation();
const online = deviceInfo.isDeviceOnline();
  • CXCoreLogger Class Methods:

Method Signature

Definition

Usage

setLogLevel(level: string)

Set logging level. Level values can be : info, error, warn, log, and none.

const row = getCurrentRow();
row.setColumn("Name","New oppty");
let cxCoreLogger = getCXCoreLogger().getLogger();
cxCoreLogger.setLogLevel("info");
cxCoreLogger.info ("On create event executed"

log(...args: any[])

Logs the message at log level.

const row = getCurrentRow();
row.setColumn("Name","New oppty");
let cxCoreLogger = getCXCoreLogger().getLogger();
cxCoreLogger.setLogLevel("log");
cxCoreLogger.log("On create event executed");

info(...args: any[])

Logs the message at info level.

const row = getCurrentRow();
row.setColumn("Name","New oppty");
let cxCoreLogger = getCXCoreLogger().getLogger();
cxCoreLogger.setLogLevel("info");
cxCoreLogger.info ("On create event executed");

warn(...args: any[])

Logs the message at warn level.

const row = getCurrentRow();
row.setColumn("Name","New oppty");
let cxCoreLogger = getCXCoreLogger().getLogger();
cxCoreLogger.setLogLevel("warn");
cxCoreLogger.warn("On create event executed");

error(...args: any[])

Logs the message at error level.

const row = getCurrentRow();
row.setColumn("Name","New oppty");
let cxCoreLogger = getCXCoreLogger().getLogger();
cxCoreLogger.setLogLevel("error");
cxCoreLogger.error("On create event executed");
  • Result Class Methods:

Method Signature

Definition

Usage

setModifiedObject()

Used to include a newly created row, or updated row, in the set of rows that the script has modified. This action will ensure that the included row is committed by event-handler implementation.

var oracleCxmOutcome = new Result('');
var row = getCurrentRow();
row.setColumn("Name","Sample Obj");
oracleCxmOutcome.setModifiedObject(row);
Note: Any row created or modified in an After Save event needs to be added using the Result object's setModifiedObject API, so that the changes are saved.

setMessage(key, stringBundle, message)

Used to add a message that can be returned to the event handler implementation. The key can be : "MESSAGE_TYPE_SUCCESS" or "MESSAGE_TYPE_ERROR".

var oracleCxmOutcome = new Result('');
var row = getCurrentRow();
row.setColumn("Name","Sample Obj");
oracleCxmOutcome.setModifiedObject(row);
oracleCxmOutcome.setMessage("MESSAGE_TYPE_SUCCESS","","Row modified");

setErrorMessage(message)

Used to set the error message and to mark the outcome qualifier as "OUTCOME_TYPE_FAILURE".

var oracleCxmOutcome = new Result('');
var row = getCurrentRow();
var a = row.getColumn("A");
var b = row.getColumn("B");
if(a>b){
oracleCxmOutcome.setErrorMessage("Row validation failed");
} else {
oracleCxmOutcome.setMessage("MESSAGE_TYPE_SUCCESS","","Row validated successfully");
}

setOutcomeQualifier()

Used to set qualifier to be handled post script execution. Returned string could be either"OUTCOME_TYPE_SUCCESS" or "OUTCOME_TYPE_FAILURE". If the qualifier "OUTCOME_TYPE_FAILURE" is used in the beforeSave event, then the page will show the error message set using setMessage/setErrorMessage.

var oracleCxmOutcome = new Result('');
var row = getCurrentRow();
var a = row.getColumn("A");
var b = row.getColumn("B");
if(a>b){
oracleCxmOutcome.setMessage("MESSAGE_TYPE_ERROR","","Row validation failed");
oracleCxmOutcome.setOutcomeQualifier("OUTCOME_TYPE_FAILURE");
}
  • Business Unit Class Methods:

Method Signature

Definition

Usage

getName()

Used to get name of the Business Unit.

let userPrefProvider = getUserPreferences();
let defaultBU = userPrefProvider.getDefaultBU();
let name = defaultBU.getName();

getBusinessUnitId()

Used to get BusinessUnitID.

let userPrefProvider = getUserPreferences();
let defaultBU = userPrefProvider.getDefaultBU();
let businessUnitId = defaultBU.getBusinessUnitId();

getBUName()

Used to get the Business Unit name.

let userPrefProvider = getUserPreferences();
let defaultBU = userPrefProvider.getDefaultBU();
let buName = defaultBU.getBUName();

getBUId()

Used to get BU ID.

let userPrefProvider = getUserPreferences();
let defaultBU = userPrefProvider.getDefaultBU();
let buID = defaultBU.getBUId();

getDefaultBUFlag()

Used to get default BUFlag.

let userPrefProvider = getUserPreferences();
let defaultBU = userPrefProvider.getDefaultBU();
let defaultBUFlag = defaultBU.getDefaultBUFlag();