Passing a parameter to startworkflow - InfoPath Dev
in

InfoPath Dev

Passing a parameter to startworkflow

Last post 09-15-2013 04:05 PM by Patrick Halstead. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 09-10-2013 01:21 PM

    • j-red
    • Not Ranked
    • Joined on 09-10-2013
    • Posts 5

    Passing a parameter to startworkflow

    I have a workflow that I would like to trigger from my Infopath 2007 form code. It has an Initiation parameter called RequestID that I would like to pass a value from my code.

    My code submits the data to a SQL db via a web service and returns the RequestID which I store in a variable.

    I can trigger the workflow without the parameter, but I need help updating that parameter with my variable.

    Here is the code that gets my workflow information and triggers the startworkflow:

    Public Shared Sub StartWorkflow(ByVal siteUrl As String, ByVal docUrl As String, ByVal workflowName As String, ByVal RequestID As Integer)

    'Call Workflow.asmx Web Reference

    Dim workflow As New Workflow.asmx.Workflow() workflow.Url = siteUrl & Convert.ToString("/_vti_bin/workflow.asmx")

    'Set Credentials to Network Cache (Whichever user is currently logged in)

    workflow.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials

    'Get the available workflows for the document library

    Dim assocNode As XmlNode = workflow.GetTemplatesForItem(docUrl)

    Dim nsmgr As New XmlNamespaceManager(assocNode.OwnerDocument.NameTable)

    nsmgr.AddNamespace("wf", "http://schemas.microsoft.com/sharepoint/soap/workflow/")

    Dim doc As New XmlDocument()

    Dim templateID As New Guid()

    Dim workflowFound As Boolean = False

    'Loop through the available workflows to find the relevant one

    Dim rows As XPathNodeIterator = assocNode.CreateNavigator().[Select]("//wf:WorkflowTemplate", nsmgr) While rows.MoveNext()

       If rows.Current.GetAttribute("Name", "").ToLower() = workflowName.ToLower() Then

          doc.LoadXml(rows.Current.SelectSingleNode("wf:AssociationData/wf:string", nsmgr).Value)

          Dim idNode As XPathNavigator = rows.Current.SelectSingleNode("wf:WorkflowTemplateIdSet", nsmgr)

          templateID = New Guid(idNode.GetAttribute("TemplateId", ""))

          workflowFound = True

          Exit While

    End If

    End While

    The InnerXML for doc includes the Parameter I set up in the workflow:

     <dfs:myFields>
     <dfs:queryFields />
     <dfs:dataFields>
      <d:SharePointListItem_RW>
       <d:RequestID>0</d:RequestID>
      </d:SharePointListItem_RW>
     </dfs:dataFields>
    </dfs:myFields>

    But when I try and change the node inner text it doesn't recognise d:RequestID

    nsmgr = New XmlNamespaceManager(assocNode.OwnerDocument.NameTable)

    nsmgr.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD")

    Dim xmlRoot As XmlElement = doc.DocumentElementxmlRoot.SelectSingleNode("d:RequestID", nsmgr).InnerText = RequestID

    Dim workflowNode As XmlNode = workflow.StartWorkflow(docUrl, templateID, doc.DocumentElement)

    The error I'm getting is namespace prefix d: is not defined. Have I got the wrong namespace?

    Does the workflow expect the same format as above? How can I write to  <d:RequestID>? I feel that I'm missing something quite simple here, but I have no idea what that may be.

    I need to send this parameter as it will direct a user to a different form with the request data pre-filled from the DB based on the requestID parameter.
    Jarred

     

  • 09-12-2013 08:29 AM In reply to

    • j-red
    • Not Ranked
    • Joined on 09-10-2013
    • Posts 5

    Re: Passing a parameter to startworkflow

    OK I worked it out. I needed to explicitly add the namespaces for d: and dfs: to the namespace manager.

    In other parts of my form it was working without having to add the namespace, but I think because I was messing with it with the workflow namespace it needed to be added like this:

    nsmgr.AddNamespace("dfs", "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution") nsmgr.AddNamespace("d", "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")

    doc.DocumentElement.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:RequestID", nsmgr).InnerText = RequestID

    'Trigger the workflow start

    Dim workflowNode As XmlNode = workflow.StartWorkflow(docUrl, templateID, doc.DocumentElement)

    I got the namespaces from the doc.innerxml

    Jarred

  • 09-15-2013 04:05 PM In reply to

    Re: Passing a parameter to startworkflow

    Cool. Glad to see you got it working and thanks for posting the fix.

    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.