Solved

Find PO associated with PR and set value in PR

Posted on 2004-08-31
8
357 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

838 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