Solved

Find PO associated with PR and set value in PR

Posted on 2004-08-31
8
354 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now