Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Help with numbering agent

Posted on 2004-08-19
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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...
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 31

Accepted Solution

qwaletee earned 1600 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)
        doc.save 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

604 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