您的位置:首页 > 其它

SSRS 请求并显示SharePoint人员和组字段

2013-06-19 16:17 85 查看
场景:

使用Reporting Service请求SharePoint List,该list中包含人员和组字段。要求:只显示人员或组的display name。示例如下:

项目参与人员期望显示
项目1张三#contoso\zhangsan;李四#contoso\lisi;19;#王五;管理员组张三;李四;王五;管理员组
步骤:

1. 替换";#"成"@@"

2. 按";"分割成数组,遍历数组,循环取出值

3. 按"#"分割字符串,取数组第一个值

4. 按"@@"分割字符串,取数组第二个值

Public Function GetPersionName(Combined As String) As String
if (InStr(Combined ,"@@") > 0) Then
Return Split(Combined,"@@").GetValue(1)
Else
if(InStr(Combined ,"#") > 0) Then
Return  Split(Combined,"#").GetValue(0)
Else
Return Combined
End If
End If
End Function

Public Function GetPersionNameStr(Combined As String) As String
if  (Combined ="") Then
return ""
End If

dim returnStr,i
returnStr= ""

Combined = Replace(Combined,";#","@@")
if (InStr(Combined ,";") > 0) Then
for  i = 0 to Split(Combined,";").Length - 1
dim str = Split(Combined,";").GetValue(i)
returnStr = returnStr+ GetPersionName(str) + ";"
next
Return returnStr
Else
Return GetPersionName(Combined)+";"
End If
End Function


报表字段里插入fx,值等于

=Code.GetPersionNameStr(Field!参与人员.Value)


预览。

P.S.

在RS中的IIF用起来跟传统的if判断有点不同。IIF不是个表达式,而是个方法,这个方法有3个参数。

IIF(Condition, ValueIfTrue, ValueIfFalse)


也就是说,Condition,ValueIfTrue,ValueIfFalse在运行的时候都会执行。如果你想这样玩儿,你就会失望了。

IIF(
InStr(Fields!User.Value,";") > 0
,Split(Fields!User.Value,";").GetValue(1)
,Fields!User.Value
)


不管条件InStr(Fields!User.Value,";") > 0成功与否,Split(Fields!User.Value,";").GetValue(1)都会执行。是不是相当不爽???!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: