SPWorkflowTask.AlterTask выдает «Указанный метод не поддерживается» - PullRequest
1 голос
/ 30 июня 2010

Я пытаюсь вызвать AlterTask для недавно созданной задачи Sharepoint, чтобы добавить расширенные свойства в мою задачу, и выдается исключение NotSupportedException.

Что происходит?

Ответы [ 2 ]

3 голосов
/ 30 июня 2010

Вновь созданная задача на самом деле является элементом списка SharePoint.ExtendedProperties, в частности, является свойством Задача рабочего процесса.

Согласно документации MSDN:

The content type of the item passed to the task parameter is not derived from the WorkflowTask content type.

Это означает, что для типа содержимого SPListItem, представляющего вашу новую задачу, должно быть установлено значение «Задача рабочего процесса»прежде чем метод AlterTask может быть вызван на нем:

    Dim selectedTaskList As SPList = web.Lists(taskListName)

    ' Create a new task item
    Dim newTask As SPListItem = selectedTaskList.Items.Add()

   ' Turn the new task item into a Workflow Task
    Dim newTaskContentType As Microsoft.SharePoint.SPContentType = web.AvailableContentTypes("Workflow Task")
    newTask("ContentTypeId") = newTaskContentType.Id

   ' Now the AlterTask method will work.  (assume you've alreade declared a hashtable of properties to set)
    Microsoft.SharePoint.Workflow.SPWorkflowTask.AlterTask(newTask, myHashTable, True)
0 голосов
/ 24 марта 2017
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim IntItemID As Integer
    Dim siteId As Guid = SPContext.Current.Site.ID
    Dim webId As Guid = SPContext.Current.Web.ID
    Using objSpSite As New SPSite(siteId)
        Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)

            If Not Page.Request.QueryString("ItemID") Is Nothing And Page.Request.QueryString("ItemID") <> "" Then
                IntItemID = CInt(Page.Request.QueryString.Item("ItemID").ToString)
                Panel1.Visible = False

                txtID.Text = IntItemID.ToString
                Dim objList As SPList = objSpWeb.Lists("RequestList")
                Dim objListItem As SPListItem = objList.Items.GetItemById(IntItemID)
                dtPermission.SelectedDate = objListItem("PermissionDate")
                dtTimeFrom.SelectedDate = objListItem("PermissionFromTime")
                dtTimeTo.SelectedDate = objListItem("PermissionToTime")
                cmbType.SelectedValue = objListItem("PermissionType")
                'dtCreated.SelectedDate = objListItem("")

            Else
                IntItemID = 0
                txtID.Text = "New"
                dtCreated.SelectedDate = Today
                txtCreatedBy.Text = objSpWeb.CurrentUser.Name
                Dim objServiceContext As SPServiceContext = SPServiceContext.GetContext(objSpSite)
                Dim objUserProfileManager As New UserProfileManager(objServiceContext)

                Dim objUserProfile As UserProfile
                Dim strUserAccount As String
                strUserAccount = objSpWeb.CurrentUser.LoginName.Replace("i:0#.w|", "")
                If objUserProfileManager.UserExists(strUserAccount) Then
                    objUserProfile = objUserProfileManager.GetUserProfile(strUserAccount)
                    Try
                        txtManager.Text = objUserProfile.GetManager.AccountName
                    Catch ex As Exception
                        txtManager.Text = ex.Message
                    End Try

                End If


                Panel2.Visible = False

            End If

        End Using
    End Using


End Sub

Protected Sub cmdSubmit_Click(sender As Object, e As EventArgs) Handles cmdSubmit.Click
    Dim siteId As Guid = SPContext.Current.Site.ID
    Dim webId As Guid = SPContext.Current.Web.ID

    Using objSpSite As New SPSite(siteId)
        Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
            objSpWeb.AllowUnsafeUpdates = True
            Dim list As SPList = objSpWeb.Lists("RequestList")
            Dim item As SPListItem = list.Items.Add()
            item("PermissionDate") = dtPermission.SelectedDate
            item("PermissionFromTime") = dtTimeFrom.SelectedDate
            item("PermissionToTime") = dtTimeTo.SelectedDate
            item("PermissionType") = cmbType.SelectedValue
            item("PermissionApprover1") = txtManager.Text

            item.Update()
            list.Update()
            objSpWeb.AllowUnsafeUpdates = False
        End Using
    End Using

End Sub

Protected Sub cmdApprove_Click(sender As Object, e As EventArgs) Handles cmdApprove.Click
    Dim siteId As Guid = SPContext.Current.Site.ID
    Dim webId As Guid = SPContext.Current.Web.ID
    Using objSpSite As New SPSite(siteId)
        Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
            Dim objList As SPList = objSpWeb.Lists("RequestList")
            Dim objListItem As SPListItem = objList.Items.GetItemById(CInt(txtID.Text))

            Dim objWFTask As SPWorkflowTask = objListItem.Tasks(0)

            If objWFTask Is Nothing Then
                ' no matching task
                Return
            End If

            ' alter the task
            Dim ht As New Hashtable()

            ht("Status") = "Complete"
            ht("PercentComplete") = 1.0F

            SPWorkflowTask.AlterTask(TryCast(objWFTask, SPListItem), ht, True)
        End Using
    End Using
...