You are viewing limited content. For full access, please sign in.

Question

Question

Dynamic Fields in Repository Access

SDK
asked on May 26, 2016 Show version history

Are there any code samples illustrating how to retrieve allowed values for dynamic fields, using Repository Access? Below code we can use with LFSO to list the dynamic fields with their allowed values, based on existing values, and we would like to know how to do the same with Repository Access but are having difficulty determining the correct syntax:

  Sub GetDynamicFieldState()
    Try
      Dim app As LFApplication = New LFApplication
      Dim serv As LFServer = app.GetServerByName("127.0.0.1")
      Dim db As LFDatabase = serv.GetDatabaseByName("xxxx")
      Dim conn As New LFConnection

      conn.UserName = ""
      conn.Password = ""
      conn.Create(db)

      Try
        ' Get Dynamic Field info for specified template details
        Dim template As LFTemplate = db.GetTemplateByName("Members 2")

        If (template.HasFormLogicRules) Then ' Don't try to retrieve dynamic fields if none exist.

          ' Create template with field values in memory to pass to LFSO
          Dim fieldData As New LFFieldData()
          fieldData.Template = template
          fieldData.Field("Doc Type") = "Photo Id"

          For Each dynamicField As LFFormLogicRule In template.GetAllFieldFormLogicRules()
            Try
              Dim q As LFQuery = dynamicField.GetQuery(fieldData)
              Dim queryresult As LFQueryResult = q.GetResult()

              Console.WriteLine(dynamicField.TemplateFieldID & " values:")
              While (queryresult.Next())
                Dim col As LFQueryColumn = queryresult.GetColumnByIndex(1)  ' Only 1 column in result set
                Console.WriteLine("  " & col.String.Trim())
              End While
            Catch ex As Exception
              ' LF9 seems to throw SQL errors if parent field has no selected value.
              If Not ex.Message.ToLower().Contains("sql") Then Throw ex
            End Try
          Next
        End If

      Catch ex As Exception
        Throw New Exception("Error looking up dynamic fields: " & ex.Message)
      End Try

      conn.Terminate()

    Catch ex As Exception
      Console.WriteLine(ex.Message)
    End Try
  End Sub

 

0 0

Answer

SELECTED ANSWER
replied on May 27, 2016

Looks like this provides the same results in RepositoryAccess:


  Sub GetDynamicFieldState()
    Try
      Dim serv As New Server("127.0.0.1")
      Dim rep As New RepositoryRegistration(serv, "xxxx")
      Dim session As New Session()

      session.CanShareLicense = True
      session.LogIn(rep)

      Try
        ' Get Dynamic Field info for specified template details
        Dim template As TemplateInfo = Laserfiche.RepositoryAccess.Template.GetInfo("Members 2", session)

        If (template.HasFormLogicRules) Then ' Don't try to retrieve dynamic fields if none exist.

          ' Create template with field values in memory to pass to LFSO
          Dim fieldColl As New FieldValueCollection()

          fieldColl.Add("Doc Type", "Photo Id")

          For Each dynamicField As FormLogicRuleInfo In template.GetFormLogicRules()
            Try
              Dim queryresult As Laserfiche.RepositoryAccess.Data.LfDataReader = dynamicField.GetDataReader(fieldColl)

              Console.WriteLine(dynamicField.FieldId & " values:")

              While (queryresult.Read())
                Console.WriteLine("  " & queryresult.Item(0).ToString().Trim())  ' Only 1 column in result set
              End While
            Catch ex As Exception
              ' LF9 seems to throw SQL errors if parent field has no selected value.
              If Not ex.Message.ToLower().Contains("sql") Then Throw ex
            End Try
          Next
        End If

      Catch ex As Exception
        Throw New Exception("Error looking up dynamic fields: " & ex.Message)
      End Try

      session.Close()

    Catch ex As Exception
      Console.WriteLine(ex.Message)
    End Try
  End Sub

 

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.