GlideModal (ネクストエクスペリエンス): クライアント
GlideModal API は、モーダルと呼ばれるコンテンツオーバーレイを表示するためのメソッドを提供します。モーダルは、ページの上に表示され、ユーザーがアクションを実行すると閉じるインタラクティブなウィンドウです。モーダルを使用して、情報を表示したり、質問したり、アクションを実行したりすることができます。
クライアントサイド JavaScript を使用できる場所であればどこでも、スクリプトで GlideModal メソッドを使用します。これらのメソッドは、ほとんどの場合 [クライアント] チェックボックスがオンになっている UI アクションから呼び出されます。
- 静的テキスト
- 動的テキスト
- Forms
- イメージ
- ボタン
- 既存のモーダルを取得します。
- UI ページまたは渡された HTML からモーダルコンテンツを作成します。
- モーダルでタイトルを設定します。
- モーダルの幅を設定します。
- 設定を取得して設定します。
- モーダルビューを切り替えます。
var dialog = new nowapi.GlideModal("UI_dialog_name");
//Set the dialog title
dialog.setTitle('Show title');
//Set the dialog width
dialog.setWidth(550);
//Display the modal
dialog.render();GlideModal (ネクストエクスペリエンス):GlideModal(文字列 id、ブール readOnly、数値/文字列の幅)
GlideModal クラスのインスタンスを作成します。
| 名前 | タイプ | 説明 |
|---|---|---|
| ID | 文字列 | モーダルにロードするUI ページ の名前。 ベースシステムで提供されている テーブル:UI ページ [sys_ui_page] |
| readOnly | ブーリアン | オプション。モーダルのコンテンツが読み取り専用かどうかを示すフラグ。 有効な値:
デフォルト値:false |
| 幅 | 数値または文字列 | オプション。モーダルの幅 (ピクセル単位) またはモーダル CSS クラス。ピクセル幅が渡されると、指定された幅が対応する CSS クラスに揃えられます。 可能なモーダル CSS クラス:
デフォルト:modal-md 最大幅:900 ピクセル 注: setWidth() メソッドを使用してモーダルの幅を設定することもできます。 |
次のコード例は、既存の UI ページを使用して GlideModal オブジェクトを作成する方法を示しています。
var dialog = new nowapi.GlideModal('UI_dialog_name');
//Set the dialog title
dialog.setTitle('Show title');
//Set the desired preferences
dialog.setPreference('table', 'task');
dialog.setPreference('name', 'value');
//Opens the dialog
dialog.render();
次のコード例は、 glide_modal_confirm ファイルを使用して GlideModal オブジェクトを作成する方法を示しています。
var dialog = new nowapi.GlideModal('glide_modal_confirm', true, 300);
dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
dialog.setPreference('body', new GwtMessage().format("This will complete all update sets in the batch. Continue changing state to complete?"));
dialog.setPreference('focusTrap', true);
dialog.setPreference('onPromptComplete', doComplete);
dialog.setPreference('onPromptCancel', doCancel);
dialog.render();
function doComplete() {
callback(true);
}
function doCancel() {
callback(false);
}
GlideModal (ネクストエクスペリエンス):destroy()
現在のモーダルを閉じます。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| なし |
次のコード例は、 destroy() メソッドを使用してモーダルを閉じる方法を示しています。
function cancelDialog(){
var dialog = new nowapi.GlideModal('cancelTask');
// Sets the dialog title
dialog.setTitle('Cancel Task');
// Set up valid custom HTML to display
dialog.renderWithContent('<div style="padding:15px">
<p>What action do you want to take?</p>
<p><select name="cancellation" id="taskCancellation" class="form-control">
<option value="cancelOnly" role="option">Cancel task but keep requested item open
</option>
<option value="cancelAll" role="option">Cancel this and all other tasks, closing the
requested item</option></select></p><div style="padding:5px;float:right"><button style="padding:5px;margin-right:10px onclick="window.changeTaskAction(this.innerHTML, jQuery(\'#taskCancellation\').val())" class="btn btn-default">Abort</button>
<button style="padding:5px" class="btn btn-primary" onclick="window.changeTaskAction(this.innerHTML,jQuery(\'#taskCancellation\').val())">
Cancel Task</button></div></div>');
// Use the windows object to ensure the code is accessible from the modal dialog
window.changeTaskAction = function(thisButton, thisAction){
// Close the GlideModal dialog window
dialog.destroy();
// Submit to the back-end
if(thisButton=='Cancel Task'){
if(thisAction=="cancelAll"){
// Closed Incomplete -- will close the Requested Item and all other open tasks
g_form.setValue('state',4);
}else{
// Closed Skipped -- will only close this task
g_form.setValue('state',7);
}
//Regular ServiceNow form submission
gsftSubmit(null, g_form.getFormElement(), 'cancel_sc_task');
}
};
// Prevents the form from submitting when the dialog first loads
return false;
}
次のコード例は、 GlideModal.get().destroy() を使用してクライアントスクリプトでモーダルを閉じる方法を示しています。次のボタンは、UI ページの HTML で宣言<button onclick="closeMe()">する必要があります。</button>
function closeGlideModal() {
try {
nowapi.GlideModal.get().destroy();
} catch (err) {
console.warn("closeGlideModal ERROR: " + err.message);
var x = document.getElementById('THE_NAME_OF_YOUR_UI_PAGE' + '_closemodal');
if (x) {
x.click();
} else {
console.warn("No 'X' close button found!");
}
}
}
function closeMe() {
setTimeout(function() {
closeGlideModal();
}, 100);
}
GlideModal (ネクストエクスペリエンス) - get(文字列 id)
指定された UI ページ名で識別される GlideModal オブジェクトを返します。
このメソッドを使用して、 GlideModal.get().destroy() などの他の GlideModal 操作で使用する GlideModal オブジェクトを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| ID | 文字列 | モーダルに関連付けられているUI ページ の名前。 ベースシステムで提供されている テーブル:UI ページ [sys_ui_page] |
| タイプ | 説明 |
|---|---|
| GlideModal | 要求された GlideModal オブジェクト。 |
この例では、 get() メソッドを使用して、 destroy() メソッドを使用して閉じるモーダルを取得する方法を示します。
// If the modal was initially created like this:
var dialog = new nowapi.GlideModal("glide_modal_confirm");
dialog.render();
// Code using the modal
...
// Now use the get() and destroy() methods to close the modal
var glideModal = new nowapi.GlideModal().get("glide_modal_confirm");
glideModal.destroy();
// You could also code it like this:
// GlideModal.prototype.get('glide_modal_confirm').destroy();
GlideModal (ネクストエクスペリエンス):getID()
GlideModal ID を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | GlideModal の ID。 |
次の例は、インスタンスで GlideModal ID を取得する方法を示しています。
var id = modal.getID();
console.log('modal id', id);
GlideModal (ネクストエクスペリエンス) - getPreference(文字列名, 文字列値)
指定された preference (プロパティ) の値を返します。
モーダルを作成するアクションを呼び出すと、通常、 GlideModal (ネクストエクスペリエンス) - setPreference(文字列名, 文字列値) メソッドを使用してモーダルに必要な設定も作成されます。 UI ページのクライアントスクリプトは このメソッドを使用してこれらの設定を使用できます。
| 名前 | タイプ | 説明 |
|---|---|---|
| name | 文字列 | 取得する設定値の名前。この値は、 setPreference() メソッドを使用してモーダルで事前に設定されている必要があります。 |
| 値 | 文字列 | 取得する設定の値。この値は、 setPreference() メソッドを使用してモーダルで事前に設定されている必要があります。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 指定された設定の値。 |
この例は 設定を設定し、指定されたモーダルからその設定を取得する簡単なケースを示しています。
var dialog = new nowapi.GlideModal('UI_dialog_name');
//Sets the dialog title
dialog.setTitle('Modal title');
//Sets the value of the preference table
dialog.setPreference('table', 'incident');
//Gets the value of the preference table
var title = dialog.getPreference('table');
GlideModal (ネクストエクスペリエンス):getPreferences()
モーダルに関連付けられているすべての設定と値を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 指定された設定の値。 |
この例は 設定を設定し、指定されたモーダルからその設定を取得する簡単なケースを示しています。
var dialog = new nowapi.GlideModal('UI_dialog_name');
//Sets the dialog title
dialog.setTitle('Modal title');
//Sets the value of the preference table
dialog.setPreference('table', 'incident');
//Gets the value of the preference table
var title = dialog.getPreference('table');
GlideModal (ネクストエクスペリエンス):render()
モーダルで API がインスタンス化されたときに指定された UI ページをレンダリングします。UI に表示するには、モーダルを定義した後にこのメソッドを呼び出す必要があります。
UI ページを使用してモーダルのコンテンツを生成する場合は、このメソッドを呼び出します。モーダル内に HTML を表示する場合は、 renderWithContent(String html) を呼び出してモーダルをレンダリングします。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| なし |
次のコード例は、UI ページ「UI_dialog_name」を使用して GlideModal オブジェクトをインスタンス化し、モーダルのタイトルと幅を設定してから、UI (レンダリング) にモーダルを表示する方法を示しています。
var dialog = new nowapi.GlideModal("UI_dialog_name");
//Set the dialog title and width
dialog.setTitle('Show title');
dialog.setWidth(550);
//Display the dialog
dialog.render();
GlideModal (ネクストエクスペリエンス):renderWithContent(文字列 html)
指定された文字列ベースの HTML コンテンツを含むモーダルを表示します。
HTML からモーダルコンテンツを派生させるときは、render() メソッドの代わりに renderWithContent() メソッドを使用します。
| 名前 | タイプ | 説明 |
|---|---|---|
| html | 文字列 | モーダルに表示する HTML コンテンツ。 |
| タイプ | 説明 |
|---|---|
| なし |
このコード例は、ユーザーが選択できる選択肢のリストを含む、渡された HTML 文字列を使用して構築されたモーダルを表示する方法を示しています。
function cancelDialog(){
var dialog = new nowapi.GlideModal('cancelTask');
// Sets the dialog title
dialog.setTitle('Cancel Task');
// Set up valid custom HTML to display
dialog.renderWithContent('<div style="padding:15px">
<p>What action do you want to take?</p>
<p><select name="cancellation" id="taskCancellation" class="form-control">
<option value="cancelOnly" role="option">Cancel task but keep requested item open
</option>
<option value="cancelAll" role="option">Cancel this and all other tasks, closing the
requested item</option></select></p><div style="padding:5px;float:right"><button style="padding:5px;margin-right:10px onclick="window.changeTaskAction(this.innerHTML, jQuery(\'#taskCancellation\').val())" class="btn btn-default">Abort</button>
<button style="padding:5px" class="btn btn-primary" onclick="window.changeTaskAction(this.innerHTML,jQuery(\'#taskCancellation\').val())">
Cancel Task</button></div></div>');
// Use the windows object to ensure the code is accessible from the modal dialog
window.changeTaskAction = function(thisButton, thisAction){
// Close the GlideModal dialog window
dialog.destroy();
// Submit to the back-end
if(thisButton=='Cancel Task'){
if(thisAction=="cancelAll"){
// Closed Incomplete -- will close the Requested Item and all other open tasks
g_form.setValue('state',4);
}else{
// Closed Skipped -- will only close this task
g_form.setValue('state',7);
}
//Regular ServiceNow form submission
gsftSubmit(null, g_form.getFormElement(), 'cancel_sc_task');
}
};
// Prevents the form from submitting when the dialog first loads
return false;
}
GlideModal (ネクストエクスペリエンス) - setDialog(文字列 dialogName)
ダイアログ名を GlideModal のテーブル設定として設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| ダイアログ名 | 文字列 | ダイアログ名と対応する設定テーブルとして使用されるモーダルダイアログの名前。 |
| タイプ | 説明 |
|---|---|
| なし |
この例では、モーダルダイアログ名をテーブル設定として設定する方法を示します。
var dialog = new nowapi.GlideModal('change_confirm_reason', false, 648, 250);
dialog.setTitle(new GwtMessage().getMessage('Cancel Change Request'));
dialog.setPreference('focusTrap', true);
dialog.setDialog('onPromptComplete');
dialog.setPreference('onPromptCancel', onPromptCancel);
dialog.on('closeconfirm', onPromptCancel);
dialog.setPreference('buttonLabelComplete', new GwtMessage().getMessage('OK'));
dialog.setPreference('buttonLabelCancel', new GwtMessage().getMessage('Cancel'));
dialog.render();
GlideModal (ネクストエクスペリエンス) - setPreferenceAndReload(オブジェクトプロパティ)
指定された設定を行い、モーダルを再ロードします。
| 名前 | タイプ | 説明 |
|---|---|---|
| プロパティ | オブジェクト | 形式の設定として設定する名前と値のペア。 |
| タイプ | 説明 |
|---|---|
| なし |
この例では、 setPreferenceAndReload() 関数が設定を行い、更新された設定でモーダルを再ロードします。モーダルは初期設定でレンダリングされ、5 秒後に setPreferenceAndReload() が呼び出され、更新された設定でモーダルが再ロードされます。
// UI Page to render in the GlideModal is 'glide_modal_confirm'
var glideModal = new nowapi.GlideModal("glide_modal_confirm", false, 600);
glideModal.setTitle(getMessage("Confirmation"));
glideModal.setPreference("body", getMessage("Are you sure you want to reject this deal registration? This action cannot be undone."));
glideModal.setPreference('buttonLabelComplete', getMessage("Reject"));
glideModal.setPreference('buttonLabelCancel', getMessage("Cancel"));
glideModal.render();
var preferences = {
"body": "THIS IS THE UPDATED BODY PREFERENCE",
"buttonLabelComplete": "NEW REJECT",
"buttonLabelCancel": "NEW CANCEL"
};
setTimeout(function() {
glideModal.setPreferenceAndReload(preferences);
}, 5000); GlideModal (ネクストエクスペリエンス) - setPreference(文字列名, 文字列値)
現在のフォームの指定されたフィールドを指定された値に設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| 名前 | 文字列 | 更新するフォームフィールドの名前。 このフィールドが現在のフォームに存在しない場合、要求は無視されます。 |
| value | 文字列 | 指定されたフォームフィールドに格納する値。 |
| タイプ | 説明 |
|---|---|
| なし |
次のコード例は、 table 設定を「task」に設定し、 name 設定を「value」に設定する方法を示しています。
var dialog = new nowapi.GlideModal('UI_dialog_name');
//Set the dialog title
dialog.setTitle('Show title');
//Set the desired preferences
dialog.setPreference('table', 'task');
dialog.setPreference('name', 'value');
//Opens the dialog
dialog.render();
GlideModal (ネクストエクスペリエンス):setTitle(文字列タイトル)
モーダルのタイトルを設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| タイトル | 文字列 | モーダルのタイトルに表示するテキスト。 |
| タイプ | 説明 |
|---|---|
| なし |
次のコード例は、モーダルタイトルを [更新するテーブル] に設定する方法を示しています。
var dialog = new nowapi.GlideModal('UI_dialog_name');
//Sets the dialog title
dialog.setTitle('Table to update');
dialog.setPreference('table', 'task');
dialog.setWidth(550);
//Opens the dialog
dialog.render();
GlideModal (ネクストエクスペリエンス):setWidth(数値/文字列の幅)
モーダルの幅 を設定します。
GlideModal() コンストラクターを使用して API を初めてインスタンス化するときに、モーダルの幅を設定することもできます。
| 名前 | タイプ | 説明 |
|---|---|---|
| 幅 | 数値または文字列 | モーダルの幅 (ピクセル単位) またはモーダル CSS クラス。ピクセル幅が渡されると、指定された幅が対応する CSS クラスに揃えられます。 可能なモーダル CSS クラス:
最大幅:900 ピクセル |
| タイプ | 説明 |
|---|---|
| なし |
次のコード例は、モーダルの幅を 550 ピクセルに設定する方法を示しています。
var dialog = new nowapi.GlideModal('UI_dialog_name');
//Sets the dialog title
dialog.setTitle('Show title');
dialog.setPreference('name', 'value');
dialog.setWidth(550);
//Opens the dialog
dialog.render();
GlideModal (ネクストエクスペリエンス) - switchView(文字列 newView)
ビューを変更し、モーダルを再ロードします。
| 名前 | タイプ | 説明 |
|---|---|---|
| 新規ビュー | 文字列 | 使用するビュー。 |
| タイプ | 説明 |
|---|---|
| なし |
GlideModal (ネクストエクスペリエンス):type()
タイプを GlideModal として返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | タイプが GlideModal であることを示す文字列を返します。 |
GlideModal (ネクストエクスペリエンス):updateTitle()
GlideModal setTitle() メソッドを使用して指定されたタイトルを更新します。
変更をコミットするには、常に最初に GlideModal (ネクストエクスペリエンス):setTitle(文字列タイトル) を呼び出し、 updateTitle() を使用してモーダルタイトルを指定する必要があります。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| なし |
次の例は、 setTitle() と updateTitle() をそれぞれ呼び出して、モーダルのタイトルを設定および更新する方法を示しています。
var modal = new nowapi.GlideModal();
modal.renderWithContent('TEST CONTENT');
setTimeout(function() {
modal.setTitle("TEST setTitle() AND updateTitle() METHODS"); // will only update the `title` prop, updateTitle() must be called to see change
modal.updateTitle();
}, 3000);