備註
社區興趣小組現在已從 Yammer 轉移到 Microsoft Viva Engage。 若要加入 Viva Engage 社群並參與最新的討論,請填寫 [ 要求存取財務和營運 Viva Engage 社群 表單 」 ,並選擇您要加入的社群。
本文說明會話執行階段函式。
curExt
擷取用於目前公司的延伸模組。
str curExt()
返回值
目前公司的延伸模組。
Example
static void curExtExample(Args _arg)
{
str s;
// Sets s to the extension of the current company.
s = curExt();
print "Current extension is " + s;
}
curUserId
擷取代表目前使用者的非數值識別碼。
str curUserId()
返回值
代表目前使用者的非數字識別碼。
Example
static void curUserIdExample(Args _arg)
{
str s;
s = curUserId();
print "Current user ID is " + s;
}
funcName
擷取包含目前函式內容的字串。
str funcName()
返回值
執行此方法的方法名稱。
備註
如果執行目前在資料表或類別的成員內,則方法的名稱會以該資料表或類別的名稱為前置詞。
Example
static void funcNameExample(Args _arg)
{
print "Current function context is " + funcName();
}
getCurrentPartition
擷取目前分割區的簡短名稱。
str getCurrentPartition()
返回值
目前分割區的簡短名稱。
備註
傳回之資料分割區名稱長度上限為八個字元。
Example
下列程式碼範例顯示 X++ 語言的 getCurrentPartition 函式的呼叫和輸出,以及相關函式或方法。
static public void Main(Args _args) // X++ method.
{
int64 iPartition;
str sPartition;
SelectableDataArea oSelectableDataArea; // System ExDT.
iPartition = getCurrentPartitionRecId();
sPartition = getcurrentpartition();
oSelectableDataArea = Global::getCompany( tableNum(BankAccountTable) );
Global::info( strFmt(
"getCurrentPartitionRecId =%1 , getCurrentPartition =%2 , getCompany =%3",
iPartition, sPartition, oSelectableDataArea) );
}
/**** Pasted from Infolog window:
Message_@SYS14327 (03:42:38 pm)
getCurrentPartitionRecId =5637144576 , getCurrentPartition =initial , getCompany =ceu
****/
getCurrentPartitionRecId
擷取目前分割區的 RecId 欄位。
int64 getCurrentPartitionRecId()
返回值
目前資料分割區的 RecId 欄位。
備註
若要查看依賴 getCurrentPartitionRecId 函式的程式碼範例,請參閱 如何:在直接 Transact-SQL 中包含分割區的篩選。
Example
下列程式碼範例顯示對 X++ 語言的 getCurrentPartitionRecId 函式的呼叫和輸出,以及相關函式或方法。
static public void Main(Args _args) // X++ method.
{
int64 iPartition;
str sPartition;
SelectableDataArea oSelectableDataArea; // System ExDT.
iPartition = getCurrentPartitionRecId();
sPartition = getcurrentpartition();
oSelectableDataArea = Global::getCompany( tableNum(BankAccountTable) );
Global::info( strFmt(
"getCurrentPartitionRecId =%1 , getCurrentPartition =%2 , getCompany =%3",
iPartition, sPartition, oSelectableDataArea) );
}
/**** Pasted from Infolog window:
Message_@SYS14327 (03:42:38 pm)
getCurrentPartitionRecId =5637144576 , getCurrentPartition =initial , getCompany =ceu
****/
getPrefix
在連續呼叫 setPrefix 函式之後擷取目前的執行前置詞。
str getPrefix()
返回值
目前的執行前置詞。
備註
前置詞機制可讓您更直接地撰寫有關應用程式執行之交易的精確錯誤訊息。 由於在 Infolog 中建立了分層顯示,因此可以更輕鬆地確定每個錯誤的來源。
Example
static void getPrefixExample(Args _arg)
{
setPrefix("Prefix");
setPrefix("Another prefix");
print getPrefix();
}
sessionId
擷取目前階段作業的階段作業編號。
int sessionId()
返回值
目前工作階段的數值 ID。
備註
當用戶端啟動並連線到應用程式物件伺服器 (AOS) 時,會指派工作階段號碼。 在用戶端生命週期期間,每次呼叫此函式都會傳回相同的整數值。 傳回值與 SessionID 擴充資料類型相容。 contains 方法會傳回個別使用者會話的相關資訊。
Example
static void sessionIdExample(Args _arg)
{
int session;
session = sessionId();
print "This session ID is number " + int2Str(session);
}
prmIs預設
判斷目前方法的指定參數是否具有預設值。
int prmIsDefault(anytype argument)
參數
| 參數 | Description |
|---|---|
| Argument | 要測試的參數。 |
返回值
1 如果使用參數的預設值;否則為 0 (零)。
Example
static void prmIsDefaultExample(Args _arg)
{
void fn(boolean b = true, int j = 42)
{
if (prmIsDefault(b) == 1)
{
print "First parameter is using the default value.";
}
else
{
print "First parameter is not using the default value.";
}
}
fn();
fn(false);
}
runAs
可讓呼叫端在另一個使用者的安全性內容中執行 X++ 方法。 此功能最常用於批次處理。
container runAs(
str userId,
int classId,
str staticMethodName
[,
container params,
str company,
str language,
str partition
])
參數
| 參數 | Description |
|---|---|
| userId | 要模擬的使用者。 |
| 類別標識符 | 要在模擬會話中叫用的類別。 |
| 靜態方法名稱 | 要在新使用者內容中叫用的類別方法。 |
| 參數 | 要傳遞給方法的參數;隨意的。 |
| 公司 | 選取進行模擬工作階段的公司;隨意的。 |
| 語言 | 為模擬工作階段選取的語言;隨意的。 |
| 分割 | getCurrentPartition 函數所傳回之類型的分割區索引鍵;隨意的。 |
返回值
如果傳回任何值,則會保存 runAs 函式所呼叫之方法的一或多個傳回值的容器。
備註
此函式可讓您以其他使用者身分執行程式碼。 此功能會帶來安全威脅。 因此,此函式會在 [程式碼存取安全性] 下執行。 在伺服器上呼叫此函式需要 RunAsPermission 類別的許可權。 此應用程式介面 (API) 的每次使用都應進行威脅建模。 如果發現安全漏洞,請驗證此 API 的輸入。 偵錯工具可能會忽略位於使用 runAs 函式呼叫的方法中的中斷點。 runAs 函式所執行的 X++ 程式碼必須以 Microsoft .NET Framework 通用中繼語言 (CIL) 身分執行。 如果尚未針對目標靜態方法產生 CIL,則錯誤訊息會指出找不到該方法。 PartitionKey 系統類型是分割區參數的確切類型。 PartitionKey 是長度上限為八個字元的字串。
Example
下列範例會呼叫 EventJobDueDate 類別中的 runDueDateEventsForUser 方法。 程式碼會在使用者的安全性內容中執行。 將此程式碼套用至新類別中的方法,以執行此程式碼。
server static public void Main(Args _args)
{
RunAsPermission perm;
UserId runAsUser;
SysUserInfo userInfo;
userInfo = SysUserInfo::find();
runAsUser = userInfo.Id;
perm = new RunAsPermission(runAsUser);
perm.assert();
runAs(runAsUser, classnum(EventJobDueDate), "runDueDateEventsForUser");
CodeAccessPermission::revertAssert();
}
setPrefix
設定目前執行範圍的前置詞。
int setPrefix(str _prefix)
參數
| 參數 | Description |
|---|---|
| _前綴 | 目前執行範圍的前置詞。 |
返回值
如果字首設定成功,則為 0。
備註
您可以使用 getPrefix 函數擷取執行的完整前置詞。 當範圍離開時,前置詞會自動重設為上一個層級。 前置詞機制可讓您更直接地撰寫有關應用程式執行之交易的精確錯誤訊息。 例如, AA 方法呼叫 BB 方法,每個方法呼叫 setPrefix 函數。 BB 方法寫入 Infolog 的訊息會巢狀顯示在階層中。 當 BB 方法結束,且控制權傳回 AA 方法時, BB 方法所設定的前置詞不會附加至後續訊息。
Example
static void setPrefixExample(Args _arg)
{
int i;
i = setPrefix("Prefix");
print i;
}