Solved

Help with a formatting agent.

Posted on 2012-04-10
17
326 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
  • 7
  • 6
  • 4
17 Comments
 
LVL 10

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 10

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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 37833894
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 10

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 10

Expert Comment

by:larsberntrop
ID: 37837460
Nowhere.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

17 Experts available now in Live!

Get 1:1 Help Now