imjamesw
asked on
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,Tr ue,False,F alse,False ,False,"Vi ew",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(l inkdoc,1)
'POLINK= prdoc.FieldGetText( linkdoc )
PRNumber = prdoc.PRNumber(0)
Set dc = poview.GetAllDocumentsByKe y(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(prd oc)
Loop
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,Tr
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(l
'POLINK= prdoc.FieldGetText( linkdoc )
PRNumber = prdoc.PRNumber(0)
Set dc = poview.GetAllDocumentsByKe
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(prd
Loop
ASKER
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Type mismatch on
linkValue = PR.getItemValue("PO_Link" & index)
linkValue = PR.getItemValue("PO_Link" & index)
ASKER
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(linkV alue)
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
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(linkV
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
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.
> 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.
ASKER
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(linkV alue)
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(prd oc)
Loop
End Sub
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)
If linkValue <> ""Then
On Error Resume Next
Set podoc = db.getDocumentByUNID(linkV
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(prd
Loop
End Sub
Dim index As Integer, POLinks(1 To 10) As String
For index = LBound(POLinks) To UBound(POLinks)
POLinks(index) = doc.getItemValue("PO_Link"
Next