Solved

Help with numbering agent

Posted on 2004-08-19
10
264 Views
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
Next

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

Regards

James




0
Comment
Question by:imjamesw
  • 4
  • 3
  • 3
10 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
Try this

Create a field in PO as computed with formula

@GetDocField( pr_link1; "PRNumber")

Run agent on selected documents with following command
@Command([Toolsrefreshselecteddocs])

~Hemanth
0
 

Author Comment

by:imjamesw
Comment Utility
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
      Wend
0
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
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...
0
 
LVL 31

Accepted Solution

by:
qwaletee earned 400 total points
Comment Utility
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
Else
    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)
    Else
        '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
Loop
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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.

Example:
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.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:imjamesw
Comment Utility
Hi I get an error on viewAutoRefresh
Not a Member
0
 

Author Comment

by:imjamesw
Comment Utility
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))
0
 
LVL 24

Assisted Solution

by:HemanthaKumar
HemanthaKumar earned 100 total points
Comment Utility
try this

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

Expert Comment

by:qwaletee
Comment Utility
Isn't that exactly what I had put in?
0
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
+/&
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 beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

7 Experts available now in Live!

Get 1:1 Help Now