Solved

Help with a formatting agent.

Posted on 2012-04-10
17
334 Views
Last Modified: 2013-12-18
Hoping this might be a quick fix. I have a DB that has about 5000 records. For these I need to format the Agency field to be 3 characters with leading zeroes if needed. The agent I have is getting hung up. I am hoping that it can be rewritten to run just on the tagged records I have. I think one issue here is that it is running on all the records in the Agency view. How can this be tweaked to run just on the records I have tagged. It would not be in the Agency view. I have the main records in another view.

Sub Initialize
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim view As NotesView
	Dim doc As NotesDocument
	
	Set db = session.currentdatabase
	Set view = db.getview("Agency")
	Set doc = view.GetFirstDocument
	
	While Not Doc Is Nothing
		Call doc.ReplaceItemValue( "Agency", Format( doc.Agency(0), "000") )
		Call Doc.Save(True,False)
		Set doc = view.GetNextDocument(doc)
	Wend
	
End Sub

Open in new window

0
Comment
Question by:jforget1
[X]
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
  • 7
  • 6
  • 4
17 Comments
 
LVL 11

Accepted Solution

by:
larsberntrop earned 500 total points
ID: 37831450
Update all if not compliant:

Sub Initialize
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim view As NotesView
	Dim doc As NotesDocument, docNext as NotesDocument
	Dim agStr$, agNorm$
	
	Set db = session.CurrentDatabase
	Set view = db.GetView("Agency")
	view.AutoUpdate = False
	Set doc = view.GetFirstDocument
	
	Do Until Doc Is Nothing
		Set docNext = view.GetNextDocument(doc)
		agStr = Cstr(doc.GetItemValue("Agency")(0))
		agNorm = Right$("000" & agStr, 3)
		If agStr <> agNorm Then
			Call doc.ReplaceItemValue( "Agency", Format$(doc.Agency(0), "000"))
			Call Doc.Save(True, False)
		End If
		Set doc = docNext
	Loop
	
End Sub

Open in new window


If you want to process only selected documents: make sure to set the target in the agent properties to 'All selected documents'
Sub Initialize
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim dc As NotesDocumentCollection
	Dim doc As NotesDocument, docNext as NotesDocument
	Dim agStr$, agNorm$
	
	Set db = session.CurrentDatabase
	Set dc = db.UnprocessedDocuments
	Set doc = dc.GetFirstDocument
	
	Do Until Doc Is Nothing
		Set docNext = dc.GetNextDocument(doc)
		agStr = Cstr(doc.GetItemValue("Agency")(0))
		agNorm = Right$("000" & agStr, 3)
		If agStr <> agNorm Then
			Call doc.ReplaceItemValue( "Agency", Format$(doc.Agency(0), "000"))
			Call Doc.Save(True, False)
		End If
		Set doc = docNext
	Loop
End Sub

Open in new window

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37831462
Two ways:
1. you run the agent based on the unprocessed documents, instead of the view:
Sub Initialize
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim dc As NotesDocumentCollection
	Dim doc As NotesDocument
	
	Set db = session.currentdatabase
	Set dc= db.unprocessedDocuments
	Set doc = dc.GetFirstDocument
	
	While Not Doc Is Nothing
		Call doc.ReplaceItemValue( "Agency", Format( doc.Agency(0), "000") )
		Call Doc.Save(True,False)
		Set doc = dc.GetNextDocument(doc)
	Wend
	
End Sub

Open in new window


or you use a one-line Formula agent that runs on selected documents:
Field Agency:= @Right("000"+@Text(Agency);"3")

Open in new window

0
 
LVL 11

Expert Comment

by:larsberntrop
ID: 37831478
Yeah, both will solve the problem.  I tend to try not to save when not needed though.  Avoids being a resource hog.
0
Technology Partners: 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!

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37831548
I don't know, but one of my friends found out that Notes doesn't save when nothing has changed. Not quite sure if it applies here.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37831575
Plus, for a one-shot agent, who cares...
0
 

Author Closing Comment

by:jforget1
ID: 37833187
Appreciate the help with this one.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37833310
Appreciate the points for the one-liner... ;-)
0
 

Author Comment

by:jforget1
ID: 37833334
Well I tired the one liner first and for some reason it clear out the Agency value for all the records tagged. I was able to correct as I had another field I could reference, but something was a little off with that one.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37833778
Correct! I'm a fool, what a silly mistake... Here the corrected line:
Field Agency:= @Right("000"+@Text(Agency); 3)

Open in new window

0
 

Author Comment

by:jforget1
ID: 37833815
Damn those silly quotes. I see that looks like the only difference. As always I really do appreciate all the help on these issues. We are moving to Outlook/Sharepoint very soon, so these are hopefully my final Notes questions I will need to ask.
0
 

Author Comment

by:jforget1
ID: 37833973
This one is not our call, this is at a much higher level in the company, I am just along for the ride.
0
 

Author Comment

by:jforget1
ID: 37834264
sjef,

Any change you could take a peak at the other little issue I have at this point. Having trouble getting the hides working properly on a form.
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/Lotus_SmartSuite/Lotus_Notes/Q_27671056.html
0
 
LVL 11

Expert Comment

by:larsberntrop
ID: 37834586
Heh, oneliners that kill off data. Still calling me fool for using LotusScript on a test db?
0
 

Author Comment

by:jforget1
ID: 37834600
Figured out the syntax on the other issue I had.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37836385
@Lars: where did I call you a fool??

IMHO, the "art" of using Formula language is grossly underrated... Instead of 24 lines, only 1...
0
 
LVL 11

Expert Comment

by:larsberntrop
ID: 37837460
Nowhere.
0

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…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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