Help with numbering agent

Posted on 2004-08-19
Last Modified: 2013-12-18
HI Guys

Well  I have inherited another mess

What I would like to do is add a unique number to documents created with the Purchase Requistion form. I will create a new number field PRNumber

This is easy enough to do when new, however there are several already created dox. Part two of this is that there are several dox created with the Purchase Order form that are related to the PR's. They are created by a button on the PR when all approvals have passed. When the PO's are created the pr_link1 is populated with the UNID of the PR.  The unfortunate side of this is that the original creater of this db did not use response dox.

There is a field on the PO's that captures the UNID of the PR,  pr_link1
There can be several PO's related to the singular PR.

I would like to have an agent that will
a) capture the UNID of the PR
b) locate that UNID in a view that contains all the UNID's that are in the pr_link1 field that match the PR UNID
c) add the new number of the PR to the pr_link1 field

I am thinking this is a two part solution
Fisrt create the PR numbers then run the other that will change the fields as outlined above

Any help or thoughts appreciated



Question by:imjamesw
  • 4
  • 3
  • 3
LVL 24

Expert Comment

ID: 11841809
Try this

Create a field in PO as computed with formula

@GetDocField( pr_link1; "PRNumber")

Run agent on selected documents with following command


Author Comment

ID: 11841902
Here is what I have so far for creating an agent to number the existing PR;s

I created a field name PRNumber on the PR form

Am I missing anything from this agent

Dim ThisDB As NotesDatabase
Dim ThisServer As String
Dim ThisAgent As NotesAgent
Dim NewNum As Integer
Dim prdoc As NotesDocument
Dim view As NotesView

Dim Session As New NotesSession  
      Set ThisDB = session.CurrentDatabase  
      Set view = ThisDB.GetView("GPR")       
      Set prdoc = view.GetFirstDocument
      While Not (prdoc Is Nothing)       
            PRNum =prdoc.PRNumber
            PRNum = 0000
            NewNum = PRNum + 1
            If PRNum = "" Then
                  prdoc.PRNumber = NewNum
            End If
LVL 24

Expert Comment

ID: 11842176
Yes you have to set PRNumber for PR docs as you have in above agent .. And create another agent (this would be a temp agent) which will pull data in PO docs...
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 31

Accepted Solution

qwaletee earned 400 total points
ID: 11843430
Yes, you are missing a few things.

First off,  from this line:
    If PRNum = "" Then
... I take it that this is your permanent code for assigning PR #'s -- both "retroactive" assignment of old PR docs, and new ones as well.Yet, you have:
    PRNum = 0000
That shoudl only be done if you can't get an existing PRNum to increment!

In addition, this sequence makes no sense:

          PRNum =prdoc.PRNumber
          PRNum = 0000

... for two reasons.  prdoc.PRNumber will return an array, so you are missing prdoc.PRNumber(0).  Second, why the heck would you assign it 0 right after havinfg retrieved it?  FInally, what's the 0000 business?  Are you trying to force it to be four digits?  That won't do it, because 0000 evaluates to plain 0.  Maybe you meant it tobe a string?

Here's what Ithink you want to do.  Sort the view on PRNum, descending sort.  That will make the latest assigned PR number appear at the top, and the docs with no PR apppear at the bottom.  Now you can do this:

Dim s as new notesSession
Dim db as notesDatabase
Set db = s.currentDatabase
Dim view as notesView
Set view = db.getView("GPR")
Dim doc as notesDocument
Set doc = view.getFirstDOcument
Dim priorNumber as integer
If doc.PRNumber(0) = "" Then
    'No PR ever assigned, use prior number of 0, which it already is since it was not assigned a vlue
    priorNumber = doc.PRNumber(0)
End If

view.autoRefrehs = false 'otherwise, when we assign # and save, cur doc goes to top of view, and prev doc becomes end of view

Set doc = view.getLastDocument
Do Until doc Is Nothing
    If doc.PRNumber(0) = "" Then
        priorNumber = priorNumber + 1 'now it is "next" number
        doc.replaceItemValue "PRNumber" , Right("000" + priorNumber,4) false, false
        Set doc = view.getPreviousDocument(doc)
        'We hit a doc that was assigned a number, force processing to stop!
        Set doc = Nothing 'sort of fools the loop, as if we ran out of docs
    End If
LVL 31

Expert Comment

ID: 11843484
Next up would be to push the changes through to the PO's.  Build a view of PO's sorted by the PR doc ID # field.  Go through each PR, use its docID as a key to search that view, using getAllDocumentsByKey.  This retruns a document collection of all matching documents, and you can use NotesDocumentCOllection.stampAll to assign the PR # to the PO.

One probelm I see with this is that PR:PO is a many to many relationship in most companies.  I can have one PR that generates many POs, and one PO that came from several PRs.

SOmeone puts in a PR for all the equipment to build a server cluster.  The drives may come from one vendor while the chassis comes from another vendor.  That would be two POs for one PR.  But, if someone else happened to request a server chassis within teh same period, the purchase agnet might put both chassis on a single PO to the server vendor.

Author Comment

ID: 11843703
Hi I get an error on viewAutoRefresh
Not a Member

Author Comment

ID: 11846244
I am looking to modify the field PRNumber as

PR-00000001 etc....

I believe it gas to do with this line   doc.replaceItemValue "PRNumber" , Right("000" + priorNumber,4)
PRNumber is a text field

I have tried variations of this
doc.replaceItemValue "PRNumber" , Cstr(Right("000" +Cstr( priorNumber),4))
LVL 24

Assisted Solution

HemanthaKumar earned 100 total points
ID: 11851155
try this

doc.replaceItemValue "PRNumber" , Right("000" & priorNumber,4)
LVL 31

Expert Comment

ID: 11853494
Isn't that exactly what I had put in?
LVL 24

Expert Comment

ID: 11854181

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

809 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