SPSitedataQueryを使用して特定のユーザーのためにタスクを集約するために正しいSPFieldUservalueを入手できますか?
-
10-12-2019 - |
質問
特定のユーザーの特定のコンテンツタイプのすべてのタスクを集めようとしています。これを達成するために私はこのようなSPSiteTaQqueryを使用しています:
string where = String.Format(@"<Where>
<And>
<BeginsWith>
<FieldRef Name='ContentTypeId'/>
<Value Type='Text'>0x0108010031C20CDC28544f93B27958D36ACBE2F5</Value>
</BeginsWith>
<Eq>
<FieldRef Name='AssignedTo'/>
<Value Type='Text'>{0}</Value>
</Eq>
</And>
</Where>", userValue.ToString());
query.Query = where;
DataTable results = web.GetSiteData(query);
.
コンテンツの種類をフィルタリングしたいだけでなく、ユーザーのフィルタリングは失敗した場合はうまく機能します。
これは私が問題があると思います。
17;#TestUser01
.
しかし私の通常のloginnameには、特許請求の列とドメインが含まれており、こののように見えます。
i:0#.w|test\TestUser01
.
assignedto-fieldにある同じユーザー文字列を取得するためにSPFieldUservalueを作成しようとしました。
SPFieldUserValue userValue = new SPFieldUserValue(web, SPContext.Current.Web.CurrentUser.ID, SPContext.Current.Web.CurrentUser.LoginName);
.
..しかし、私はちょうどこのような値を得るだけです:
17;#i:0#.w|test\TestUser01
.
..そして私はまだ私の照会から結果を得る..
どのように正しい文字列を実行してクエリを実行できますか?
解決
By changing the CAML like this:
string where = @"<Where>
<And>
<BeginsWith>
<FieldRef Name='ContentTypeId'/>
<Value Type='Text'>0x0108010031C20CDC28544f93B27958D36ACBE2F5</Value>
</BeginsWith>
<Eq>
<FieldRef Name='AssignedTo' LookupId='TRUE' />
<Value Type='Integer'><UserID /></Value>
</Eq>
</And>
</Where>";
query.Query = where;
DataTable results = web.GetSiteData(query);
it will fetch for current user :)
If you need to specify another user you can use:
string where = String.Format(@"<Where>
<And>
<BeginsWith>
<FieldRef Name='ContentTypeId'/>
<Value Type='Text'>0x0108010031C20CDC28544f93B27958D36ACBE2F5</Value>
</BeginsWith>
<Eq>
<FieldRef Name='AssignedTo' LookupId='TRUE' />
<Value Type='Integer'>{0}</Value>
</Eq>
</And>
</Where>", userValue.ToString());
query.Query = where;
DataTable results = web.GetSiteData(query);
and just make sue you have the ID of the user in userValue
他のヒント
The CAML Query for fetching the values for current user is:
"<Where><Eq><FieldRef Name='AssignedTo' /><Value Type='Integer'><UserID Type='Integer' /></Value></Eq></Where>";
And for another user it should be as mentioned by @Robert.
所属していません sharepoint.stackexchange