开发者

How to update the original InfoPath form from within Workflow?

I have created an InfoPath form (e.g. Form_ExpenseReport) for collect data from end users, and a number of task forms (also InfoPath form, e.g. TaskForm_1, TaskForm_2) for my state machine workflow use. The users want to see all the comments of Task forms (TaskForm_1 & TaskForm_2) in the original IP form (Form_ExpenseReport). How can I update the first form from within workflow? Can anybody give me some tips?

My environment:


Use the below method to update the values in InfoPath form from Workflow.. it is generic method..

You need to pass .. FieldName as xpath (/myfields/my:txtcomments",your values)

 public void SetFormFieldvalue(string FieldName, string FieldValue)
        {
            SPFile file = workflowProperties.Item.File;
            string strLabel = string.Empty;
            try
            {
            XmlDocument modifyEmpXMlDoc = new XmlDocument();
            using (MemoryStream memorySream = new MemoryStream(file.OpenBinary()))
            {
                modifyEmpXMlDoc.PreserveWhitespace = true;
                modifyEmpXMlDoc.Load(memorySream);
                memorySream.Close();
            }
            if (modifyEmpXMlDoc == null)
                return;

            XPathNavigator modifyEmpFormNav = modifyEmpXMlDoc.CreateNavigator();

            modifyEmpFormNav.MoveToFollowing(XPathNodeType.Element);
            XmlNamespaceManager nsManager = new XmlNamespaceManager(new NameTable());

            foreach (KeyValuePair<string, string> nameSpace
                in modifyEmpFormNav.GetNamespacesInScope(XmlNamespaceScope.All))
            {
                if (nameSpace.Key == String.Empty)
                {
                    nsManager.AddNamespace("def", nameSpace.Value);
                }
                else
                {
                    nsManager.AddNamespace(nameSpace.Key, nameSpace.Value);
                }
            }

            // Change the value of the InfoPath form field
            modifyEmpXMlDoc.SelectSingleNode(FieldName,
            nsManager).InnerText = FieldValue;

            // Save the bytes of the XML document as the contents
            // of the SPFile object that represents the InfoPath form
            file.SaveBinary(Encoding.UTF8.GetBytes(modifyEmpXMlDoc.OuterXml));

            // Save the changes made to the SPFile object
            file.Update();
        }
        catch (Exception ex)
        {

        }
    }

Thanks, Amjad

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜