0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

g_userについて【ServiceNow】

Posted at

※この記事はServiceNow初心者が学習用のために記載した記事です。内容について誤っている場合がございます。不足点などございましたらコメントいただけますと幸いです。

g_user とは?

  • g_user は、現在ログインしているユーザーの情報を取得するためのオブジェクトである
  • ServiceNowのクライアントスクリプト(Client Script)やUIスクリプトで使用できる

g_user の主なメソッドとプロパティ

1. g_user.userID

  • 現在のユーザーのSys IDを取得する
  console.log(g_user.userID);

2. g_user.userName

  • 現在のユーザーのユーザー名を取得する
  • console.log(g_user.userName);
    
    

3. g_user.hasRole(roleName)

  • 指定したロールをユーザーが持っているか確認する
  • 戻り値: true(持っている)または false(持っていない)
  •     if (g_user.hasRole('admin')) {
        console.log('このユーザーは管理者です。');
    } else {
        console.log('管理者権限がありません。');
    }
    

4. g_user.hasRoles()

  • ユーザーが1つ以上のロールを持っているか確認する
  • 戻り値: true(1つ以上のロールあり)または false(ロールなし)
  • if (g_user.hasRoles()) {
        console.log('ユーザーには少なくとも1つのロールがあります。');
    } else {
        console.log('このユーザーにはロールがありません。');
    }
    

5. g_user.isLoggedIn()

  • ユーザーがログインしているかどうかを判定する
  • 戻り値: true(ログイン済み)または false(未ログイン)
  • if (g_user.isLoggedIn()) {
        console.log('ユーザーはログインしています。');
    } else {
        console.log('ユーザーはログインしていません。');
    }
    

6. g_user.getFullName()

  • ユーザーのフルネームを取得する
  • 戻り値: string(ユーザーのフルネーム)
  • console.log(`ユーザーのフルネーム: ${g_user.getFullName()}`);
    

まとめ

  • g_user は、現在ログインしているユーザーの情報を取得し、UIの制御に役立てることができる便利なオブジェクトである
  • 特定のロールを持っているかのチェックや、ユーザー情報の表示などに活用できる
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?