如何在OnCreating事件处理程序中更新自定义字段 [英] How to update custom field inside OnCreating Event handler

查看:66
本文介绍了如何在OnCreating事件处理程序中更新自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我试图在OnCreating项目事件处理程序中使用PSI更新自定义字段,但没有成功。

I was trying to update a custom field using PSI inside a OnCreating Project Event Handler, but without sucess.

在下面,你可以看到我的尝试:

Here below, you can see how i was trying:

public override void OnCreating(PSContextInfo contextInfo, ProjectPreEventArgs e)
        {


            SPSite site = new SPSite(contextInfo.SiteGuid);
            try
            {
                NetworkCredential credential = new NetworkCredential(userProject, passProject);

                Services.ServicePSI service = new Services.ServicePSI(site.Url, credential);

                service.LoadProjectService(ref ProjectClient);
                service.LoadQueueService(ref QueueSoapClient);

                _DataSet = ProjectClient.ReadProject(e.ProjectGuid, SvcProject.DataStoreEnum.WorkingStore);

                PSSchema.ProjectDataSet.ProjectCustomFieldsRow newrow = e.ProjectDataSet.ProjectCustomFields.NewProjectCustomFieldsRow();
                newrow.CUSTOM_FIELD_UID = Guid.NewGuid();
                newrow.MD_PROP_UID = fieldUid;
                newrow.PROJ_UID = e.ProjectGuid;
                newrow.NUM_VALUE = 15;

                e.ProjectDataSet.ProjectCustomFields.AddProjectCustomFieldsRow(newrow);

                ProjectClient.QueueAddToProject(Guid.NewGuid(), e.ProjectDataSet.Project[0].PROJ_SESSION_UID, e.ProjectDataSet, false);
            }
            finally
            {
                site.Dispose();
                base.OnCreating(contextInfo, e);
            }
        }

但是在项目创建后,该字段仍然是空白。

But after project created the field still blank.

任何想法都会受到欢迎。

Any ideas will be appreciate.

Tks!

推荐答案

Vanessa,

Vanessa,

我过去多次处理过这个问题。任何项目服务器事件处理程序中的e.ProjectDataSet都不可用于更新。这是项目服务器事件处理程序的限制。做你想做的事情的唯一方法是等到通过OnCreated创建
项目,然后检查项目,使用PSI读取项目,添加/更新自定义字段并重新检入。这可以可以在每晚的基础上使用偶数处理程序或预定作业完成。

I have dealt with this many times in the past. The e.ProjectDataSet from any of the project server event handlers is not available for updates. This is a limitation of the project server event handlers. The only way to do what you want is to wait until the project has been created via OnCreated and then check out the project, read the project using PSI, add/update the custom field and check it back in. This can be done with an even handler or a scheduled job on a nightly basis.

您可以考虑的另一个选项是使用项目服务器工作流程。使用工作流,您可以避免为此编写代码,而是使用工作流任务来更新项目自定义字段。工作流程将负责签出,更新和
重新签入。

Another option you can consider is to use a project server workflow. With a workflow, you can avoid having to write code for this and instead use a workflow task to update a project custom field. The workflow will take care of checking out, updating and checking back in.


这篇关于如何在OnCreating事件处理程序中更新自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆