Solved

Find PO associated with PR and set value in PR

Posted on 2004-08-31
8
359 Views
Last Modified: 2013-12-18
Hi guys


I am having a little problem trying to script this

THere is a form PR that contains ten fields
PO_Link1 >PO_Link10

The fields contain the UNID of a document PO

Currently they use the UNID's however we would like to use the asscociated PO numbers
I would like to replace the UNID value in the PO_Link fields with the PO number
The following is an agent that is run manually

Iam sure this can be done with
Dim POLinks(0-9) as string

 POLinks(0) = prdoc.polink1(0)

POLinks(1) = prdoc.polink2(0) etcc..


not sure how to cycle thru the fields

I am using Cases to select which of the ten fields i wish to search fo a matching UNID
Dim W As New Notesuiworkspace
      Dim s As New notesSession
      Dim db As notesDatabase
      Set db = s.currentDatabase
      Dim poview As notesView
      Dim prview As notesView
      Dim dc As NotesDocumentCollection
      Set poview = db.getView("POUNID")
      Set prview = db.getView("PRCPR")
      Set uidoc = w.currentdocument
      Dim podoc As notesDocument
      Dim prdoc As notesDocument
      Set prdoc = prview.getFirstDOcument
      
      J=0
      Set  doc3 = New NotesDocument(db)
      ret =  w.DialogBox("FVPR",True,True,False,False,False,False,"View",doc3)
      If ret Then    
            AccKey = doc3.Number1(0)
            If AccKey = "" Then
                  Messagebox "You must select a number"
                  Exit Sub
            End If
      Else
            Print "View halted"
            Exit Sub
      End If
     '******    
      J=AccKey
      Select Case AccKey
      Case 1
            linkdoc = prdoc.po_link1(0)
      Case 2
            linkdoc = prdoc.po_link2(0)
      Case 3
            linkdoc = prdoc.po_link3(0)
      Case 4
            linkdoc = prdoc.po_link4(0)
      Case 5
            linkdoc = prdoc.po_link5(0)
      Case 6
            linkdoc = prdoc.po_link6(0)
      Case 7
            linkdoc = prdoc.po_link7(0)
      Case 8
            linkdoc = prdoc.po_link8(0)
      Case 9
            linkdoc =prdoc.po_link9(0)
      Case 10
            linkdoc = prdoc.po_link10(0)
            
      End Select
      
      Do Until prdoc Is Nothing
            
            'Set podoc =poview.GetDocumentByKey(linkdoc,1)
      'POLINK= prdoc.FieldGetText( linkdoc )
            PRNumber = prdoc.PRNumber(0)
            Set dc = poview.GetAllDocumentsByKey(linkdoc, True)
            
            If dc Is Nothing Then
                  'Print "No matches for " & PRUNID          
            'Elseif dc.count < 1 Then
            '      Print "No matches for " & PRUNID      
            'Else
                  Call dc.StampAll("POUNID", PRNumber)
            End If
            Set prdoc = prview.getNextDocument(prdoc)
            
      Loop
      
0
Comment
Question by:imjamesw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 31

Expert Comment

by:qwaletee
ID: 11943658
Not really sure what you are trying to do.  The following will loop through all ten fields and get their string values into an array:

Dim index As Integer, POLinks(1 To 10) As String
For index = LBound(POLinks) To UBound(POLinks)
    POLinks(index) = doc.getItemValue("PO_Link" & index)
Next
0
 

Author Comment

by:imjamesw
ID: 11943682
All I want to do really is find the POs that are aasociated with a PR and the replace the value(unid) withe a PO number

0
 

Author Comment

by:imjamesw
ID: 11943950
So

Go to aview(GPR) and get the first document(PR)
Get the values of the the po_link fields(UNIDS)

Go to aview(POUNID) find the matching UNID and PO Number
Replace the value of the  PR_Link? with the correct PO NUmber save

Next
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Accepted Solution

by:
qwaletee earned 500 total points
ID: 11945197
Fourth line is still a little unclear.  Which doc are you changing -- the PO (reteieved in step 3), or the PR (retrieved in step 1)?

You don't need a view for the third step... you can use getDocumentByUNID.

I would think the code would be:


Dim s as new notesSession
Dim db as notesDatabase
Set db = s.curentDatabase
Dim PRs as notesView
Set PRs = db.getView("GPR")
PRs.autoRefresh=false
Dim PR as notesdocument
Set PR = PRs.getFirstDOcument
Dim PO as notesDocument, index as integer, linkValue as string, changeFlag
Do until PR is nothing
    changeFlag = false
    For index = 1 to 10
        linkValue = PR.getItemValue("PO_Link" & index)
        If linkValue <> "" Then
            On Error resume next
            Set PO = db.getDocumentByUNID(linkValue)
            If err <> 0 then
                err = 0
            Else
                'OK, we have work to do!
                changeFlag = True
                PR.replaceItemValue "PO_Number" & index , PO.PONumber(0)
            End If
        End If
    Next
    Set PR = PRs.getNextDocument(PR)
Loop
0
 

Author Comment

by:imjamesw
ID: 11945301
Type mismatch on

 linkValue = PR.getItemValue("PO_Link" & index)
0
 

Author Comment

by:imjamesw
ID: 11945905
I got passed the above error

I am getting type mismatch on
      
If linkValue <> "" Then



Do Until prdoc Is Nothing
            For index = 1 To 10
                  POLINK ="po_link" & index
                  linkValue =   prdoc.getItemValue(POLINK)
                  
                  If linkValue <> "" Then
                        On Error Resume Next
                        Set PO = db.getDocumentByUNID(linkValue)
                        If Err <> 0 Then
                              Err = 0
                        Else
                'OK, we have work to do!
                              changeFlag = True
                              PR.replaceItemValue "PO_Number" & index , PO.PONumber(0)
                        End If
                  End If
            Next
            Set PR = PRs.getNextDocument(PR)
      Loop
End Sub
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 11945960
qwaletee,
>         linkValue = PR.getItemValue("PO_Link" & index)
>         If linkValue <> "" Then



Oops!

        linkValue = PR.getItemValue("PO_Link" & index)(0) '<--- forgot this
        If linkValue <> "" Then
 
Your problem with the IF LINKVALUE may be because, if you fixed the first problem by changing linkValue from string to variant, thrn linkValue is now an array instead of a string.  Fixing it like I did here, by appending "(0)" after the getItemValue, should fix both problems.
0
 

Author Comment

by:imjamesw
ID: 11946963
HI

Thanx a bunch

I fiddled with what you gave me a it worked Here it is

Dim s As New notesSession
      Dim db As notesDatabase
      Set db = s.currentDatabase
      Dim poview As notesView
      Dim prview As notesView
      Set poview = db.getView("POUNID")
      Set prview = db.getView("GPR")
      Dim podoc As notesDocument
      Dim prdoc As notesDocument
      Dim index As Integer
      Dim linkValue As String
      Dim changeFlag As String
      Set prdoc = prview.getLastDocument
      
      
      
      Do Until prdoc Is Nothing
            PRNumber = prdoc.PRNUMBER(0)
            For index = 1 To 10
                  POLINK ="po_link" & index
                  linkValue =   prdoc.getItemValue(POLINK)(0)
                  
                  If linkValue <> ""Then
                        On Error Resume Next
                        Set podoc = db.getDocumentByUNID(linkValue)
                        If Err <> 0 Then
                              Err = 0
                        Else
                'OK, we have work to do!
                              changeFlag = True
                              prdoc.replaceItemValue "po_link" & index , podoc.ponum(0)
                        End If
                  End If
            Next
            Call prdoc.save(False,False)
            Set prdoc =  prview.getPrevDocument(prdoc)
      Loop
End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question