30 additional methods to the Global class

February 27, 2019

Global class is a standard class that contains a lot of small static functions. This post describes additional functions that extend it. To avoid using prefixes, all functions were added into the separate static class DEV. It exists in the DEVCommon model. As common practice, you can copy this class into your application as it is, or rename it according to your model name(e.g. ABC)

DEV class methods

buf2Buf

Copies one cursor to another using field names(standard buf2Buf uses IDs). So you can copy values between different tables

static void buf2Buf(Common _dest, Common _source, container _fieldsToExclude = conNull())
static void buf2BufMerge(Common _dest, Common _source)

canBeConverted, convertQty

The same functions as UnitofMeasureConverter::canBeConverted and ::convert but with the string parameters instead of RecIds

public static client server boolean canBeConverted(
        UnitOfMeasureSymbol     _fromUnitOfMeasure,
        UnitOfMeasureSymbol     _toUnitOfMeasure,
        ItemId                  _ItemId)

qty

Rounds the value according to unit settings

static Qty qty(Qty  _qty, UnitOfMeasureSymbol  _unit)

cObject

Casts parameter to Object

static Object cObject(Object  _obj)
{  return _obj;   }

countTotalQuick

Calculates the number of records in the query using Count(RecId). Standard SysQuery::countTotal switches to the loop mode when the query contains more than 1 DataSource.

static Integer countTotalQuick(QueryRun _queryRun)

copyRanges

Copies DataSource ranges

static void copyRanges(QueryBuildDataSource _qbdsTarget, QueryBuildDataSource _qbdsSource)

datasourceRangesAsText

Gets a string, that contains all ranges values. Used in reports to display current filter values in the report header.

static Notes datasourceRangesAsText(QueryBuildDataSource _sourceDS)

date2DateTime, dateTime2Date

Converts date to DateTime using UserPreferredTimeZone

static utcDateTime date2DateTime(TransDate _date, boolean _isEndOfDay = false)
static date dateTime2Date(utcDateTime _dateTime)

systemdateget

Returns the current date. It is still unclear for me, why the original method was marked as obsolete

static TransDate systemdateget()
{ return DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()); }

dateStartWk, dateStartYr

Returns the start of the week, the start of the year

static TransDate  dateStartWk(TransDate _transDate)
static TransDate  dateStartYr(TransDate _transDate)

dsAllowEditExceptFields

Enable or disable all form DS fields, except specified

static void dsAllowEditExceptFields(FormDataSource _formDataSource, boolean _allowEdit, container _fieldListExclude=connull())

dsGetDisabledFields

Get a list of the disabled fields. Used with the previous function when Datasource contains some code, that disables some fields, before dsAllowEditExceptFields call.

static container dsGetDisabledFields(FormDataSource _formDataSource)

dsRefresh, dsResearch, dsExecuteQuery

Performs datasource refresh/research/executeQuery

static void dsRefresh(Common  _record)
static void dsResearch(Common _record, NoYes _savePosition = NoYes::Yes)
static void dsExecuteQuery(Common _record, NoYes _savePosition = NoYes::Yes)

getFormRunFromFormArgs

Gets the calling form from the current form args

static Object getFormRunFromFormArgs(FormRun  _element, IdentifierName _formName)

queryHasRecord

Checks, that the query has a record. The common usage scenario is when you need to create a custom lookup for the field. In this case, you create a query for this lookup, create the lookup based on this query and add a check into the validateWrite() method to check that the entered value(user can enter the value using the manual entry) exists in this query

static boolean queryHasRecord(Query  _q)

isUserInRole

Is the current user included into the role

static boolean isUserInRole(Description  _roleName)

purchTableConfirm

Confirms a purchase order

static void  purchTableConfirm(PurchTable  _purchTable)

runButtonWithRecord

Executes menu item button with the specified record

static void runButtonWithRecord(FormFunctionButtonControl _button, Common _record,
                                               Object _obj = null)

validateCondition

Validates the specified condition

static boolean validateCondition(anytype _condition, str _message, boolean _isThrowError = false)

validateCursorIsNotEmpty

Performs if (! A.RecId) {throw error("..")}

static void validateCursorIsNotEmpty(Common  _common, str _someText = '')

validateCursorField

Checks that the field is not empty and generates a message

static boolean validateCursorField(Common _table, fieldId _fieldId, boolean _isThrow = true)

validateWriteRecordCheck

Calls a validateWrite() method and generates an error if it fails

static void validateWriteRecordCheck(Common _record)

mergeInventDim

Merges 2 inventDim values

public static InventDim mergeInventDim(
        InventDimGroupSetup         _dimGroupSetup,
        InventDim                   _fromInventDim,
        InventDim                   _addedDim)

w

Displays the current value - info(StrFmt('%1',_i));, using mostly for debug purposes.

static void w(anytype _i, str _addition = '')

Summary

You can download this class using the following link https://github.com/TrudAX/XppTools/blob/master/DEVCommon/DEVCommon/AxClass/DEV.xml

If you know some other helpful functions feel free to create a GitHub pull request or leave a comment.


Tagged with:
Denis Trunin
Written by Denis Trunin

Get notifications about new posts on Twitter, RSS .