Solved

Help with a formatting agent.

Posted on 2012-04-10
17
332 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 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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