MS Project 2010 PSI:有没有一种方法可以在不加载项目的情况下获取自定义字段值?
我正在尝试通过自定义字段值查找特定项目。到目前为止,这是我发现的最好的方法:
var targetProjectId = "some_external_reference_ID";
var projIdCustomFieldUid = GetCustomFieldUidByName("ExternalProjectId");
var projectList = base.ProjectClient.ReadProjectList();
foreach (ProjectDataSet.ProjectRow projRow in projectList.Project.Rows)
{
var fullProj = base.ProjectClient.ReadProject(projRow.PROJ_UID, DataStoreEnum.WorkingStore);
if (fullProj != null)
{
var cf = fullProj.ProjectCustomFields.Where(x => x.MD_PROP_UID == projIdCustomFieldUid && x.TEXT_VALUE == targetProjectId ).FirstOrDefault();
if (cf != null)
{
return fullProj;
}
}
}
return null;
}
正如您可以想象的那样,循环遍历所有项目并加载每个项目以检查自定义字段值是非常缓慢和丑陋的。我需要尽快通过自定义字段值识别 PROJ_UID,因此:
有没有办法在不加载整个项目的情况下获取自定义字段值?
I am trying to locate a particular project by a custom field value. So far, this is the best way I've found to do it:
var targetProjectId = "some_external_reference_ID";
var projIdCustomFieldUid = GetCustomFieldUidByName("ExternalProjectId");
var projectList = base.ProjectClient.ReadProjectList();
foreach (ProjectDataSet.ProjectRow projRow in projectList.Project.Rows)
{
var fullProj = base.ProjectClient.ReadProject(projRow.PROJ_UID, DataStoreEnum.WorkingStore);
if (fullProj != null)
{
var cf = fullProj.ProjectCustomFields.Where(x => x.MD_PROP_UID == projIdCustomFieldUid && x.TEXT_VALUE == targetProjectId ).FirstOrDefault();
if (cf != null)
{
return fullProj;
}
}
}
return null;
}
As you can imagine, looping through all the projects and loading each one to check the custom field value is horribly slow and ugly. I need to identify a PROJ_UID by custom field value as fast as possible, thus:
Is there a way to get at custom field values without loading a whole project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只需要已发布的项目,那么我将在 ProjectServer_Reporting 数据库(可能是 MSP_EPMProject_UserView 视图)上使用 SQL 查询。此视图包括大多数类型的自定义字段的列。
如果您确实需要通过 PSI 调用它,那么 iirc,您可以发出一个过滤查询来获取您需要的项目,但我面前没有语法。如果您确实想使用 PSI 而不是 SQL 方法,请告诉我,我会四处寻找。
希望这有帮助...
詹姆斯·弗雷泽
If you only need published projects then I would use a SQL query on the ProjectServer_Reporting database, probably the MSP_EPMProject_UserView view. This view includes columns for most types of custom fields.
If you really need to call this through the PSI, then iirc, there is a filtered query you can issue to get just the projects you need, but I don't have the syntax in front of me. Let me know if you really want to use PSI for this instead of the SQL method, and I'll look around for this.
Hope this helps...
James Fraser
使用 2007 版本的 PSI,我们遇到了同样的问题。我们决定将所有自定义元数据属性同步到 SharePoint 列表。这使得查询和使用变得非常容易。然而,维护同步需要相当多的工作。
我认为另一种方法是查询报告数据库,但我一直无法找到这方面的良好信息来源。
Using the 2007 version of the PSI, we came across this same problem. We decided to sync all of the custom metadata properties to a SharePoint list. This makes it very easy to query and consume. However, the sync is quite a bit of work to maintain.
I think an alternative would be to query the Reporting database, but I haven't been able to find a good source of information for this.
要加载自定义字段而不加载整个项目,您可以使用 ReadProjectEntities,如下所示 ReadProjectEntities(..., 32, ...) 其中 32 标识 CustomField 实体
To load custom fields withouth loading whole project you can use ReadProjectEntities like this ReadProjectEntities(..., 32, ...) where 32 identifies CustomField entities