Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

Find PO associated with PR and set value in PR

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
imjamesw
Asked:
imjamesw
  • 5
  • 3
1 Solution
 
qwaleteeCommented:
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
 
imjameswAuthor Commented:
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
 
imjameswAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
qwaleteeCommented:
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
 
imjameswAuthor Commented:
Type mismatch on

 linkValue = PR.getItemValue("PO_Link" & index)
0
 
imjameswAuthor Commented:
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
 
qwaleteeCommented:
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
 
imjameswAuthor Commented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now