ブログ

2021/03/10
【プリザンター】 第86回)サーバスクリプト#4 Contextオブジェクト

contextオブジェクトとは

こんにちは、CCSの田中です。

サーバスクリプトについての4回目の投稿になります。
まだどうやって使えるのか、どんな設定すると便利なのかなどを考えていて、具体的な案が出てきていない状況です。そう言っていても進まないため、今回はcontextオブジェクトについて調べてみました。
プリザンターのユーザマニュアルにはプロパティの説明はあり、すべて読取り専用ということで、何かの判定に使えるのではと思っています。

contextのプロパティの値

contextのプロパティには、「SiteId」や「Id(レコードID)」などがあり、一覧画面やレコードの詳細画面を開いたときの情報が入っています。
まずは、以下のようにログを出力することで、各プロパティにどのような値が入っているのかを確認したいと思います。
サーバスクリプトに以下のように確認するプロパティを書いていきます。
条件は、ひとまず「サイト設定の読み込み時」にしておきましょう。

<サーバスクリプト>


context.Log('FormStringRaw=' + context.FormStringRaw);
context.Log('FormString=' + context.FormString);
context.Log('Ajax=' + context.Ajax);
context.Log('Mobile=' + context.Mobile);
context.Log('ApplicationPath=' + context.ApplicationPath);
context.Log('AbsoluteUri=' + context.AbsoluteUri);
context.Log('AbsolutePath=' + context.AbsolutePath);
context.Log('Url=' + context.Url);
context.Log('UrlReferrer=' + context.UrlReferrer);
context.Log('Query=' + context.Query);
context.Log('Controller=' + context.Controller);
context.Log('Action=' + context.Action);
context.Log('TenantId=' + context.TenantId);
context.Log('SiteId=' + context.SiteId);
context.Log('Id=' + context.Id);
context.Log('Groups=' + context.Groups);
context.Log('TenantTitle=' + context.TenantTitle);
context.Log('SiteTitle=' + context.SiteTitle);
context.Log('RecordTitle=' + context.RecordTitle);
context.Log('DeptId=' + context.DeptId);
context.Log('UserId=' + context.UserId);
context.Log('LoginId=' + context.LoginId);
context.Log('Language=' + context.Language);
context.Log('TimeZoneInfo=' + context.TimeZoneInfo);
context.Log('HasPrivilege=' + context.HasPrivilege);
context.Log('ApiVersion=' + context.ApiVersion);
context.Log('ApiRequestBody=' + context.ApiRequestBody);
context.Log('RequestDataString=' + context.RequestDataString);
context.Log('ContentType=' + context.ContentType);




Chromeブラウザを開いて、F12キーを押下するとデベロッパーツールが開くので、「Console」メニューをクリックすると、今回設定した情報が表示されますので、確認ができます。
以下が一覧ページを開いた時のConsoleの結果です。
SiteIdやId、UserId、LoginIdなどは容易に想像ができたのですが、Groupsなどは良く理解できておりません。また、Mobileについては、Trueだった場合に別の処理をさせるなどスマホ等の対応で処理がわけられそうですね。

FormStringRaw=
FormString=
Ajax=false
Mobile=false
ApplicationPath=/pleasanter/
AbsoluteUri=http://localhost/pleasanter/items/18972/index
AbsolutePath=/pleasanter/items/18972/index
Url=http://localhost/pleasanter/items/18972/index
UrlReferrer=http://localhost/pleasanter/items/18972/edit
Query=
Controller=items
Action=index
TenantId=1
SiteId=18972
Id=18972
Groups=[object Object]
TenantTitle=Pleasanter
SiteTitle=Contextオブジェクト確認用
RecordTitle=null
DeptId=4
UserId=5
LoginId=K_Tanaka
Language=ja
TimeZoneInfo=(UTC+09:00) 大阪、札幌、東京
HasPrivilege=true
ApiVersion=1
ApiRequestBody=null
RequestDataString=
ContentType=null

まとめ

さて、いかがでしたか?

今回はサーバスクリプトの4回目としてcontextオブジェクトについて説明しました。
まだどう使ってい良いかを模索中なので、もう少し実用レベルのものを作りましたら、また紹介したいと思います。

導入の支援、スクリプト開発などでお困りの場合は、当社で支援もいたします。プリザンター逆引き辞典PDF版やスタイル・スクリプトサンプル集PDF版の販売もしております!

☆☆ブログ内容への質問や追加説明をご希望の方は
【問い合わせフォーム】 こちら からお気軽にお問い合わせください☆☆

PAGE TOP