locked
version history in infopath form RRS feed

  • Question

  • Hi,
    Am working on infopath 2007 for the workflow. I have couple of questions on developing infopth form,
    I need to make some of the infopath fields readonly once they fill the data and submit at first time. And ...How to get version history of specific infopth form field? Any help would be appreciated. Thanks.
    Friday, February 26, 2010 7:11 PM

Answers

  • Hi Bob,
    Thanks for your quick reply. I htink rules means I need to enable digital signatures??. and I am new to this environment. Is there any way to keep my data in sharepoint instead version history i.e. report generation or?? which is the best and easy option for me to do this?. Thanks.

    You can use SharePoint’s built-in version history to track changes. Though it’s not specifically for individual fields it is for overall form. As the data submitted by InfoPath to SharePoint is an XML document, there is no functionality in SharePoint to do a Text difference inside the files. So you need to do the following in order to track the history for columns in more readable and user friendly manner without using any code

    1. Make sure that the InfoPath form is submitted to any custom forms library of your choice.
    2. While submitting the form, make sure that you are promoting the columns for which you want to view/track the version history
    3. Now once the form library is created with columns you want to track, add a new calculated column for each promoted column. E.g. if form has “col1” which is promoted to SharePoint then create a calculated column called “col1_version” and click on column “col1” from the list box “Insert Columns:” into “Formula:” box. Do this for each promoted column. So if you have 10 promoted column then you will have to create 10 calculated columns.
    4. Now fill up the form and submit to this library.
    5. Go to the library and click on the newly created form which will open it in edit mode and make some modifications to columns which are promoted and tracked, after editing submit it back to the library.
    6. Now if you pull down the context menu for the file which you just changed select “Version History” and you can see list of filed which were changed during each version.


    You don't the columns to be in your default view for this to work. So you can remove them your default view.

    This is the closes we can get without using a single line of code keeping it simple and small… (KISS)

     


    Sameer Dhoot
    My Blog : http://sharemypoint.in/
    Friday, February 26, 2010 11:35 PM

All replies

  • Use rules to lock a field once it contains data.
    For versioning a field:  I rolled my own, as getting from the API would be dodgy at best.  My approach:
    1. Create a change log in the schema
    2. Write some a generic function to add to the log
    3. For fields of interest, use the changed event to capture changes to the log via the function you wrote.
    Schema:
    .c9Y6TC { color:#0000ff; } .cLUY2 { color:#ea8f0f; }     < Activity >
    .c9Y6TC { color:#0000ff; } .cLUY2 { color:#ea8f0f; } .c18YC0 { color:#d00020; } .c5M9S0 { color:#000090; }         < ChangeLog >
                < ChangeItem >
                    < ActivityId/ >
                    < Activity_Date xsi:nil= "true"
                                   xsi:type=
    "dateTime" / >
                    < ActUserId/ >
                    < XPath/ >
                    < NewValue/ >
                    < OldValue/ >
                    < OldParent/ >
                    < Operation/ >
                    < isUndoRedo/ >
                    < ItemXML/ >
                    < Status/ >
                    < StatusUserId/ >
                    < StatusDate xsi:nil= "true"
                                xsi:type=
    "dateTime" / >
                < /ChangeItem >
                < ChangeItem/ >
            < /ChangeLog >
    .c9Y6TC { color:#0000ff; } .cLUY2 { color:#ea8f0f; }     < /Activity >

    code
            Public Function of_AddChangelogRow(ByRef sender As Object, ByRef e As XmlEventArgs, Optional ByVal ab_SkipIfNew As Boolean = True, Optional ByVal as_Mode As String = "Prepend") As Integer
    ' log writer code for InfoPath Changelog by chauvinr 2008
                Dim ll_RC As Integer = 1

                Try

                    Dim mainDomNavigator As XPathNavigator = MainDataSource.CreateNavigator()
                    Dim dtTodayDate As String = System.DateTime.Now.ToString("YYYY-MM-DDThh:mm:ss") ' date only("yyyy-MM-dd")

                    If Me.[New] And ab_SkipIfNew Then Return -1

                    'Dim xnNodeTemplate As String 'XPathNavigator


                    'xnNode = Me.Template.Manifest.SelectSingleNode("//xsf:xDocumentClass/xsf:views/xsf:view/xsf:editing/xsf:xmlToEdit[@name='ChangeItem_63']/xsf:editWith/xsf:fragmentToInsert/xsf:chooseFragment/Activity/ChangeLog/ChangeItem", Me.NamespaceManager)
                    If _ChangelogTemplate = "" Then
                        ' If you get an object error, the value of xsf:xmlToEdit[@name='ChangeItem_3050' is probably not matching to the form.  Go to the view with the repeating section and get the ==> Properties/Advanced-Code xmlToEdit for XCollection property value.
                        _ChangelogTemplate = Me.Template.Manifest.SelectSingleNode("//xsf:xDocumentClass/xsf:views/xsf:view/xsf:editing/xsf:xmlToEdit[@name='ChangeItem_3078']/xsf:editWith/xsf:fragmentToInsert/xsf:chooseFragment/Activity/ChangeLog/ChangeItem", Me.NamespaceManager).OuterXml
                    End If
                    If as_Mode.ToLower = "prepend" Then
                        mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog", Me.NamespaceManager).PrependChild(_ChangelogTemplate) '.InnerXml)
                    Else
                        mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog", Me.NamespaceManager).AppendChild(_ChangelogTemplate) '.InnerXml)
                    End If

                    'mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog/ChangeItem/ActUserId", NamespaceManager).SetValue(Me.Application.User.UserName)
                    'mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog/ChangeItem/Activity_Date", NamespaceManager).SetValue(dtTodayDate)
                    mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog/ChangeItem/XPath", NamespaceManager).SetValue(e.Site.Name)
                    mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog/ChangeItem/NewValue", NamespaceManager).SetValue(e.NewValue)
                    mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog/ChangeItem/OldValue", NamespaceManager).SetValue(e.OldValue)
                    mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog/ChangeItem/Operation", NamespaceManager).SetValue(e.Operation)
                    mainDomNavigator.SelectSingleNode("/myFields/Activity/ChangeLog/ChangeItem/isUndoRedo", NamespaceManager).SetValue(e.UndoRedo)

                    '/myFields/Activity/ChangeLog/Operation
                    ll_RC = 1 ' indicate success

                Catch ex As Exception
                    ll_RC = -1
                End Try


                Return ll_RC

            End Function
    /bac
    Friday, February 26, 2010 7:39 PM
  • Hi Bob,
    Thanks for your quick reply. I htink rules means I need to enable digital signatures??. and I am new to this environment. Is there any way to keep my data in sharepoint instead version history i.e. report generation or?? which is the best and easy option for me to do this?. Thanks.
    Friday, February 26, 2010 9:22 PM
  • Hi Bob,
    Thanks for your quick reply. I htink rules means I need to enable digital signatures??. and I am new to this environment. Is there any way to keep my data in sharepoint instead version history i.e. report generation or?? which is the best and easy option for me to do this?. Thanks.

    You can use SharePoint’s built-in version history to track changes. Though it’s not specifically for individual fields it is for overall form. As the data submitted by InfoPath to SharePoint is an XML document, there is no functionality in SharePoint to do a Text difference inside the files. So you need to do the following in order to track the history for columns in more readable and user friendly manner without using any code

    1. Make sure that the InfoPath form is submitted to any custom forms library of your choice.
    2. While submitting the form, make sure that you are promoting the columns for which you want to view/track the version history
    3. Now once the form library is created with columns you want to track, add a new calculated column for each promoted column. E.g. if form has “col1” which is promoted to SharePoint then create a calculated column called “col1_version” and click on column “col1” from the list box “Insert Columns:” into “Formula:” box. Do this for each promoted column. So if you have 10 promoted column then you will have to create 10 calculated columns.
    4. Now fill up the form and submit to this library.
    5. Go to the library and click on the newly created form which will open it in edit mode and make some modifications to columns which are promoted and tracked, after editing submit it back to the library.
    6. Now if you pull down the context menu for the file which you just changed select “Version History” and you can see list of filed which were changed during each version.


    You don't the columns to be in your default view for this to work. So you can remove them your default view.

    This is the closes we can get without using a single line of code keeping it simple and small… (KISS)

     


    Sameer Dhoot
    My Blog : http://sharemypoint.in/
    Friday, February 26, 2010 11:35 PM
  • Rules  are not the same as Digital Sigs.  See this link re rules http://blogs.msdn.com/infopath/archive/2006/05/17/best-practices-for-rules.aspx.

    The problem you will face with your version history requirement is that the built in version history is somewhat limited, especially for items in repeating groups and reporting.  That's why I suggest the coded solution above which will allow you to track item changes in the form itself.

    My best advice is to do more google searching on the topic.  Coding in IP is rather simple compared to other environments. 
    /bac
    Monday, March 1, 2010 1:39 PM
  • Thanks sameer. It is working.
    Friday, March 5, 2010 7:43 PM
  • Sameer,
    Can you please explain how can I made editable field to specific user after the form submitton. I mean how to lock once submitted and how to unlock to specific user. Am trying to set up rules but not working. Any help would be appreciated. Thanks.
    Friday, March 5, 2010 7:46 PM
  • Sameer,
    Can you please explain how can I made editable field to specific user after the form submitton. I mean how to lock once submitted and how to unlock to specific user. Am trying to set up rules but not working. Any help would be appreciated. Thanks.

    I am glad that the solution worked for you.

    I am not clear on what you want to accomplish here. You can always create a column in Document Library which can be of People/Person type where you can enter the user name.

    I am not sure what to mean by lock and unlock specific user. If you mean that you want the ability where the fields can be editable/read-only based on user who is logged in, then this is not possible OOB but can be accomplished using editing the EditForm.aspx page in SPD. You can drop a Content Editor Web Part and have a custom JavaScript which will hide the fields or make fields read-only based on users who is logged in.

    If you can be more specific on what you want then i can help.

    Thanks,


    Sameer Dhoot
    My Blog : http://sharemypoint.in/
    Saturday, March 6, 2010 12:55 AM
  • I don't think i tmakes sense to give them a warning AFTER they try to edit a field.  Instead, send all unauthorized users to a read-only vew - that should be very simple.

    1) Create a new view
    2) Copy all relevant controls to the new view
    3) Go to that view's properties and set it to Read-Only
    4) Create a Form Load rule (Tools > Form Options > Open & Save > Rules) that compares the current user's identity (userame() function) against a known set of usernames stored the form.  If you need to compare group membership, then use this method: InfoPath - User Roles in Browser-Enabled Forms Using AD Groups.  If this is not a browser form, then simply use the built-in user Roles, which requires no effort.
    SharePoint Architect || My Blog
    Wednesday, March 17, 2010 1:35 AM
  • thanks for your quick reply...can you provide some step by step SharePoint Object Model resources??

    No, I am not a developer, sorry.
    SharePoint Architect || My Blog
    Wednesday, March 17, 2010 4:55 AM
  • Thanks Sameer.  This worked for me too.  I was looking for a way to track changes on fields of an InfoPath form. The only problem I faced with this method is that rich text field values would not appear in version history, only plain text field values would show up.  To work around this problem, I created a hidden plain text field in the form, adding a function to map the values from the rich text field to it, then I promoted the plain text field. 

    In my case I didn't need the formatting from the rich text field to be available in the SharePoint list so this worked out. 


    dms
    Friday, July 1, 2011 9:22 PM