Profile Doc Read Fields

I thought this problem was solved, but it's back and more of a problem.

I have multiple fields on the profile doc :

fldnameApprvAS
fldnameByupApprvAS
fldnameDoerAS            are 3 of them. To extract the value of these fields I pass the

value "AS" to the below function to 3 variables. "AS" is passed to this function in "stName".This, in theory, gives me the before mentioned three field names I need. I need to read these field names and get the text data stored in the field. Instead the value I get are the names of the fields.

I should mention I need to extract the field values, not override them.

Help.... The function code follows:

      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim prfdoc As NotesDocument
      Dim fldnameApprv As String
      Dim fldnameBkupApprv As String
      Dim fldnameDoer As String
      Set db = session.CurrentDatabase
      Set prfdoc = db.GetProfileDocument("frmProfile")
      fldnameApprv = "fldPrflAppvr" +  (stName)
      fldnameBkupApprv = "fldPrflBkupAppv" + (stName)
      fldnameDoer = "fldPrflDoer" + (stName)
      If prfdoc.getItem(fldnameApprv)(0)<> "" Then
            getProfile = prfdoc.getItemvalue(fldnameApprv)
      Else
            If prfdoc.getItemValue(fldnameBkupApprv)(0)<> "" Then
                  getProfile = prfdoc.getItemvalue(fldnameBkupApprv)
            Else
                  If prfdoc.getItemValue(fldnameDoer)(0) <> "" Then
                        getProfile = prfdoc.getItemvalue(fldnameDoer)
                  End If
            End If
      End If      
      
End Function

bobdrazAsked:
Who is Participating?
 
HemanthaKumarConnect With a Mentor Commented:
I believe you have to refine the function to return a variant/array of three values ...

          getProfile = prfdoc.getItemvalue(fldnameApprv)
          getProfile = ArrayAppend(getProfile, prfdoc.getItemvalue(fldnameBkupApprv))
          getProfile = ArrayAppend(getProfile, prfdoc.getItemvalue(fldnameDoer))

And the function should be declared to return variant

i.e. function getProfile as variant

And later loop thru the return value for any nulls and disregard.
 
0
 
HemanthaKumarCommented:
You could aswell continued on previous question and clarified it with the expert.

Anyway

Here you go..

     If prfdoc.getItem(fldnameApprv)(0)<> "" Then
          getProfile = prfdoc.getItemvalue(fldnameApprv)(0)
     Else
          If prfdoc.getItemValue(fldnameBkupApprv)(0)<> "" Then
               getProfile = prfdoc.getItemvalue(fldnameBkupApprv)(0)
          Else
               If prfdoc.getItemValue(fldnameDoer)(0) <> "" Then
                    getProfile = prfdoc.getItemvalue(fldnameDoer)(0)
               End If
          End If
     End If    

I just added index 0 to the getitemvalue function .. so that it will get the first value of the field

~Hemanth
0
 
bobdrazAuthor Commented:
I did add the index O and declared the function as varient and ran a another test with the degugger. It seems to fall through the nested If statement as if each field on the profile doc was null. I verified the fields on the profile doc are populated with names. I use these names for email purposes. I access this function from another function with the code:
                               
            If x <> "" Then
                  apr(k) = x
                  k = k + 1
                  aprname = getProfile(x)

In the debugger when I return to this fuction, aprname is still set to null. My code just doesn't seem to read the profile doc fields. - Help
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
HemanthaKumarCommented:
There is a problem in your first if condition.. it is not getItem, it should be getitemvalue
0
 
bobdrazAuthor Commented:
I fixed the if condition to getItemvalue, but it still doesn't work. In the first if condition:

If prfdoc.getItem(fldnameApprv)(0)<> "" Then
          getProfile = prfdoc.getItemvalue(fldnameApprv)(0)


The string fldnameApprv contants the profile doc field name "fldPrflApprvAS"
The value "AS" was passed from the prior function.

In this function the string is build to contain the name of the field on the profile doc I want to get the value from.

 fldnameApprv = "fldPrflAppvr" +  (stName)

I put the string into:

If prfdoc.getItem(fldnameApprv)(0)<> "" Then
          getProfile = prfdoc.getItemvalue(fldnameApprv)(0)

I want the value of the profile doc field returned in "getProfile" to the prior function. It does not appear I am getting to the profile doc field..... Help
0
 
HemanthaKumarCommented:
Again it is not getitem...

Check this line...If prfdoc.getItem(fldnameApprv)(0)<> "" Then

It should be If prfdoc.getItemVALUE(fldnameApprv)(0)<> "" Then
0
 
bobdrazAuthor Commented:
I apologize. I did fix the code as you instructed. I copied it back here incorrectly. Here's the actual code I just ran and I still can't get it to work. - help

Function getProfile (stName) As Variant
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Dim fldnameApprv As String
      Dim fldnameBkupApprv As String
      Dim fldnameDoer As String
      Dim doer As NotesItem
      Set s = New NotesSession
      Set db = s.CurrentDatabase
      Set doc = db.GetProfileDocument("frmProfile")
      fldnameApprv = "fldPrflAppvr" +  (stName)
      fldnameBkupApprv = "fldPrflBkupAppv" + (stName)
      fldnameDoer = "fldPrflDoer" + (stName)
      
      If doc.GetItemValue(fldnameApprv)(0) = "" Then
      getProfile = doc.GetItemValue(fldnameApprv)(0)
      Else
      If doc.GetItemValue(fldnameBkupApprv)(0)<> "" Then
            getProfile = doc.GetItemValue(fldnameBkupApprv)(0)
      Else
            If doc.GetItemValue(fldnameDoer)(0) <> "" Then
                  getProfile = doc.GetItemValue(fldnameDoer)(0)
                  End If
            End If
      End If      
      End Function
0
 
HemanthaKumarCommented:
Still you have got problem in this line...If doc.GetItemValue(fldnameApprv)(0) = "" Then

Should it be = or <> ?
0
 
bobdrazAuthor Commented:
The line

If doc.GetItemValue(fldnameApprv)(0) = "" 

was changed to an equal condition for a test. The result was the same.
0
 
bobdrazAuthor Commented:
It should be <>. I was running a test.
0
 
bobdrazAuthor Commented:
Could it be how I'm referencing the field names in the GetItemValue. For example; one of the fields on the profile doc is "fldPrflAppvrAS". I derive this value in the folling string:  

fldnameApprv = "fldPrflAppvr" +  (stName)

And the use it:

If doc.GetItemValue(fldnameApprv)(0) = "" Then
     getProfile = doc.GetItemValue(fldnameApprv)(0)

Am I missing a DIM somewhere??
0
 
HemanthaKumarCommented:
There is a little confusion here

you mention the field names int he profile as
fldnameApprvAS
fldnameByupApprvAS
fldnameDoerAS            

And you construct different field names here

     fldnameApprv = "fldPrflAppvr" +  (stName)     .... Effective field name is - fldPrflApprvAS
     fldnameBkupApprv = "fldPrflBkupAppv" + (stName)     .... Effective field name is - fldprflBkuppvAS
     fldnameDoer = "fldPrflDoer" + (stName)     .... Effective field name is - fldPrflDoerAS


So what is the actual field name in profile ???

If you are not sure what you are getting.. then I suggest u to debug and inspect the profile doc field items !!
0
 
bobdrazAuthor Commented:
I apologize for the confusion. This should help. I'll restrict this to just 3 of the profile doc fields.

Profile Doc - field names are fldPrflAppvrAS, fldPrflBkupAppvAS and fldPrflDoerAS.

My first function( which works fine) determins the field names by passing the value "AS" to my getProfile function (described above and not working).

I append the "AS" into the following strings:

   fldnameApprv = "fldPrflAppvr" +  (stName)
   fldnameBkupApprv = "fldPrflBkupApprv" + (stName)
    fldnameDoer = "fldPrflDoer" + (stName)

This strings now hold the actual profile doc field names I need the value from.

    fldPrflAppvrAS
    fldPrflBkupApprvAS
    fldprflDoerAS

So, in the line     If doc.GetItemValue(fldnameApprv)(0) = "" 

(fldnameApprv) is a string with field name of "fldPrflApprvAS" that I wish to get the value of.
0
 
qwaleteeCommented:
Add some print statements so you see what it is doing...

     If doc.GetItemValue(fldnameApprv)(0) <> "" Then
         getProfile = doc.GetItemValue(fldnameApprv)(0)
         Print {Retrieved value '} getProfile {' for } stName " from approver field " fldnameApprv
     ElseIf doc.GetItemValue(fldnameBkupApprv)(0)<> "" Then
         getProfile = doc.GetItemValue(fldnameBkupApprv)(0)
         Print {Retrieved value '} getProfile {' for } stName " from backup field " fldnameBkupApprv " after failing field " fldnameApprv
     ElseIf doc.GetItemValue(fldnameDoer)(0) <> "" Then
         getProfile = doc.GetItemValue(fldnameDoer)(0)
         Print {Retrieved value '} getProfile {' for } stName " from doer field " fldnameDoer " after failing fields " fldnameApprv "," fldnameBkupApprv
     Else
         Print {No values found, should return blank value -> '} getProfile {'}
     End If    


I also restructured it to use elseif instead of nested ifs (same thing but a little cleaner style and faster), and explicitly provide an else for the last condition failing.

So, you shoud now see what the parameter was, what the fldname used, what value returned, and if it went through multiple tests, what the rejected field names were.

You shoud also run this through the debugger, and before it exits, expand doc>Items, and see if the fields you are examining 1) exist, and 2) have values
0
 
bobdrazAuthor Commented:
Thanks for the help. Actually, I have been running this through the debugger and the values do check out OK. I will add the print statements and restructure as you suggest. Again, thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.