2010-06-30 6 views

답변

3

새로 생성 된 작업은 실제로 SharePoint ListItem입니다. ExtendedProperties는 특히 Workflow Task 속성입니다. MSDN 설명서 당으로

는 :

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

이것은 AlterTask 방법은 그것을 호출 할 수 있습니다 전에 새로운 작업을 나타내는 SPListItem의 컨텐츠 유형이 "워크 플로 작업을"로 설정되어야 함을 의미 :

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
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 
관련 문제