Sequential numer & Profile-Doc?

Hi there,I’m using a profile-doc to give each new document a new (of course unique) sequential numer:

on QuerySave:

If source.IsNewDoc Then

Call seqNumber(source)		

End If

sub seqNumber(source)

Dim profil As NotesDocument

Set profil = db.GetProfileDocument("Profil")



Dim seqNo As String

seqNo = Cstr(profil.seqNo(0))	

profil.seqNo = profil.seqNo(0) + 1

Call profil.save(True, False)			

exit sub

But now I encountered several documents with the same number - how can this happen??? And: these documents were created within 10 minutes(!!!), so a “buisy server” is unlikely to can be blamed for |-[

Thanks in advance,

Buzzy

Subject: Sequential numer & Profile-Doc?

Hi Buzzy,

I have come across caching issues with profile documents before which have caused problems like these.

You update a field in a profile document yet when you go back to it the same value is there. However, if you close down your client and go back in the value has been updated. This caching issue doesn’t only apply to the UI - it also applies to the back end.

Nowadays I never use profile documents - I always create a view named “(Configs)” and create normal documents (as opposed to profiles) with a field named “ConfigName” in them which is displayed as the first sorted column of the view. I then create a function “GetConfigInfo()” which returns the config doc as a NotesDocument object.

A little more work than Profile documents - but at least you get correct values and no caching issues.

You can see the caching issues in effect sometimes if you edit your OOO profile (no need to enable the agent - just save & exit). When you go back in the old values are still there.

Hope this helps,

Tom.

Subject: RE: Sequential numer & Profile-Doc?

Hi Tom,nice idea, but for there are about 50 people who can create documents (and in this way also access the ConfigDoc) in that app: isn’t it quite likely to create conflict-documents? Or can I catch this case by checking the “LockHolders”-field?

Another way could be to count the total number of docs in a view (using EntryCount)…? But in this case I’d have to be sure that the view is up-to-date!

Maybe your solution is the best way…

Thanks,

Buzzy

Subject: RE: Sequential numer & Profile-Doc?

There are a few things you can to do reduce the possibility of a duplicate. One is to use some portion of the user’s name in the document key, and store that individual’s counter in their local notes.ini using an environment variable. Another is use a timestamp instead of a numeric increment.

Following is how I do it in an application that about 120 people update all day and I have never had an issue with conflicts. This generates a TicketNumber in the format YDDD-XXX, with Y being the year, DDD being the day of the year, then an incremental counter. There is only one document in the ($NumberWheel) view.

@If(TicketNumber != “”;@Return(TicketNumber);“”);

unid := @DbColumn(“”:“”;@DbName;“($NumberWheel)”; 1);

day := @DbColumn(“”:“NoCache”;@DbName;“($NumberWheel)”; 3);

year := @Text(@Year(@Today));

today := (@Today - @Date(@ToTime(“01/01/” + year))) / 86400;

@If(day = today;

	num := @DbColumn("":"ReCache";@DbName;"($NumberWheel)";2);

	@Do(

		num := 0;

		@SetDocField(unid; "Day";today)

	)

);

num := num + 1;

@SetDocField(unid; “NumberWheel”;num);

ticketnum := @Text(@TextToNumber(year) - 2000) + @Right(“00” + @Text(today); 3) + “-” + @Right(“000” + @Text(num); 3);

ticketnum

There is probably a more efficient way to handle this, and I welcome any suggestions to improve this or recommendations for another approach that would work better.

Thanks,

Charles

Subject: RE: Sequential numer & Profile-Doc?

Well, maybe I’ll have to use some special kind of ID, but for the time being I’d like to stay simple ;-)Our users complained even about a 4-digit-ID…

Thanks,

Buzzy

Subject: RE: Sequential numer & Profile-Doc?

I have implemented sequential numbering in many notes apps and the easiest way is to do it on queryopen (and then have delete code in querysave if the user decides to not save).

Just create a hidden view sorted by your id (where ID <> “”), and use, call view.refresh and view.getlastdocuemt, this will give you the the most current id in the database, this avoids conflicts on the config doc or caching issues with profile docs.

Subject: RE: Sequential numer & Profile-Doc?

Well, I already thought about using view.columncount in order to determine how many docs have been created so far, but I didn’t knew whether the view.refresh takes too long…?Here’s what I did (following Tom’s suggestion):

I created a view and a form “Counter”. The form holds one field containing the number.

When a user saves a new doc, following script is called:

[setting views, docs ‘n’ stuff]

For loopcount = 1 To 5

If Not counterdoc.LockHolders(0) = "" Then

	Sleep(1)		

Else

	lockOK = counterdoc.Lock(s.effectiveUsername)

	If lockOK Then

		dummyNr = counterdoc.lfdNrGesamt(0)	

		counterdoc.lfdNrGesamt = dummyNr + 1		

		Call counterdoc.save(True,False)

		Call counterdoc.UnLock

		Exit For

	End If		

End If			

Next

The Loop is for the case that there are several users trying to update the CounterDoc at the same time - or the server hangs :slight_smile:

If the CounterDoc couldn’t be update within five tries, ID will be set to 0 and I’ll receive a mail…

Hope this will work! If not, I’ll give your idea a try!

Thanks to you all!

Buzzy

Subject: RE: Sequential numer & Profile-Doc?

Formula being generally faster than script you could achieve the same thing with @Subset(@DBColumn(“”:“NoCache”;@DBName;“view”;1);-1)

The only issue I have had with this is in databases with a large number of documents the view refreshes can have a significant performance impact on both the client and server.

Subject: Sequential numer & Profile-Doc?

Profile doc’s should only be used for Static information. Each user has a cached copy, and so cannot see changes that other users make to them.

Subject: RE: Sequential numer & Profile-Doc?

Hm,what a pity that there is no way to force an update of the user’s “copy” of the profile-document |-[

Thanks,

Buzzy

Subject: RE: Sequential numer & Profile-Doc?

But that’s not what profile documents were added for. If you want to share updates, just use normal documents.

Profile documents are used when your application needs to lookup static information over and over, and you don’t want to keep hitting the server for data that’s not changing.