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
スコープ付き 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
スコープ対象 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());
}
スコープ対象 GlideElement - changesFrom(Object o)
現在のフィールドの前の値が指定されたオブジェクトと一致するかどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| o | オブジェクト | 現在のフィールドの前の値と照合するオブジェクト値。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 前の値が一致する場合は true、一致しない場合は false。 |
// The following example shows that in a business rule, if "active" field is changed from true,
// insert a event in the EventQueue.
if (current.active.changesFrom(true)) {
gs.eventQueue("incident.inactive", current, current.incident_state, previous.incident_state);
}
スコープ対象 GlideElement - changesTo(Object o)
変更後のフィールドの新しい値が指定されたオブジェクトと一致するかどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| o | オブジェクト | 現在のフィールドの新しい値と照合するオブジェクト値。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 前の値が一致する場合は true、一致しない場合は false。 |
// The following example shows that in a business rule, if "active" field is changed to false,
// insert a event in the EventQueue.
if (current.active.changesTo(false)) {
gs.eventQueue("incident.inactive", current, current.incident_state, previous.incident_state);
}
スコープ対象 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
スコープ対象 GlideElement - getAttribute(String 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
スコープ対象 GlideElement - getBooleanAttribute(String 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
スコープ対象 GlideElement - getChoices(文字列依存)
指定されたフィールドの選択リストを返します。
選択リストを返すフィールドは、メソッド呼び出しで指定されます。例: var choices = glideRecord.urgency.getChoices();。選択リストフィールドタイプとそれに関連する機能の詳細については、「 選択リストフィールドタイプ」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| 依存 | 文字列 | オプション。選択リストフィールドが依存する関連レコード内のフィールド。 |
| タイプ | 説明 |
|---|---|
| アレイ | 選択肢 [sys_choice] テーブルの値である、選択リストに使用可能な値のリスト。dependent パラメーターが渡された場合、返される結果には、指定された依存フィールドで利用可能な選択肢のみが反映されます。 |
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();
スコープ付き GlideElement - getChoiceValue()
現在の選択肢のラベルを返します。
選択肢には値 (数値) とラベル (文字列) があります。このメソッドはラベルを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 選択した選択肢のラベル。 |
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 choiceLabel = glideRecord.urgency.getChoiceValue();
gs.info(choiceLabel);
出力:
1 - High
スコープ付き GlideElement - getDecryptedValue()
スコープ対象のアプリケーションのパスワード (双方向暗号化) フィールドのクリアテキスト値を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | クリアテキストパスワード。 |
var tablename = 'x_scoped_app_table'
var CI = new GlideRecord(tablename);
CI.addQuery('number', '0001002');
CI.query();
CI.next();
var password = CI.password_field
var decrypted = password.getDecryptedValue();
gs.info(decrypted);
x_scoped_app: cleartextpasswordスコープ対象 GlideElement - getDisplayValue(Number maxCharacters)
関連付けられた GlideRecord オブジェクトから指定されたフィールドの書式設定された表示値を返します。
表示値は、データベースの実際の値とユーザーまたはシステムの設定と設定に基づいて操作されます。
- 選択肢フィールド:データベース値は数値でもかまいませんが、表示値はよりわかりやすいものになります。
- 日付フィールド:データベース値は UTC 形式で、表示値はユーザーのタイムゾーンに基づいています。
- 暗号化テキスト:データベース値は暗号化されますが、表示される値はユーザーの暗号化コンテキストに基づいて暗号化されません。
- 参照フィールド:データベース値はsys_idですが、表示値は参照レコードの表示フィールドです。
表示値の詳細については、「 表示値」を参照してください。
| 名前 | タイプ | 説明 |
|---|---|---|
| maxCharacters | 番号 | オプション。必要な最大文字数。 デフォルト:すべて |
| タイプ | 説明 |
|---|---|
| 文字列 | 指定したフィールドの表示値。 |
次の例は、インシデントレコードの優先度フィールドの表示値を取得する方法を示しています。
var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
gs.info(glideRecord.priority.getDisplayValue());
出力:
1 - Critical
次の例は、インシデントデータベース内の指定されたフィールドの表示値と内部値の両方を取得する方法を示しています。
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
スコープ対象 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
スコープ付き GlideElement - getED()
フィールドの要素記述子を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| GlideElementDescriptor | フィールドの要素記述子。 |
var grInc = new GlideRecord('incident');
grInc.query('priority', '1');
var field = grInc.getElement('priority');
var ed = field.getED();
スコープ付き GlideElement - getGlideObject()
フィールドの値に関連付けられているプラットフォームオブジェクトを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| オブジェクト | フィールドのデータタイプに対応するプラットフォームオブジェクト ( 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
スコープ付き GlideElement - getGlobalDisplayValue()
電話番号を国際形式で返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 国際形式の電話番号。 |
次の例は、ウォークアップ場所の電話番号を取得する方法を示しています。この例では、 ウォークアップエクスペリエンス プラグインが必要です。
// Passing walkup location name and closed phone number in parameters
setWalkupLocPhone('Santa Clara Tech Lounge','phone_number');
function setWalkupLocPhone(locName, field) {
var walkupLoc = new GlideRecord('wu_location_queue');
walkupLoc.addQuery('name',locName);
walkupLoc.query();
walkupLoc.next();
// Returns the phone number of walk-up location queue in international format
gs.info(walkupLoc[field].getGlobalDisplayValue());
}
出力:
+91 98124 56789
スコープ付き GlideElement - getHTMLValue(Number maxChars)
フィールドの HTML 値を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| maxChar | 番号 | オプション。返す最大文字数。 |
| タイプ | 説明 |
|---|---|
| 文字列 | フィールドの HTML 値。 |
var inccause = new GlideRecord("incident");
inccause.short_description = current.short_description;
inccause.comments = current.comments.getHTMLValue();
inccause.insert();
スコープ付き 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.info(na[i]);
スコープ対象 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");
}
}
}
スコープ付き 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
スコープ付き 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
...
スコープ付き GlideElement - getReferenceTable()
参照要素のテーブル名を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 参照のテーブル名。 |
var grINC = new GlideRecord('incident');
grINC.query('number','INC0010041'); // record assignment group assigned to "CAB Approval"
if (grINC.next()) {
// Get the table name
var tableName = grINC.assignment_group.getReferenceTable();
gs.info( tableName );
}
スコープ付き GlideElement - getRefRecord()
指定された参照要素の GlideRecord オブジェクトを返します。
計算されたフィールドの場合、このメソッドは参照レコードをフェッチし、スクリプト化されたデフォルト値で計算を実行します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| GlideRecord | GlideRecord オブジェクト |
var grINC = new GlideRecord('incident');
grINC.addNotNullQuery('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.info(grUSER.getValue('name'));
}
スコープ付き 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());
}
}
スコープ対象 GlideElement - nil()
フィールドが null かどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | フィールドが null かどうかを示すフラグ。 可能な値:
|
var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
gs.info(glideRecord.state.nil());
出力:
false
スコープ対象 GlideElement - setDateNumericValue(ミリ秒数)
日付/時刻要素の値を、1970 年 1 月 1 日 00:00:00 GMT 以降の指定されたミリ秒数に設定します。
呼び出されると、 setDateNumericValue() は必要な GlideDateTime/GlideDate/GlideDuration オブジェクトを自動的に作成し、要素を指定された値に設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| ミリ秒 | 番号 | 1970 年 1 月 1 日からのミリ秒数 |
| タイプ | 説明 |
|---|---|
| なし |
var now_GR = new GlideRecord("incident");
now_GR.initialize();
now_GR.opened_at.setDateNumericValue(10000);
スコープ対象 GlideElement - setDisplayValue(Object value)
フィールドの表示値を設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| value | オブジェクト | フィールドに設定する値。 |
| タイプ | 説明 |
|---|---|
| なし |
var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
//change the urgency to 3
glideRecord.urgency.setDisplayValue('3 - Low');
gs.info(glideRecord.urgency);
スコープ対象 GlideElement - setError(文字列 errorMessage)
関連するフィールドにエラーメッセージを追加します。
| 名前 | タイプ | 説明 |
|---|---|---|
| errorMessage | 文字列 | エラーメッセージ。 |
| タイプ | 説明 |
|---|---|
| なし |
次の例は、簡単な説明が空の優先度 1 のインシデントにエラーメッセージを設定する方法を示しています。
var now_GR = new GlideRecord('incident');
now_GR.addQuery('priority', '1');
now_GR.query();
if (now_GR.next()) {
var shortDesc = now_GR.short_description.toString();
if (!shortDesc || shortDesc.trim() === '') {
now_GR.short_description.setError(
'A short description is required for all Priority 1 incidents. Please provide a brief summary of the issue.'
);
}
}
スコープ対象 GlideElement - setPhoneNumber(Object phoneNumber, Boolean strict)
フィールドを指定された電話番号に設定します。
このメソッドは、電話番号の GlideElement でのみ使用できます。
| 名前 | タイプ | 説明 |
|---|---|---|
| phoneNumber | オブジェクト | 設定する電話番号。これは、国際形式または国内形式のいずれかにすることができます。 |
| strict | ブーリアン | true の場合、指定された数値が正しい形式と一致する必要があることを指定します。false の場合、システムは不適切な形式の電話番号の修正を試みます。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 電話番号の値が設定されたかどうかを示すフラグ。 可能な値:
|
次の例は、ウォークアップ場所の電話番号を設定する方法を示しています。この例では、 ウォークアップエクスペリエンス プラグインが必要です。
setWalkupLocPhone('Santa Clara Tech Lounge','+91 9812456789');
function setWalkupLocPhone(locName, phoneNumber) {
var walkupLoc = new GlideRecord('wu_location_queue');
walkupLoc.addQuery('name', locName);
walkupLoc.query();
walkupLoc.next();
// Set phone number of walk-up location
var isPhoneNumberSet = walkupLoc.phone_number.setPhoneNumber(phoneNumber, true);
walkupLoc.update();
gs.info('Phone Number: ' + walkupLoc.phone_number);
gs.info('Is phone number specified match the correct format: ' + isPhoneNumberSet);
}
出力:
Phone Number: +919812456789
Is phone number specified match the correct format: true
スコープ対象 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();
スコープ付き GlideElement:toString()
GlideRecord フィールドの値を文字列に変換します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 文字列としての値。 |
var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
gs.info(glideRecord.opened_at.toString());
出力:
2019-08-31 23:09:51