Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
みなさん、こんにちは。
今日は開発者の方向けの情報として、Microsoft Dynamics CRM
ユーザーの設定の取得、更新についてのサンプルを紹介します。
UsetSettings エンティティ
Microsoft Dynamics CRM では、各ユーザーの設定を管理者が
一括して参照する機能がありません。しかし全ユーザーの設定
の参照や更新を行いたいという要望は多くあります。
ユーザーの設定は UserSettings エンティティに格納されており、
SDK を利用してデータを取得、更新することが可能です。
参照: UserSettings エンティティ メタデータ
https://msdn.microsoft.com/ja-jp/library/gg328438.aspx
サンプルコード
今回は、サンプル: タイム ゾーン情報の取得を利用します。
https://msdn.microsoft.com/ja-jp/library/hh547406.aspx
1. Visual Studio で sdk\samplecode\cs\businessdatamodel\
businessmanagement\businessmanagement.sln を開きます。
2. プロジェクトのプロパティより、スタートアップ オブジェクトに
WorkingWithTimeZones を指定します。
![]()
3. WorkingWithTimeZones.cs を開きます。
4. 65行目 から 70 行目までをコメントアウトします。
5. 63行目 の RetrieveCurrentUsersSettings(); の次の行に以下の
コードを差し込みます。
Console.WriteLine("LocaleId: " + _localeId + " TimeZoneCode: " + _timeZoneCode);
6. プログラムを実行します。必要な接続情報を入力します。
7. 以下のように、接続したユーザーのロケールとタイムゾーン
が表示されます。
サンプルコードの変更
では次に、このサンプルコードを発展させて、全ユーザー名と
タイムゾーンの情報を表示してみます。
以下のメソッドをクラスに追加します。
private void RetrieveAllUsersSettings()
{
// 有効でかつライセンスがあるユーザーのみ取得
var users = _serviceProxy.RetrieveMultiple(
new QueryExpression(SystemUser.EntityLogicalName)
{
ColumnSet = new ColumnSet("fullname"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("isdisabled", ConditionOperator.Equal, false),
new ConditionExpression("islicensed", ConditionOperator.Equal, true)
}
}
}).Entities;
// それぞれのユーザーの設定を確認
foreach (SystemUser user in users)
{
var userSettings = _serviceProxy.RetrieveMultiple(
new QueryExpression(UserSettings.EntityLogicalName)
{
ColumnSet = new ColumnSet("localeid", "timezonecode"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("systemuserid", ConditionOperator.Equal, user.SystemUserId)
}
}
}).Entities[0].ToEntity<UserSettings>();
// 結果を画面に表示
Console.WriteLine("UserName: " + user.FullName + " LocaleId: " + _localeId + " TimeZoneCode: " + _timeZoneCode);
}
}
こちらのメソッドを実行することで、各ユーザーのロケールと
タイムゾーン情報を取得することが出来ます。
まとめ
後は取得する列の追加、削除や結果をどこに表示するか、また更新
できる列については更新する等の機能を追加することが可能です。
- Dynamics CRM サポート 中村 憲一郎