Extract specific fields for export

I’m new to LS and could use some help. I need to export some fields from a Response Document. I understand there is not an easy way to show just the responses without the parents in a view, so I’m trying to export just the fields I need instead of the whole view. The first thing I need to ask is how to get the fields from just the response forms only. I’ve included the script I’ve been using that does some of what I need; but I have 10 question fields and 10 corresponding comment fields I need to collect. Question fields are a to j, with comment fields being a_1 to j_1. I’m unsure how to pick them up in the order a, a_1, b, b_1. Help…

Sub Initialize

Set session = New NotesSession

Set db = session.CurrentDatabase

Set coll = db.UnprocessedDocuments

docCt = 0



fileNum% = Freefile()

fileName = "c:\windows\desktop\SurveyResults.txt"



If coll.count = 0 Then

	Msgbox "No documents to process"

	Exit Sub

Elseif coll.count > 1000 Then

	Msgbox "Please limit your selection to 1000 documents or fewer"

	Exit Sub

Else

	Set doc = coll.GetFirstDocument

End If



Open fileName For Output As fileNum%

While Not doc Is Nothing

             Set notesFrom = New NotesName(doc.GetItemValue("From")(0))

	docFrom = notesFrom.Common  'doc.GetItemValue("From")(0)

'Comments is an extra optional field

	dataArr(docCt) = docFrom & "," & doc.Comments

'gather all the field data into an array

 For i = 97 To 106 'lowercase a through j

fieldToGet = Chr(i)

dataArr(docCt) = dataArr(docCt) & "," &_

doc.GetItemValue(fieldToGet & "_1")(0)

		

fieldCt = fieldCt + 1

		

Next



docCt = docCt + 1	

Set doc = coll.GetNextDocument(doc)

Wend



'write all the array data to a file

Forall d In dataArr

’ Print d

	Print #fileNum%, d		

End Forall



Close fileNum%

End Sub

Subject: Extract specific fields for export

Hello,

You can check doc.IsResponse to see if it is a Response document or not. For the rest, I’m sure there’s a better way, but something like this would work.

Open “c:\results.txt” For Output As #1

Then get your documents and test to see if it’s a response doc and get in your loop.

Print #1, Trim$(doc.a(0)) & “,” & Trim$(doc.a_1(0)) & “,” & Trim$(doc.b(0)) & “,” & Trim$(doc.b_1(0)) & “,” & Trim$(doc.c(0)) & “,” & Trim$(doc.c_1(0))

And after getting out of the loop…

Close #1

You may also want to check for things like commas, carriage returns and other things in your comment fields and replace them with something else.

HTH,

  • David

Subject: Extract specific fields for export

It is simple to show only response documents in a view. Just create a new view with the view selection criteria ofSELECT Form = “ResponseFormName”

Then put your export function in this view instead of the view with main and response documents