以编程方式将项目添加到列表时工作流程启动失败

发布于 2025-01-07 01:08:43 字数 2492 浏览 2 评论 0原文

我有一个自定义构建的 Web 服务,旨在将项目简单地添加到 SharePoint Foundation 2010 中的列表中。我已将工作流附加到列表,但是当我使用 Web 服务(引用 SharePoint 对象模型)创建项目时,工作流“失败”在开始'。如果我直接在 SharePoint 中将项目添加到列表中,工作流程将按要求启动,不会出现任何问题。到目前为止,我已尝试以下操作(包括一起使用它们的所有变体),但这些都不能解决问题:

  • 使用 SPSecurity.RunWithElevatedPrivilages 运行我的代码
  • 模拟管理员和系统帐户的不同用户来创建项目作为
  • 运行我的应用程序池作为与我的站点的应用程序池相同的用户以与
  • 我的站点的应用程序池用户不同的帐户运行我的应用程序池 Web 服务没有失败,它正在创建项目,只是工作流程没有运行...任何人都可以帮我解决这个问题吗?

我用来创建列表项的代码如下:

 SPSecurity.RunWithElevatedPrivileges(delegate()
        {

            SPSite oTempSite = new SPSite(SharePointSite);
            SPUser oUserImpersonate = oTempSite.OpenWeb().EnsureUser(UserToEntryAs);

            SPSite oSite = new SPSite(SharePointSite, oUserImpersonate.UserToken);
            SPWeb oWeb = oSite.OpenWeb();

            try
            {
                oSite.AllowUnsafeUpdates = true;
                oWeb.AllowUnsafeUpdates = true;

                SPList oList = oWeb.Lists["Sample Log"];

                SPListItem oNewItem = oList.Items.Add();

                oNewItem["Customer"] = intCustomerID;
                oNewItem["Cust. Contact Name"] = strCustomerContactName;
                oNewItem["Contact Email"] = strCustomerContactEmail;
                oNewItem["Sample Number"] = strSampleNumber;
                oNewItem["Notes"] = strNotes;
                oNewItem["Application"] = strSampleApplication;
                oNewItem["Despatch Method"] = strDespatchMethod;
                oNewItem["Cost"] = dblCost;
                oNewItem["Sample 1"] = intSampleProductID;
                oNewItem["Weight 1"] = strSampleWeight;
                oNewItem["Batch No. 1"] = strSampleBatch;

                //Handle Account Manager(s):
                SPFieldUserValueCollection usrAccountManagers = new SPFieldUserValueCollection();
                foreach (string strAcctMrg in AccountManagers.Split(';'))
                {
                    SPUser oUser = oWeb.EnsureUser(strAcctMrg);
                    usrAccountManagers.Add(new SPFieldUserValue(oWeb, oUser.ID, oUser.LoginName));
                }
                oNewItem["Account Manager"] = usrAccountManagers;

                oNewItem["Content Type"] = "Ingredient Sample"; //Set the content type to be 'Ingredient Sample'
                oNewItem["Ingredient Sample Status"] = "Awaiting Result"; //Set the status to default to 'Awaiting Result'

                oNewItem.Update();

提前致谢...

I have a custom built web service that is built to simply add items into a list in SharePoint Foundation 2010. I have workflow attached to the list but when I create an item using my web service (which references the SharePoint Object Model) workflows 'Fail on Start'. If I add an item to the list directly within SharePoint the workflows start as required with no problems. I have tried the following so far (including all variations of using them together) but non of these fix the issue:

  • Using SPSecurity.RunWithElevatedPrivilages to run my code
  • Impersonating a different user to the Administrator and System Account to create the item as
  • Running my application pool as the same user as my site's application pool
  • Running my application pool as a different account to my site's application pool user
    The web service is not failing and it is creating the items, just the workflows are not running... can anyone help me with this please?

The code I am using to create the list item is as follows:

 SPSecurity.RunWithElevatedPrivileges(delegate()
        {

            SPSite oTempSite = new SPSite(SharePointSite);
            SPUser oUserImpersonate = oTempSite.OpenWeb().EnsureUser(UserToEntryAs);

            SPSite oSite = new SPSite(SharePointSite, oUserImpersonate.UserToken);
            SPWeb oWeb = oSite.OpenWeb();

            try
            {
                oSite.AllowUnsafeUpdates = true;
                oWeb.AllowUnsafeUpdates = true;

                SPList oList = oWeb.Lists["Sample Log"];

                SPListItem oNewItem = oList.Items.Add();

                oNewItem["Customer"] = intCustomerID;
                oNewItem["Cust. Contact Name"] = strCustomerContactName;
                oNewItem["Contact Email"] = strCustomerContactEmail;
                oNewItem["Sample Number"] = strSampleNumber;
                oNewItem["Notes"] = strNotes;
                oNewItem["Application"] = strSampleApplication;
                oNewItem["Despatch Method"] = strDespatchMethod;
                oNewItem["Cost"] = dblCost;
                oNewItem["Sample 1"] = intSampleProductID;
                oNewItem["Weight 1"] = strSampleWeight;
                oNewItem["Batch No. 1"] = strSampleBatch;

                //Handle Account Manager(s):
                SPFieldUserValueCollection usrAccountManagers = new SPFieldUserValueCollection();
                foreach (string strAcctMrg in AccountManagers.Split(';'))
                {
                    SPUser oUser = oWeb.EnsureUser(strAcctMrg);
                    usrAccountManagers.Add(new SPFieldUserValue(oWeb, oUser.ID, oUser.LoginName));
                }
                oNewItem["Account Manager"] = usrAccountManagers;

                oNewItem["Content Type"] = "Ingredient Sample"; //Set the content type to be 'Ingredient Sample'
                oNewItem["Ingredient Sample Status"] = "Awaiting Result"; //Set the status to default to 'Awaiting Result'

                oNewItem.Update();

Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话已封尘 2025-01-14 01:08:43

研究 ULS 日志错误后,我发现问题出在 Web 服务上的 web.config 文件,该文件需要声明工作流程的授权类型才能在我创建的项目上运行。

我用这篇文章来帮助我解决它:http://social.msdn.microsoft.com/forums/en-US/sharepointworkflow/thread/71d23c0e-24c5-4d61-8d62-265c374ac81c/

After researching the ULS log errors I found the issue was with my web.config file on my Web Service that needed the Authorized types declaring for the workflows to be able to run on the item I had created.

I used this post to help me resolve it: http://social.msdn.microsoft.com/forums/en-US/sharepointworkflow/thread/71d23c0e-24c5-4d61-8d62-265c374ac81c/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文