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