Archivo

Archive for the ‘InfoPath’ Category

Quitar todas las validaciones del formulario

 

Es posible que alguna vez queramos quitar de una todas las validaciones y errores de un formulario antes de enviarlo.

 

Para esto solo tenemos que eliminar los errores del contenedor de errores del formulario.

 

En mi caso si se cumplía la condición de que es un borrador el formulario se envía sin tener en cuenta los errores

 

‘Si es un borrador eliminamos los errores.

    If esBorrador Then

          Me.Errors.DeleteAll()

    End If

‘Enviamos el formulario a la biblioteca de Sharepoint.

    Me.DataConnections.Item("Envío de biblioteca de SharePoint").Execute()

 

 

Saludos.

Categorías: InfoPath

Cambiar de vista default en el evento Load

A veces nos interesa cambiar de vista default en el evento Load, dependiendo además de alguna variable.

Aquí va como hacerlo.

 

Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs)

 

 Dim navigator As XPathNavigator = Me.MainDataSource.CreateNavigator()

 Dim valorEstado As String = navigator.SelectSingleNode("/my:misCampos/my:Estado",NamespaceManager).Value

 If valorEstado = "4" Then

     e.SetDefaultView("NombreVista")

 End If

End Sub

 

Saludos.

Categorías: InfoPath

Agregar datos a una tabla de repetición accediendo a datos de una lista de Sharpoint

A veces queremos tener una lista dinamica en el formulario Infopath. Para ello se ha de tener la lista creada con los campos que quieras mostrar.

1.- Agregar la conexion de la lista de sharepoint a la cual quieres acceder.

2.- Agregar un grupo de repetición con los elementos que sean necesarios.

3.- Añadir el codigo en el evento que consideres necesario

 

En mi caso lo he puesto en el evento Load del infopath.

 

Dim navigator As XPathNavigator = Me.MainDataSource.CreateNavigator()

Dim rows As XPathNodeIterator = navigator.Select("/my:misCampos/my:Tabla", NamespaceManager)

Dim row As XPathNavigator = Me.MainDataSource.CreateNavigator().SelectSingleNode("/my:misCampos/my:Tabla[" + rows.Count.ToString + "]", NamespaceManager)

Dim newrow As XPathNavigator = row.Clone()

Dim primera As Boolean = True

 

‘Mi lista se llamaba Material al igual que la conexión

Dim navigatorMaterial As XPathNavigator = Me.DataSources("Material").CreateNavigator

Dim rowsMaterial As XPathNodeIterator = navigatorMaterial.Select("/dfs:myFields/dfs:dataFields/dfs:Material/@Títol", NamespaceManager)

 

For Each obj As Object In rowsMaterial

If Not primera Then

row.InsertAfter(newrow)

End If

newrow.SelectSingleNode("my:Nombre",NamespaceManager).SetValue(obj.ToString)

primera = False

Next

 

Resultado: se cargara la tabla de repetición con los datos de la lista. En mi caso la conexión solo tenia un campo "Title" de la lista que agrego a la tabla de repetición en el campo nombre del infopath.

Categorías: InfoPath

Submit and Close form infopath

  1. Set the Submit Option to "Perform custion action via Code", and set the Advanced "After Submit" property to "Close the Form"
  2. Code the FormEvents_Submit .  For the submit to the form library to work you need to use the FileSubmitConnection related code.

Public Sub FormEvents_Submit(ByVal sender As Object, ByVal e As SubmitEventArgs)
            ‘ If the submit operation is successful, set e.CancelableArgs.Cancel = False
            ‘ Write your code here.
            Dim lb_Success As Boolean = False
            Dim fc As FileSubmitConnection
            Try
                ‘Me.of_SomePreSaveFunction()
                fc = DirectCast(Me.DataConnections("SharePoint Library Submit"), FileSubmitConnection)
                fc.Execute()

                e.CancelableArgs.Cancel = False ‘success
                lb_Success = True
            Catch ex As Exception
                e.CancelableArgs.Cancel = True ‘Error
                ‘of_ErrorMessageFunction("Error Submiting the form – FC Execute Error: " + ex.Message, False)

            End Try

            If lb_Success Then
                ‘ any other non-critical processing
                ‘of_SomeCleanupFunction()
            End If

            fc = Nothing

        End Sub

 

3. Finally, add a button with the Action property set to Submit, which will use your code.

Categorías: InfoPath

Contact Selector

 

Using the Contact Selector Control

http://blogs.msdn.com/infopath/archive/2007/02/28/using-the-contact-selector-control.aspx

We have seen a number of requests on how to allow a user to enter (or select) a person’s name or logon alias and then validate that user against their Active Directory without using code. This has been especially true in workflow scenarios where User A needs to enter in the name of User B – the next person in the workflow process.

Well, InfoPath 2007 ships with a control called Contact Selector Control that will resolve these issues! You may have seen our older article on the subject; this one aims to dive in deeper.

The Contact Selector control is an ActiveX control but it is a special cased control, in that it can also be used in InfoPath browser forms. To use this control there are specific steps that need to be taken – let’s take a look at those now.


Step 1: Add the Contact Selector control to your Controls Task Pane

1) From the Controls Task Pane click the Add or Remove Custom Controls link

2) Click the Add button

3) On the first screen of the Add Custom Control Wizard select ActiveX control and click Next

4) From the list of controls, choose Contact Selector and click Next

5) Select “Don’t include a .cab file” and click Next

6) For Binding Property select Value and click Next

7) From the Field or group type box choose Field or group (any data type) and click Finish

8) Click Close and then click OK

 

Step 2: Create the data structure for the Contact Selector Control

The Contact Selector control needs to have a specific data structure to work properly – this is documented on the “Items” tab of the Properties screen for the control; however, we’ll include that information here as well.

**IMPORTANT!** Spelling and capitalization must be exactly the same, starting with the “Person” group!

1) Add a non-Repeating Group named: gpContactSelector

2) Add a Repeating Group named: Person

3) Add the following 3 text fields to the Person group: DisplayName, AccountId and AccountType

Step 3: Add and bind the Contact Selector control to the View

1) Drag the gpContactSelector Group to the View and select “Contact Selector” from the list of controls

2) You’re almost done…! 🙂

Step 4: Add a secondary data source XML file which specifies the SharePoint server

The Contact Selector control needs to know the “context” of where the user validation should occur. These steps are not necessary if you are only displaying the form in a browser from SharePoint – in this case, it uses the context of the site from where it was provisioned; however, if you are in a mixed client/browser scenario you will need to include this XML file so forms opened in the client can use this functionality.

1) Launch Notepad

2) Copy and paste this one-line XML:

<Context siteUrl="http://<servername>"/&gt;

**NOTE: Replace <servername> with the name of your server

3) Save this as: Context.xml (again – naming and capitalization are important)

4) Add Context.xml as a “Receive” type Secondary Data Connection to your form template and make sure the option “Include the data as a resource file” is enabled

Step 5: Test!

You should now be able to Preview the form, enter a name or logon alias, click the “Check Names” button and resolve the name! Alternatively you could click the “To” button to perform a Search if you do not know the complete name of the user.

One other important point: if this control is something you will use numerous times, this process works great to create a “Contact Selector Template Part” – then you only have to complete these steps one time!

Categorías: InfoPath