機械翻訳について

カスタム・スクリプト用のシステム関数のライブラリ

カスタム・スクリプトを作成する際には、APIをスクリプトに自動移入するシステム関数が使用できるようになる機能を使用できます。 「コントロール+スペース」と入力し、「システム機能」セクションまで下にスクロールすると、使用できるAPIのリストが表示されます。 ここでは、システム関数とそれらに関連するクラスについて詳しく説明します。

システム関数

使用可能なシステム関数は次のとおりです。

メソッド・シグネチャ

定義

使用方法

getCurrentRow()

現在の行を返します。

Rowクラス・メソッドの詳細は、次の表を参照してください。

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

getCurrentChildRow()

子行のコンテキストにある場合は現在の子行を返し、それ以外の場合はnullを返します。

次の表のRowクラス・メソッドを参照してください。

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

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

指定されたリソースおよび子タイプの新しい行または子行を作成します。 AfterSaveイベントでのみサポートされています。

次の表のRowクラス・メソッドを参照してください。

const opptyRow =  createNewRow(false, "Opportunity", null);
opptyRow.setColumn("Name","New oppty");
ノート: トップ・レベル・リソースに対してのみ行を作成する場合に、このAPIを使用することをお薦めします。 トップ・レベル・リソースの子を作成する場合は、RowクラスのaddNewChildRowを参照してください。

query(resource: string)

指定されたリソースのQueryオブジェクトを返します。 これを使用して、問合せパラメータを設定することにより、指定したリソースの行を問い合せることができます。 この関数は、デバイスにローカルで格納されているデータのみを問い合せます。

次の表のQueryクラス・メソッドを参照してください。

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");
}
ノート: このAPIは、主キーのみに基づく問合せ用です。 他のフィールドを使用して問い合せるには、次のqueryWithParameters APIを参照してください。

getUserPreferences()

UserPreferencesオブジェクトを返します。 これを使用して、様々なユーザー・プリファレンスを取得できます。

UserPreferencesクラス・メソッドの詳細は、次の表を参照してください。

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

getDeviceInformation()

DeviceInformationオブジェクトを返します。 これを使用して、様々なデバイス関連情報を取得できます。

次の表のDeviceInformationクラス・メソッドを参照してください。

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

getCXCoreLogger().getLogger()

情報、エラー、警告などのロギングに使用できるCXCoreLoggerのインスタンスを返します。

次の表のCXCoreLoggerクラス・メソッドを参照してください。

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()

現在のオブジェクトへのアクセス元である親オブジェクトを返します。 別の最上位オブジェクトを介してアクセスされる最上位オブジェクトのコンテキストでのみ使用されます。

ノート: この関数は、子行の親を返すわけではありません。

次の表のRowクラス・メソッドを参照してください。

/*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()

ローカルの値リスト(LOV)データ・プロバイダを返します。 LOVデータは、このプロバイダを使用してフェッチできます。

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)

動的フィールド、演算子および値を渡してレコードを問い合せるために使用されます。

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);
}

クラス・メソッド

ここでは、前の表で概説したシステム関数のクラス・メソッドとそれらの使用方法の例を示します。

  • Rowクラス・メソッド:

メソッド・シグネチャ

定義

使用方法

setColumn(name: string, value: string)

行の特定の列の値を設定するために使用します。

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

getColumn(name: string)

行の特定の列の値を取得するために使用します。

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

isNew(): boolean

行が新しい場合はtrueを返し、それ以外の場合はfalseを返します。

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

getResourceName(): string

行が属するリソースを返します。

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

setColumnMandatory(name: string, value: boolean)

特定の列について必須プロパティの値を設定するために使用します。

ノート: CX Cloud Mobileのスクリプトをコピーする場合は、CX Cloud Mobileの関数のかわりにこの関数を使用します。
const optyRow = getCurrentRow();
const childRev = getCurrentChildRow();
childRev.setColumnMandatory('UnitPrice', true);

setColumnUpdatable(name: string, value: boolean)

特定の列について更新可能なプロパティの値を設定するために使用します。

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

setColumnVisible(name: string, value: boolean)

特定の列を表示/非表示にするために使用します。

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

addNewChildRow(childName: string)

行に新しい子を追加します。

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)

フィールドの表示タイプをテキスト、スキャンまたは数値に変更するために使用します。

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

disableAction(action: string, disable: boolean)

編集ビューで保存処理を無効または有効にするために使用します。

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

getOriginalValues()

変更前のフィールドの元の値を取得するために使用されます。

const row = getCurrentRow();
let oriVal = row.getOriginalValues();
let oriName = oriVal.Name;
let currName = row.getcolumn('Name');
  • Queryクラス・メソッド:

メソッド・シグネチャ

定義

使用方法

getParameters()

この問合せで使用可能なすべてのパラメータを取得するために使用します。

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)

特定の問合せパラメータの値を設定するために使用します。

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

execute()

問合せを実行するために使用します。 これは、問合せ基準を満たす行のセットを返します。

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:

メソッド・シグネチャ

定義

使用方法

getUserSettings()

ユーザー設定を返します。

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

getUserName()

現在のユーザーのユーザー名を返します。

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

getPartyName()

現在のユーザーの名前を返します。

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

getDateFormat()

現在のユーザーによって設定された日付書式を返します。

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

getPartyId()

現在のユーザーのIDを返します。

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

getCurrency()

現在のユーザーによって設定された通貨を返します。

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

getTimezone()

現在のユーザーによって設定されたタイム・ゾーンを返します。

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

getNumberFormat()

現在のユーザーによって設定された数値書式を返します。

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

getLanguage()

現在のユーザーによって設定された言語を返します。

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

getRoles()

現在のユーザーに割り当てられているロールを返します。

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

getProfileOptions()

現在のユーザーのすべてのプロファイル・オプションを返します。

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

getProfileOptionValue(profileOption)

指定されたプロファイル・オプションが存在する場合は現在のユーザーについてそのプロファイル・オプションのプロファイル・オプション値を返し、それ以外の場合はnullを返します。

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

isRoleAssigned(role)

指定されたロールが現在のユーザーに割り当てられている場合はtrueを返し、それ以外の場合はfalseを返します。

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

getDefaultBU()

現在のユーザーのデフォルトBUをフェッチするために使用します。 後述の「ビジネス・ユニット・クラス・メソッド」を参照してください。

let userPrefProvider = getUserPreferences();
let defaultBU = userPrefProvider.getDefaultBU();
  • DeviceInfoクラス・メソッド:

メソッド・シグネチャ

定義

使用方法

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

デバイスの位置を返します。

パラメータ:

  • maximumAge: キャッシュされた位置について許容可能なミリ秒単位の時間。 キャッシュされた位置が許容可能でない場合は、0を入力します。

  • timeout: navigator.geolocation.getCurrentPositionへのコールから、対応するgeolocationSuccessコールバックが実行されるまでの間に許可される最大経過時間(ミリ秒)。 この時間内にgeolocationSuccessコールバックが起動しない場合は、geolocationErrorコールバックにPositionError.TIMEOUTエラー・コードが渡されます。

  • enableHighAccuracy: アプリケーションが可能なかぎり最良の結果を必要とすることを示すヒントを提供します。 デフォルトでは、デバイスはネットワークベースの方法を使用して位置の取得を試みます。 このプロパティをtrueに設定すると、衛星測位など、より正確な方法を使用するようフレームワークは指示されます。

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

getOs()

デバイスのオペレーティング・システム名を返します。

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

getPlatform()

デバイスのプラットフォーム名を返します。

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

getVersion()

デバイスのバージョンを返します。

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

getModel()

デバイスのモデル名を返します。

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

isDeviceOnline()

デバイスがオンラインの場合はtrueを返し、それ以外の場合はfalseを返します。

const deviceInfo = getDeviceInformation();
const online = deviceInfo.isDeviceOnline();
  • CXCoreLoggerクラス・メソッド:

メソッド・シグネチャ

定義

使用方法

setLogLevel(level: string)

ロギング・レベルを設定します。 レベル値には、infoerrorwarnlogおよび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[])

メッセージをログ・レベルで記録します。

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

info(...args: any[])

メッセージを情報レベルで記録します。

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

warn(...args: any[])

メッセージを警告レベルで記録します。

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

error(...args: any[])

メッセージをエラー・レベルで記録します。

const row = getCurrentRow();
row.setColumn("Name","New oppty");
let cxCoreLogger = getCXCoreLogger().getLogger();
cxCoreLogger.setLogLevel("error");
cxCoreLogger.error("On create event executed");
  • Resultクラス・メソッド:

メソッド・シグネチャ

定義

使用方法

setModifiedObject()

スクリプトによって変更された行のセットに、新しく作成された行または更新された行を挿入するために使用します。 この処理によって、挿入された行がイベント・ハンドラ実装によって確実にコミットされます。

var oracleCxmOutcome = new Result('');
var row = getCurrentRow();
row.setColumn("Name","Sample Obj");
oracleCxmOutcome.setModifiedObject(row);
ノート: 保存後イベントで作成または変更された行は、変更内容が保存されるように、結果オブジェクトのsetModifiedObject APIを使用して追加する必要があります。

setMessage(key, stringBundle, message)

イベント・ハンドラ実装に返すことができるメッセージを追加するために使用します。 キーには、"MESSAGE_TYPE_SUCCESS"または"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)

エラー・メッセージを設定し、結果クオリファイアを"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()

スクリプトの実行後に処理されるクオリファイアを設定するために使用します。 返される文字列は、"OUTCOME_TYPE_SUCCESS"または"OUTCOME_TYPE_FAILURE"のいずれかです。 クオリファイア"OUTCOME_TYPE_FAILURE"beforeSaveイベントで使用されている場合、ページには、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");
}
  • ビジネス・ユニット・クラス・メソッド

メソッド・シグネチャ

定義

使用方法

getName()

ビジネス・ユニットの名前の取得に使用されます。

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

getBusinessUnitId()

BusinessUnitIDを取得するために使用します。

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

getBUName()

ビジネス・ユニットの名前の取得に使用されます。

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

getBUId()

BU IDの取得に使用されます。

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

getDefaultBUFlag()

デフォルトのBUFlagを取得するために使用します。

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