GlideElement - グローバル
GlideElement API には、フィールドとその値を扱うための便利なスクリプトメソッドが多数用意されています。GlideElement メソッドは、現在の Glide レコードのフィールドで使用できます。
GlideElement - canCreate()
ユーザーのロールが関連するフィールドへの新しいエントリの作成を許可するかどうかを決定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | 現在のユーザーが、関連付けられたフィールドに新しいエントリを作成する権限を持っているかどうかを示すフラグ。 可能な値:
|
次の例は、ユーザーが問題 [problem] テーブルの最新の 3 つのレコードのエントリーを作成する権限を持っているかどうかを判断する方法を示しています。
var gr = new GlideRecord('problem');
// Get records in new state in Problem Table
gr.addQuery('state','101');
// Sort records in order of recent to earlier Created Date
gr.orderByDesc('sys_created_on');
// Limit the query to three records
gr.setLimit(3);
gr.query();
while(gr.next()){
if(gr.short_description.canCreate()){ ///check to see if the current user is allowed to create the record
gs.info("I can create new records for the field Problem statement for - " + gr.number);
}
}
出力:
I can create new records for the field Problem statement for - PRB0000004
I can create new records for the field Problem statement for - PRB0001000
I can create new records for the field Problem statement for - PRB0001001
スコープ対応
スコープ対象のアプリケーションで canCreate() メソッドを使用するには、対応するスコープ対象のメソッドである canCreate() を使用します。
GlideElement - canRead()
ユーザーのロールが関連する GlideRecord の読み取りを許可されているかどうかを決定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | フィールドが読み取れる場合は true、それ以外の場合は false。 |
次の例は、読み取り可能な [簡単な説明] フィールドを含むアクティブなインシデントレコードのリストを取得する方法を示しています。
var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("active=true"); //Query the Incident table for active incidents
grIncident.orderByDesc('number');
grIncident.setLimit(3); // limit to three results for example
grIncident.query();
while (grIncident.next()) {
if (grIncident.short_description.canRead()) { //check to see if the current user is allowed to read the record
gs.info('You have permission to read the short description of: ' + grIncident.number + ' ' + grIncident.short_description);
}
}
出力:
*** Script: You have permission to read the short description of: INC0009009 Unable to access the shared folder.
*** Script: You have permission to read the short description of: INC0009005 Email server is down.
*** Script: You have permission to read the short description of: INC0009001 Unable to post content on a Wiki page
スコープ対応
スコープ対象のアプリケーションで canRead() メソッドを使用するには、対応するスコープ対象のメソッドである canRead() を使用します。
GlideElement:canWrite()
ユーザーのロールが関連する GlideRecord への書き込みを許可されているかどうかを決定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | ユーザーがフィールドに書き込むことができる場合は true、それ以外の場合は false。 |
次の例は、書き込み可能な [簡単な説明] フィールドを含むアクティブなインシデントレコードのリストを取得する方法を示しています。
var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("active=true"); //Query the Incident table for active incidents
grIncident.orderByDesc('number');
grIncident.setLimit(3); // limit to three results for example
grIncident.query();
while (grIncident.next()) {
if (grIncident.short_description.canWrite()) { //check to see if the current user is allowed to write to the record
gs.info('You have permission to write to the short description of: ' + grIncident.number + ' ' + grIncident.short_description);
}
}
出力:
*** Script: You have permission to write to the short description of: INC0009009 Unable to access the shared folder.
*** Script: You have permission to write to the short description of: INC0009005 Email server is down.
*** Script: You have permission to write to the short description of: INC0009001 Unable to post content on a Wiki page
スコープ対応
スコープ対象のアプリケーションで canWrite() メソッドを使用するには、対応するスコープ対象のメソッドである canWrite() を使用します。
GlideElement - changes()
現在のフィールドが変更されているかどうかを判定します。この機能は、ジャーナルフィールドを除く利用可能なすべてのデータタイプで使用できます。
- ビジネスルールの実行
- ServiceNow AI Platformは、列 (GlideElement オブジェクト) の内部以前の値を現在の値にリセットする前に、ビジネスルール (BEFORE または AFTER) を呼び出します。このシーケンスにより、次のアクションが有効になります。
- <column>.changes 条件で AFTER ビジネスルールをトリガーします。
- スクリプトセクションで前の GlideRecord オブジェクトにアクセスします。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | フィールドが変更された場合は true、それ以外の場合は false。 |
次のビジネスルールの例は、[ assigned_to ] フィールドの値が変更された場合に EventQueue にイベントを作成する方法を示しています。包括的な例については、「 Sample scripts from the change events business rule」を参照してください。
if (!current.assigned_to.nil() && current.assigned_to.changes()) {
gs.eventQueue('incident.assigned', current, current.assigned_to.getDisplayValue(), previous.assigned_to.getDisplayValue());
}
スコープ対応
スコープ対象のアプリケーションで changes() メソッドを使用するには、対応するスコープ対象のメソッド changes() を使用します。
GlideElement - changesFrom(オブジェクト値)
現在のフィールドの前の値が指定されたオブジェクトと一致するかどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| value | オブジェクト | 現在のフィールドの前の値と照合するオブジェクト値。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 前の値がパラメーターに一致する場合は true、一致しない場合は false。 |
if (theState.changesTo(resolvedState)) {
operation = 4; //Resolved
}
else if (theState.changesTo(closedState)) {
operation = 11; //Resolution Accepted
}
else if (theState.changesFrom(resolvedState) || theState.changesFrom(closedState)) {
operation = 10; //Re-open
}
else {
operation = 6; //Update
}
スコープ対応
スコープ対象のアプリケーションで changesFrom() メソッドを使用するには、対応するスコープ対象のメソッド changesFrom() を使用します。
GlideElement - changesTo(オブジェクト値)
変更後のフィールドの新しい値が指定されたオブジェクトと一致するかどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| value | オブジェクト | 現在のフィールドの新しい値と照合するオブジェクト値。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 新しい値がパラメーターに一致する場合は true、一致しない場合は false。 |
if (theState.changesTo(resolvedState)) {
operation = 4; //Resolved
}
else if (theState.changesTo(closedState)) {
operation = 11; //Resolution Accepted
}
else if (theState.changesFrom(resolvedState) || theState.changesFrom(closedState)) {
operation = 10; //Re-open
}
else {
operation = 6; //Update
}
スコープ対応
スコープ対象のアプリケーションで changesTo() メソッドを使用するには、対応するスコープ対象のメソッド changesTo() を使用します。
GlideElement - dateNumericValue()
期間フィールドについて、1970 年 1 月 1 日 00:00:00 GMT からのミリ秒数を返します。duration フィールドは既に GlideDateTime オブジェクトであるため、GlideDateTime オブジェクトを作成する必要はありません。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 番号 | 1970 年 1 月 1 日 00:00:00 GMT からのミリ秒数。 |
var inc = new GlideRecord('incident');
inc.get('17c90efb13418700cc36b1422244b05d');
gs.info(inc.calendar_duration.dateNumericValue());
出力:98000
スコープ対応
スコープ対象のアプリケーションで dateNumericValue() メソッドを使用するには、対応するスコープ対象のメソッド dateNumericValue() を使用します。
GlideElement - debug(オブジェクト o)
オブジェクトをデバッグし、 setError(String) を使用してデバッグメッセージを追加します。
| 名前 | タイプ | 説明 |
|---|---|---|
| o | オブジェクト | デバッグするオブジェクト。 |
| タイプ | 説明 |
|---|---|
| なし |
GlideElement - getAttribute(文字列 attributeName)
指定された属性の値を辞書から返します。
ブール属性の場合、 getBooleanAttribute() メソッドを使用して、値を文字列ではなくブール値として返すことができます。
| 名前 | タイプ | 説明 |
|---|---|---|
| attributeName | 文字列 | 属性の名前。属性名は、辞書エントリ [sys_dictionary] テーブルにリストされます。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 指定された属性の値。 |
次の例は、ユーザー [sys_user] テーブルの location 列の tree_picker 属性の値を文字列として取得する方法を示しています。
var now_GR = new GlideRecord('sys_user');
now_GR.query("user_name","admin");
if (now_GR.next()) {
gs.info("The value of the tree_picker attribute in the location column is " + now_GR.location.getAttribute("tree_picker"));
}
出力:
The value of the tree_picker attribute in the location column is true
スコープ対応
スコープ対象のアプリケーションで getAttribute() メソッドを使用するには、対応するスコープ対象のメソッド getAttribute() を使用します。
GlideElement - getBaseTableName()
フィールドのベーステーブルを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | ベーステーブルの名前。この名前は、フィールドが定義されているテーブルとは異なる場合があります。製品ドキュメントの Table extension and classes を参照してください。 |
次の例は、インシデントレコードの [アサイン先グループ] フィールドのベーステーブルを作成する方法を示しています。
var gr = new GlideRecord('incident');
//query the Incident Records which have category as Inquiry/Help
gr.addQuery('category','inquiry');
// sort them in the order of earlier to recent created date
gr.orderBy('sys_created_on');
gr.query();
if(gr.next()){ //If at least any one record exists matching this query
//Print the base table for the Assignment Group field
gs.print("The Base Table for the field Assignment Group is - " + gr.assignment_group.getBaseTableName());
};
出力:
The Base Table for the field Assignment Group is - task
GlideElement - getBooleanAttribute(文字列 attributeName)
指定されたブールタイプの属性を辞書からブール値として返します。
属性値を文字列として返すには、 getAttribute() メソッドを使用します。
| 名前 | タイプ | 説明 |
|---|---|---|
| attributeName | 文字列 | 属性の名前。属性名は、辞書エントリ [sys_dictionary] テーブルにリストされます。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 属性の値をブール値、true、または false として指定します。 |
次の例は、2 つのフィールドの ignore_filter_on_new 属性のブール値を取得する方法を示しています。
var inc = new GlideRecord('incident');
inc.query();
if (inc.next())
{
// opened_by field has attribute "ignore_filter_on_new = true"
gs.info(inc.opened_by.getBooleanAttribute("ignore_filter_on_new"));
// short_description field does not have attribute ignore_filter_on_new
gs.info(inc.short_description.getBooleanAttribute("ignore_filter_on_new"));
}
出力:
true
false
スコープ対応
スコープ対象のアプリケーションで getBooleanAttribute() メソッドを使用するには、対応するスコープ対象のメソッド getBooleanAttribute() を使用します。
GlideElement - getChoices(文字列依存)
フィールドの選択リストを生成します。拡張テーブルからではなく、ベーステーブルからのみ選択値を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| 依存 | 文字列 | オプション。選択リストフィールドが依存する関連レコード内のフィールド。 |
| タイプ | 説明 |
|---|---|
| アレイリスト | フィールドの選択値。 |
var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
// urgency has choice list: 1 - High, 2 - Medium, 3 - Low, with value: 1, 2, 3
var choices = glideRecord.urgency.getChoices();
スコープ対応
スコープ対象のアプリケーションで getChoices() メソッドを使用するには、対応するスコープ対象のメソッド getChoices() を使用します。
GlideElement - getChoiceValue()
現在の選択値の選択ラベルを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 選択肢ラベル。 |
次の例は、優先度の値が「標準」の変更要求レコードの選択ラベルを取得する方法を示しています。
var gr = new GlideRecord('change_request');
//query for the change records with change type as "Normal"
gr.addQuery('type','normal');
// sort them in the order of recent to earlier Created Date
gr.orderByDesc('sys_created_on');
// limit the query to 4 records
gr.setLimit(4);
gr.query();
while(gr.next()){
//Printing the choice label for those records
gs.print("The label of the current priority '"+ gr.priority+"' for the change request - " + gr.number + " is - "+ gr.priority.getChoiceValue());
}
出力:
The label of the current priority '4' for the change request - CHG0000014 is - 4 - Low
The label of the current priority '4' for the change request - CHG0000013 is - 4 - Low
The label of the current priority '4' for the change request - CHG0000012 is - 4 - Low
The label of the current priority '4' for the change request - CHG0000011 is - 4 - Low
スコープ対応
スコープ対象のアプリケーションで getChoiceValue() メソッドを使用するには、対応するスコープ対象のメソッド getChoiceValue() を使用します。
GlideElement - getDebugCount()
debug() によってログに記録されたデバッグメッセージの数を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 番号 | デバッグメッセージの数。 |
GlideElement - getDependent()
指定したフィールドが依存しているフィールド (要素) を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 現在のフィールドが依存するフィールドの名前。依存関係がない場合は null。 |
次の例は、 getDependent() メソッドを使用して構成アイテムフィールドの親フィールドを検索する方法を示しています。
var inc_gr = new GlideRecord('incident');
inc_gr.get('985f53d82fab301032e8808cf699b6e8'); // Get a particular Incident
var field_element = inc_gr.getElement('cmdb_ci'); // Get the Configuration Item element
var dependent_field = field_element.getDependent(); // Read the dependent field
gs.info("Dependent field: " + dependent_field);
if(dependent_field)
{
var dependent_field_value = inc_gr.getValue(dependent_field);
if(!dependent_field_value)
{
var base_table = field_element.getRefRecord(); // Retrieve the reference record
var dependent_field_value = base_table.getValue(dependent_field); // Read the parent field value
}
inc_gr.setValue(dependent_field, dependent_field_value); // Update the parent field on the Incident
inc_gr.update();
}
出力:
company
GlideElement - getDependentTable()
フィールドが依存しているテーブルの名前を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | フィールドに依存テーブルがある場合のテーブルの名前。それ以外の場合は null です。 |
次の例は、 model_id という名前のフィールドに依存テーブルがあるかどうかを判断する方法を示しています。
var gr = new GlideRecord('cmdb_ci_hardware');
gr.setLimit(1);
gr.query();
if (gr.next()) {
var field_element = gr.getElement('model_id'); // Get the model_id field element
var dependent_table = field_element.getDependentTable(); // Get the table that drives filtering
gs.info("Field: " + field_element.getLabel());
gs.info("Dependent table: " + dependent_table); // cmdb_model_category
if (dependent_table) {
// Use the dependent table to query what's controlling the filter
var dep_gr = new GlideRecord(dependent_table);
if (dep_gr.get(gr.getValue('model_category'))) {
gs.info("Controlling record: " + dep_gr.getDisplayValue());
gs.info("Only models belonging to category '" + dep_gr.getDisplayValue() + "' are valid for this CI");
}
}
}
出力:
Field: Model ID
Dependent table: null
GlideElement - getDisplayValue(数値 maxChar)
フィールドの書式設定された表示値を返します。
表示値は、データベースの実際の値とユーザーまたはシステムの設定と設定に基づいて操作されます。
- 選択肢フィールド:データベース値は数値でもかまいませんが、表示値はよりわかりやすいものになります。
- 日付フィールド:データベース値は UTC 形式で、表示値はユーザーのタイムゾーンに基づいています。
- 暗号化テキスト:データベース値は暗号化されますが、表示される値はユーザーの暗号化コンテキストに基づいて暗号化されません。
- 参照フィールド:データベース値はsys_idですが、表示値は参照レコードの表示フィールドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| maxChar | 番号 | オプション。返す最大文字数。 |
| タイプ | 説明 |
|---|---|
| 文字列 | フィールドの表示値。 |
var fields = current.getFields();
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var name = field.getName();
var value = field.getDisplayValue();
gs.print(i + ". " + name + "=" + value);
}
スコープ対応
スコープ対象のアプリケーションで getDisplayValue() メソッドを使用するには、対応するスコープ対象のメソッド getDisplayValue() を使用します。
GlideElement - getDisplayValueExt(Number maxChar, String nullSub)
フィールドの書式設定された表示値を返します。表示値が null または空の場合は、指定された代替値を返します。
表示値は、データベースの実際の値とユーザーまたはシステムの設定と設定に基づいて操作されます。
- 選択肢フィールド:データベース値は数値でもかまいませんが、表示値はよりわかりやすいものになります。
- 日付フィールド:データベース値は UTC 形式で、表示値はユーザーのタイムゾーンに基づいています。
- 暗号化テキスト:データベース値は暗号化されますが、表示される値はユーザーの暗号化コンテキストに基づいて暗号化されません。
- 参照フィールド:データベース値はsys_idですが、表示値は参照レコードの表示フィールドです。
| 名前 | タイプ | 説明 |
|---|---|---|
| maxChar | 番号 | オプション。返される最大文字数。 デフォルト:すべて |
| nullSub | 文字列 | 表示値が null または空の場合に返される値。 |
| タイプ | 説明 |
|---|---|
| 文字列 | フィールドの書式設定された表示値、または指定された代替値。 |
次の例は、インシデント [incident] テーブルに最新の 2 つのアクティブなレコードを表示する方法を示しています。
var gr = new GlideRecord('incident');
gr.addQuery('active', true); // get the active records
gr.orderByDesc('sys_updated_on'); // sort the records from most recent to oldest updated date
gr.setLimit(2); // limit the query to 2 records
gr.query();
while(gr.next()){ // Printing the Display Value of the Configuration Item field.
// If the Display Value is Null/Empty, then it will be substituted with Default value "I with Null/Empty Display Value"
gs.info("The Display Value of the Configuration Item for the incident - "+ gr.number+ " is " + gr.cmdb_ci.getDisplayValueExt(40, " CI with Null/Empty Display Value"));
}
出力:
The Display Value of the Configuration Item for the incident - INC0007001 is CI with Null/Empty Display Value
The Display Value of the Configuration Item for the incident - INC0000069 is NYC RAC
GlideElement - getDisplayValueLang(文字列言語)
パラメーターとして渡された言語でフィールドの表示値を取得します。
結果は、[ 選択肢]、[ 翻訳済みフィールド]、[ 翻訳済みテキスト] などの翻訳可能なフィールドタイプにのみ適用されます。その他のフィールドタイプの場合、結果のデフォルトは getDisplayValue() です。
翻訳された値を取得するには、対応する言語プラグインが必要です。詳細については、「Activate a language」を参照してください。
「スコープ付き GlideElement - getLabelLang(文字列言語)」も参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| 言語 | 文字列 | IETF BCP-47 に準拠した言語タグ。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 渡された言語でのフィールドの表示値。翻訳が利用できない場合、メソッドは現在のユーザーの言語に翻訳された値を取得します。翻訳が利用できない場合、結果はデフォルトで英語になります。 |
次の例は、[ 承認 (UI ビュー)] タイトルフィールドから原文とドイツ語に翻訳されたテキストを取得する方法を示しています。
var uiView = new GlideRecord("sys_ui_view");
uiView.get("fa776f6d97700100f309124eda2975bc");
gs.info("getDisplayValue: " + uiView.getElement("title").getDisplayValue());
gs.info("getDisplayValueLang: " + uiView.getElement("title").getDisplayValueLang("de"));
出力:
getDisplayValue: Accept
getDisplayValueLang: Akzeptieren
スコープ対応
スコープ対象のアプリケーションで getDisplayValueLang() メソッドを使用するには、対応するスコープ対象のメソッド getDisplayValueLang() を使用します。
GlideElement - getDynamicAttribute()
この GlideElement の動的属性定義を返します。
動的属性には、定義済みのデータタイプとsys_idがあります。動的属性の詳細については、「 動的スキーマ」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| IDynamicAttribute | GlideElement が表す属性を記述するオブジェクト。 |
次の例は、インシデントテーブルの動的属性ストア列から make 属性u_inc_dynamic_schema値を取得する方法を示しています。
var gr_Inc = new GlideRecord('incident');
gr_Inc.query();
if(gr_Inc.next()) {
var attr = gr_Inc.getDynamicAttribute('inc_dynamic_schema->make');
gs.info(attr.getValue());
}GlideElement - getDynamicNamespace()
GlideElement 用に構成された 動的名前空間 オブジェクトを返します。
動的属性には、定義済みのデータタイプとsys_idがあります。動的属性の詳細については、「 動的スキーマ」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| IDynamicNamespace | 動的名前空間を記述するオブジェクト。 |
次の例は、インシデントテーブルの動的属性ストア列用に構成された名前空間オブジェクトinc_dynamic_schema取得方法を示しています。
var gr_Inc = new GlideRecord('incident');
gr_Inc.query();
if (gr_Inc.next()) {
var ge_Make = gr_Inc.getElement('inc_dynamic_schema->make');
var namespace = ge_Make.getDynamicNamespace();
gs.info("toString: " + namespace);
gs.info("name: " + namespace.getName());
gs.info("isActive: " + namespace.isActive());
gs.info("isTransient: " + namespace.isTransient());
}
出力:
toString: incident/inc_dynamic_schema
name: incident/inc_dynamic_schema
isActive: true
isTransient: false GlideElement - getDynamicNamespaceName()
GlideElement 用に構成された動的名前空間の名前を取得します。
動的属性には、定義済みのデータタイプとsys_idがあります。動的属性の詳細については、「 動的スキーマ」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 動的名前空間の名前。 |
次の例は、動的属性の名前空間名を返す方法を示しています。
// Gets the name of the namespace from the inc_dynamic_schema dynamic_attribute_store column on the incident table
var gr_Inc = new GlideRecord('incident');
gr_Inc.query();
if (gr_Inc.next()) {
var ge_Make = gr_Inc.getElement('inc_dynamic_schema->make');
gs.info(ge_Make.getDynamicNamespaceName());
}出力:
number,short_description,activeGlideElement - getED()
フィールド内のデータではなく、特定のフィールドに関する情報を提供する要素記述子を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ElementDescriptor | フィールドの要素記述子。 |
この例では、現在のレコードのフィールドとフィールド記述子を取得します。
var fields = current.getFields();
for (i=0; i<fields.size(); i++) {
var field = fields.get(i);
var descriptor = field.getED();
gs.print("type=" + descriptor.getType() +
" internalType=" + descriptor.getInternalType());
}
スコープ対応
スコープ対象のアプリケーションで getED() メソッドを使用するには、対応するスコープ対象のメソッド getED() を使用します。
GlideElement - getElementValue(文字列値)
指定された要素の値を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| value | 文字列 | 値を返す要素。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 要素の値。 |
var fields = current.getFields();
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var name = field.getName();
// Returns the unformatted value of the element
var value = field.getElementValue(name);
var disValue = field.getDisplayValue();
gs.print(i + ". " + name + " = " + value + ' display value = ' + disValue);
}
出力
1. cmdb_ci = 109562a3c611227500a7b7ff98cc0dc7 display value = Storage Area Network 001
2. impact = 2 display value = 2 - Medium
GlideElement - getError()
指定された要素に関連付けられているエラーメッセージを返します。
setError() メソッドを使用して、特定のフィールド (要素) にエラーを設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 指定された要素に現在設定されているエラーメッセージ。 |
この例では、short_description要素にエラーを設定し、そのエラーを読み戻す方法を示します。
var incidentGR = new GlideRecord('incident');
incidentGR.setLimit(1);
incidentGR.query();
if (incidentGR.next()) {
incidentGR.short_description.setError('The description is too short.');
gs.info(incidentGR.short_description.getError()); // 'The description is too short.'
}
出力:
The description is too short.
この例では、関数呼び出しで getError() を使用する方法を示します。
// Before query business rule (order = 100)
(function executeRule(current, previous /*null when async*/) {
var shortDescription = current.getValue('short_description');
if (shortDescription.length < 10) {
current.short_description.setError('The description is too short.');
current.setAbortAction(true);
}
})(current, previous);
// Before query business rule (order = 200)
(function executeRule(current, previous /*null when async*/) {
var shortDescriptionErrMsg = current.short_description.getError();
if (shortDescriptionErrMsg) {
// Some error was set in one of the previous business rules.
}
})(current, previous);
GlideElement - getEscapedValue()
現在の要素のエスケープされた値を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 現在の要素のエスケープされた値。 |
次の例は、 getEscapedValue() メソッドを使用して、インシデントの簡単な説明フィールドの内容をエスケープ文字付きで表示する方法を示しています。
/*** Overview - Update incident short description with escape characters and printing ***/
var inc = new GlideRecord('incident');
inc.query();
inc.next();
inc.short_description = 'Can\'t log into SAP from my laptop today';
inc.update();
gs.info("Short Description: "+inc.getElement('short_description').toString()); //without escape characters
gs.info("Escaped Short Description: "+inc.getElement('short_description').getEscapedValue()); // with escape characters
出力:
Short Description: Can't log into SAP from my laptop today
Escaped Short Description: Can\'t log into SAP from my laptop today
GlideElement - getFieldStyle()
フィールドの CSS スタイルを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | フィールドの CSS スタイル。 |
var fields = current.getFields();
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var css_style = field.getFieldStyle();
gs.print("CSS style" + "=" + css_style);
}
GlideElement:getGlideObject()
フィールドの値に関連付けられているプラットフォームオブジェクトを取得します。
ユースケースについては、「 GlideDateTime フィールド値の変更」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| オブジェクト | フィールドのデータタイプに対応するプラットフォームオブジェクト ( GlideDateTime など)。このオブジェクトは、値に対する型固有の操作に使用できます。たとえば、日付の計算、書式設定、およびタイムゾーンの変換は、フィールド値にプレーンな文字列としてアクセスする場合には利用できません。 |
次の例は、インシデントレコードのオープン日からサービスレベルアグリーメント (SLA) 期日までの期間を計算する方法を示しています。
// Query an incident record with both opened_at and sla_due populated
var incGr = new GlideRecord('incident');
incGr.addQuery('opened_at', '!=', '');
incGr.addQuery('sla_due', '!=', '');
incGr.setLimit(1);
incGr.query();
if (incGr.next()) {
gs.info("Incident: " + incGr.getValue('number'));
gs.info("Opened at: " + incGr.getValue('opened_at'));
gs.info("SLA due: " + incGr.getValue('sla_due'));
var duration = calcDateDelta(incGr.opened_at, incGr.sla_due);
if (duration) {
gs.info("Duration in seconds: " + duration.getNumericValue() / 1000);
gs.info("Duration display value: " + duration.getDisplayValue());
}
}
function calcDateDelta(start, end) {
var realStart = start.getGlideObject();
var realEnd = end.getGlideObject();
// Use GlideDuration to calculate the difference between two GlideDateTime objects
var startMS = realStart.getNumericValue();
var endMS = realEnd.getNumericValue();
var deltaMS = endMS - startMS;
// Create a GlideDuration from the millisecond difference
var duration = new GlideDuration(deltaMS);
return duration;
}
出力:
Incident: INC0000031
Opened at: 2025-03-06 00:18:03
SLA due: 2025-03-06 08:18:03
Duration in seconds: 28800
Duration display value: 8 Hours
スコープ対応
スコープ対象のアプリケーションで getGlideObject() メソッドを使用するには、対応するスコープ対象のメソッド getGlideObject() を使用します。
GlideElement - getGlideRecord()
Glide レコードを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| GlideRecord | Glide レコードオブジェクト。 |
var grInc = new GlideRecord('incident');
grInc.get('sys_id','ef43c6d40a0a0b5700c77f9bf387afe3');
gs.info("Initial grInc - " + grInc.getDisplayValue());
var caller = grInc.getElement("caller_id");
doit(caller);
function doit(caller) {
var now_GR = caller.getGlideRecord();
gs.info("doit gr is - " + now_GR.getDisplayValue());
}
出力
*** Script: Initial grInc - INC0000050
*** Script: doit gr is - INC0000050
GlideElement - getHTMLValue(Number maxChars)
フィールドの HTML 値を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| maxChar | 番号 | オプション。返す最大文字数。 |
| タイプ | 説明 |
|---|---|
| 文字列 | フィールドの HTML 値。 |
次の例は、会議メモの HTML コンテンツを取得する方法を示しています。
/*
getHTMLValueExt() This Function is used to get HTML Value of a field. It accepts 2 Parameters
a. maxChar- Number - The maximum number of characters to return.
b. nullSub - String - The value to return if the HTML value is null or empty.
*/
// get a cab meeting record by its sys_id
var gr = new GlideRecord('cab_meeting');
gr.addQuery('sys_id','7777777b6d2a20100sys70id534330f6');
gr.query();
if(gr.next()){
var substituteString = 'Meeting Notes Unavailable';
var maxLength = 50;
gs.print(gr.meeting_notes.getHTMLValueExt(maxLength, substituteString));
}
スコープ対応
スコープ対象のアプリケーションで getHTMLValue() メソッドを使用するには、対応するスコープ対象のメソッド getHTMLValue() を使用します。
GlideElement - getHTMLValueExt(数値 maxChar, 文字列 nullSub)
フィールドの HTML 値を返すか、HTML 値が null または空の場合は指定された代替値を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| maxChar | 番号 | 返す最大文字数。 |
| nullSub | 文字列 | HTML 値が null または空の場合に返される値。 |
| タイプ | 説明 |
|---|---|
| 文字列 | HTML 値または指定された代替値。 |
次の例は、会議メモの HTML コンテンツを取得する方法を示しています。
// get a cab meeting record by its sys_id
var gr = new GlideRecord('cab_meeting');
gr.addQuery('sys_id','7777777b6d2a20100sys70id534330f6');
gr.query();
if(gr.next()){
var substituteString = 'Meeting Notes Unavailable';
var maxLength = 50;
gs.print(gr.meeting_notes.getHTMLValueExt(maxLength, substituteString));
}
<p>Meeting note content.</p>GlideElement - getJournalEntry(Number mostRecent)
最新のジャーナルエントリまたはすべてのジャーナルエントリを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| mostRecent | 番号 | 1 の場合、最新のエントリを返します。-1 の場合、すべてのジャーナルエントリが返されます。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 最新のエントリの場合、ジャーナルエントリのフィールドラベル、タイムスタンプ、およびユーザー表示名を含む文字列を返します。 すべてのジャーナルエントリについて、単一の文字列として入力されたすべてのジャーナルエントリについて同じ情報を返し、各エントリは「\n\n」で区切られます。 |
//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = current.work_notes.getJournalEntry(-1);
//stores each entry into an array of strings
var na = notes.split("\n\n");
for (var i = 0; i < na.length; i++)
gs.print(na[i]);
スコープ対応
スコープ対象のアプリケーションで getJournalEntry() メソッドを使用するには、対応するスコープ対象のメソッド getJournalEntry() を使用します。
GlideElement - getLabel()
オブジェクトのラベルを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | オブジェクトのラベル |
var now_GR = new GlideRecord("sc_req_item");
now_GR.addQuery("request", current.sysapproval);
now_GR.query();
while(now_GR.next()) {
var nicePrice = now_GR.price.toString();
if (nicePrice != ) {
nicePrice = parseFloat(nicePrice);
nicePrice = nicePrice.toFixed(2);
}
template.print(now_GR.number + ": " + now_GR.quantity + " X " + now_GR.cat_item.getDisplayValue() + " at $" + nicePrice + " each \n");
template.print(" Options:\n");
var variables = now_GR.variables.getElements();
for (var key in variables) {
var now_V = variables[key];
if(now_V.getQuestion().getLabel() != ) {
template.space(4);
template.print(' ' + now_V.getQuestion().getLabel() + " = " + now_V.getDisplayValue() + "\n");
}
}
}
スコープ対応
スコープ対象のアプリケーションで getLabel() メソッドを使用するには、対応するスコープ対象のメソッド getLabel() を使用します。
GlideElement - getLabelLang(文字列言語)
パラメーターとして渡された言語のフィールドのラベル値を取得します。
翻訳された値を取得するには、対応する言語プラグインが必要です。詳細については、「Activate a language」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| 言語 | 文字列 | IETF BCP-47 に準拠した言語タグ。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 渡された言語のフィールドラベルの値。 翻訳が利用できない場合、メソッドは現在のユーザーの言語に翻訳された値を取得します。翻訳が利用できない場合、結果はデフォルトで英語になります。 |
次の例は、元のラベルテキストと 、承認 (UI ビュー) タイトルのドイツ語訳を取得する方法を示しています。
var uiView = new GlideRecord("sys_ui_view");
uiView.get("fa776f6d97700100f309124eda2975bc");
gs.info("getLabel: " + uiView.getElement("title").getLabel());
gs.info("getLabelLang: " + uiView.getElement("title").getLabelLang("de"));
出力:
getLabel: Title
getLabelLang: Titel
スコープ対応
スコープ対象のアプリケーションで getLabelLang() メソッドを使用するには、対応するスコープ対象のメソッド getLabelLang() を使用します。
GlideElement - getName()
フィールドの名前を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | フィールド名。 |
次の例は、sys_userレコード内の各フィールドの名前とその他の値を取得する方法を示しています。
var userRec = new GlideRecord("sys_user"); // GlideRecord to sys_user table
userRec.get("5137153cc611227c000bbd1bd8cd2005"); // Sys Id of user: Fred Luddy
var fields = userRec.getFields();
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var name = field.getName(); // Name of the field
var label = field.getLabel(); // Label of the field
var value = field.getDisplayValue(); // Value of the field
gs.info((Number(i) + 1) + ".\n" + "Field Label: " + label + "\n" + "Field Name: " + name + "\n" + "Field Value: " + value);
};
出力。結果には 62 個のフィールドが含まれており、スペースを節約するために省略記号 (...) で切り捨てられています。
*** Script: 1.
Field Label: Country code
Field Name: country
Field Value:
*** Script: 2.
Field Label: Calendar integration
Field Name: calendar_integration
Field Value: Outlook
...
*** Script: 47.
Field Label: First name
Field Name: first_name
Field Value: Fred
...
*** Script: 54.
Field Label: Last name
Field Name: last_name
Field Value: Luddy
...
スコープ対応
スコープ対象のアプリケーションで getName() メソッドを使用するには、対応するスコープ対象のメソッド getName() を使用します。
GlideElement - getRefRecord()
指定された参照要素の GlideRecord オブジェクトを返します。
計算されたフィールドの場合、このメソッドは参照レコードをフェッチし、スクリプト化されたデフォルト値で計算を実行します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| GlideRecord | GlideRecord オブジェクト |
var grINC = new GlideRecord('incident');
grINC.notNullQuery('caller_id');
grINC.query();
if (grINC.next()) {
// Get a GlideRecord object for the referenced sys_user record
var grUSER = grINC.caller_id.getRefRecord();
if (grUSER.isValidRecord())
gs.print( grUSER.getValue('name') );
}
スコープ対応
スコープ対象のアプリケーションで getRefRecord() メソッドを使用するには、対応するスコープ対象のメソッド getRefRecord() を使用します。
GlideElement - getStyle()
値の CSS スタイルを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 値の CSS スタイル。 |
// Get string of style field from Field Style record
var cssStyle = now_GR.state.getStyle();
GlideElement - getTableName()
フィールドを含むテーブルの名前を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 呼び出されるフィールドを含むテーブルの名前。戻り値は、レコードが含まれているテーブルクラスと異なる場合があります。詳細については、「Table extension and classes」を参照してください。 |
if (current.approver.getTableName() == "sysapproval_approver") {
if (current.approver == email.from_sys_id) {
current.comments = "reply from: " + email.from + "\n\n" + email.body_text;
// if it's been cancelled, it's cancelled.
var doit = true;
if (current.state == 'cancelled')
doit = false;
if (email.body.state != undefined)
current.state = email.body.state;
if (doit)
current.update();
} else {
gs.log("Approval for task " + current.sysapproval.getDisplayValue() +
" rejected because user sending email " + email.from +
" does not match the approver " + current.approver.getDisplayValue());
}
}
スコープ対応
スコープ対象のアプリケーションで getTableName() メソッドを使用するには、対応するスコープ対象のメソッド getTableName() を使用します。
GlideElement - getTextAreaDisplayValue()
関連付けられたフィールドの表示値を取得し、HTML をエスケープします。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 関連付けられたフィールドのエスケープされた 表示値 の HTML。 |
次の例では、KB 記事の表示値を取得します。
var grh = new GlideRecord('kb_knowledge');
grh.get('c85cd2519f77230088aebde8132e70c2'); // Knowledge record sys_id
var t = grh.text.getTextAreaDisplayValue(); // Text is HTML type field
var d = GlideXMLUtil.parseHTML(t); // Parse the HTML
var b = d.getDocumentElement().getTextContent().trim();
gs.info(b);
出力:
This article explains how to use automatic replies in Outlook 2010 for Exchange accounts.
Setting Up Automatic Replies
Click the
File tab.
Click
Automatic Replies.
Select
Send automatic replies.
If desired, select the
Only send during this time range check box to schedule when your out of office replies are active. If you do not specify a start and end time, auto-replies will be sent until you select the
Do not send automatic replies check box.
On the
Inside My Organization tab, type the response that you want to send to colleagues while you are out of the office.
On the
Outside My Organization tab, select the
Auto-reply to people outside my organization check box, and then type the response that you want to send while you are out of the office. Select whether you want replies sent to
My contacts only or to
Anyone outside my organization who sends you messages.
NOTE:
If you select
My Contacts only in step 6, replies will be sent
only to contacts that exist in your Contacts folder.
Using Rules With Automatic Replies
It is also possible to use rules to manage your messages while you are out of office. For example, you can create rules to automatically move or copy messages to other folders, to delete messages, to send custom replies, and so on.
Click the
File tab.
Click
Automatic Replies.
Click
Rules, and then click
Add Rule.
Under
When a message arrives that meets the following conditions, specify the conditions that the message must meet for the rule to be applied. If you want to specify more conditions, click
Advanced, enter or select the options that you want, and then click
OK.
If you want to specify that this rule must be applied last, select the
Do not process subsequent rules check box.
Under
Perform these actions, select the actions that you want. You can select more than one action.
Click
OK three times.
NOTES:
Automatic Replies rules can also be edited by following the above procedure.
To turn Automatic Replies rules on or off, in the Automatic Reply Rules dialog box, select or clear the check box of the rule that you want to turn on or off.
GlideElement - getValue()
データベース内のフィールドの値を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | フィールドの値。 |
次の例では、データベース内の指定されたフィールドの値を取得します。
var now_GR = new GlideRecord('incident');
now_GR.get('9c573169c611228700193229fff72400'); //INC0000001
gs.info('Display Values');
gs.info('Opened at ' + now_GR.opened_at.getDisplayValue());
gs.info('Opened by ' + now_GR.opened_by.getDisplayValue());
gs.info('Priority ' + now_GR.priority.getDisplayValue());
gs.info('Values');
gs.info('Opened at ' + now_GR.opened_at.getValue());
gs.info('Opened by ' + now_GR.opened_by.getValue());
gs.info('Priority ' + now_GR.priority.getValue());
出力:
Display Values
Opened at 2022-02-01 15:09:51
Opened by Joe Employee
Priority 1 - Critical
Values
Opened at 2022-02-01 23:09:51
Opened by 681ccaf9c0a8016400b98a06818d57c7
Priority 1
スコープ対応
スコープ対象のアプリケーションで getValue() メソッドを使用するには、対応するスコープ対象のメソッド GlideElement - スコープ対象 を使用します。
GlideElement - getXHTMLValue()
フィールドの XHTML 値を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | XHTML 値 |
GlideElement - getXMLValue()
フィールドの XML 値を文字列として取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | XML 値 |
GlideElement - hasAttribute(文字列 attributeName)
フィールドに指定された属性があるかどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| attributeName | 文字列 | 属性の名前。属性名は、辞書エントリ [sys_dictionary] テーブルにリストされます。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | フィールドに指定された属性があるかどうかを示すフラグ。 有効な値:
|
次の例は、 edge_encryption_enabled 属性を使用してユーザー [sys_user] テーブルからフィールドを取得する方法を示しています。
var fields = new GlideRecord('sys_user');
fields.query();
var userFields = fields.getFields();
for (var num = 0; num < userFields.size(); num++) {
var ed = userFields.get(num).getED();
if (ed.hasAttribute("edge_encryption_enabled")) {
gs.info(userFields.get(num).getName());
}
}
出力:
*** Script: hashed_user_id
*** Script: federated_id GlideElement - hasRightsTo(文字列 operationName)
ユーザーに特定の操作を実行する権限があるかどうかを決定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| operationName | 文字列 | チェックする操作の名前 |
| タイプ | 説明 |
|---|---|
| ブーリアン | ユーザーに操作を実行する権限がある場合は true、それ以外の場合は false。 ユーザーに操作を実行する権限があるかどうかを示すフラグ。 有効な値:
|
次の例は、ユーザーが特定のテーブルを読み取る権限を持っているかどうかを判断する方法を示しています。
// Pass table name and userId to check if user has read access against given table name
checkAccess('incident', 'adela.cervantsz');
function checkAccess(tableName, userID) {
var inc = new GlideRecordSecure(tableName);
inc.get('$[sys_id]');
var secureManager = GlideSecurityManager.get();
//fetch a different user, using user_name field on the target user record
var userObj = gs.getUser().getUserByID(userID);
secureManager.setUser(userObj);
var access = 'record/incident/read';
//check if user has right to access
var canRead = secureManager.hasRightsTo(access, inc);
gs.info('canRead: ' + canRead);
}
出力:
canRead: false
GlideElement - hasValue()
フィールドに値があるかどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | フィールドに値がある場合は true、それ以外の場合は false。 |
GlideElement:nil()
フィールドが null かどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | フィールドが null または空の文字列の場合は true、それ以外の場合は false。 |
if (current.start_date.changes() || current.end_date.changes() || current.assigned_to.changes()) {
if (!current.start_date.nil() && !current.end_date.nil() && !current.assigned_to.nil()) {
gs.eventQueue("change.calendar.notify", current, current.assigned_to, previous.assigned_to);
}
スコープ対応
スコープ対象のアプリケーションで nil() メソッドを使用するには、対応するスコープ対象のメソッド nil() を使用します。
GlideElement - setDateNumericValue(ミリ秒数)
期間フィールドについて、期間フィールドを 1970 年 1 月 1 日 00:00:00 GMT からのミリ秒数に設定します。duration フィールドは既に GlideDateTime オブジェクトであるため、GlideDateTime オブジェクトを作成する必要はありません。
| 名前 | タイプ | 説明 |
|---|---|---|
| ミリ秒 | 番号 | 期間にまたがったミリ秒数。 |
| タイプ | 説明 |
|---|---|
| なし |
var inc = new GlideRecord('incident');
inc.get('17c90efb13418700cc36b1422244b05d');
var timems = inc.calendar_duration.dateNumericValue();
timems = timems + 11*1000;
inc.calendar_duration.setDateNumericValue(timems)
gs.info(inc.calendar_duration.getValue());
出力:
1970-01-01 00:01:38
スコープ対応
スコープ対象のアプリケーションで setDateNumericValue() メソッドを使用するには、対応するスコープ対象のメソッド setDateNumericValue() を使用します。
GlideElement - setDisplayValue(オブジェクト displayValue)
フィールドの表示値を設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| displayValue | オブジェクト | 表示する値。 |
| タイプ | 説明 |
|---|---|
| なし |
スコープ対応
スコープ対象のアプリケーションで setDisplayValue() メソッドを使用するには、対応するスコープ対象のメソッド setDisplayValue() を使用します。
GlideElement - setError(文字列 errorMessage)
関連するフィールドにエラーメッセージを追加します。
getError() メソッドを使用してエラーメッセージを取得できます。
| 名前 | タイプ | 説明 |
|---|---|---|
| errorMessage | 文字列 | エラーメッセージ。 |
| タイプ | 説明 |
|---|---|
| なし |
if ((!current.u_date1.nil()) && (!current.u_date2.nil())) {
var start = current.u_date1.getGlideObject().getNumericValue();
var end = current.u_date2.getGlideObject().getNumericValue();
if (start > end) {
gs.addInfoMessage('start must be before end');
current.setAbortAction(true);
current.u_date1.setError('start must be before end');
}
}
スコープ対応
スコープ対象のアプリケーションで setError() メソッドを使用するには、対応するスコープ対象のメソッド setError() を使用します。
GlideElement - setInitialValue(オブジェクト値)
フィールドの初期値を設定します。
このメソッドは廃止されました。この機能には GlideElement - setValue(オブジェクト値) を使用します。
| 名前 | タイプ | 説明 |
|---|---|---|
| value | オブジェクト | フィールドの初期値。 |
| タイプ | 説明 |
|---|---|
| なし |
GlideElement - setJournalEntry(String entry, String userName)
ジャーナルエントリと作成者を作業メモまたはコメントフィールドとして追加します。
| 名前 | タイプ | 説明 |
|---|---|---|
| エントリー | 文字列 | ジャーナルエントリの内容。 |
| userName | 文字列 | オプション。ジャーナルエントリの属性となるユーザー。 |
| タイプ | 説明 |
|---|---|
| なし |
次の例は、作業メモとその作成者をレコードに追加する方法を示しています。
var now_GR = new GlideRecord("incident");
now_GR.addQuery("sys_id", "<sys_id_value>");
now_GR.query();
if(now_GR.next()){
now_GR.work_notes.setJournalEntry("Content of the journal entry.", "abel.tuter");
now_GR.update();
}
GlideElement - setValue(オブジェクト値)
フィールドの値を設定します。
- password2 フィールドを使用した認証用ではありません
- setValue() メソッドは password2 データをクリアーテキストとして渡すため、暗号化データの期待に関するエラーが発生します。さらに、password2 フィールドに setValue() メソッドを使用すると、暗号化する必要があるデータが公開されます。
password2 認証の場合は、代わりに setDisplayValue() メソッドを使用します。
| 名前 | タイプ | 説明 |
|---|---|---|
| value | オブジェクト | フィールドが設定される値。 |
| タイプ | 説明 |
|---|---|
| なし |
文字列を渡して値を設定します。
var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
glideRecord.short_description.setValue('Network failure');
オブジェクトを渡す値を設定します。
var now_GR = new GlideRecord('student');
now_GR.initialize();
now_GR.setValue('first_name', 'Joe');
now_GR.setValue('last_name', 'Smith');
now_GR.insert();
スコープ対応
スコープ対象のアプリケーションで setValue() メソッドを使用するには、対応するスコープ対象のメソッド setValue() を使用します。
GlideElement:toString()
フィールドの値を文字列に変換します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 文字列としてのフィールド値。 |
doit();
function doit() {
var now_GR = new GlideRecord('sys_user');
now_GR.query();
while (now_GR.next()) {
if ((now_GR().length != now_GR.first_name.toString().trim().length) || (now_GR.last_name.toString().length
!= now_GR.last_name.toString().trim().length)) {
now_GR.first_name = now_GR.first_name.toString().trim();
now_GR.last_name = now_GR.last_name.toString().trim();
now_GR.autoSysFields(false);
now_GR.update();
}
}
}
スコープ対応
スコープ対象のアプリケーションで toString() メソッドを使用するには、対応するスコープ対象のメソッド toString() を使用します。