You are viewing limited content. For full access, please sign in.

Question

Question

Stored Procedure Document Numbering Skipping Every 3 Numbers

asked on September 9, 2024 Show version history

I've set up a form with defaults that are required as input for getting a document number through a stored procedure.

And I set up the lookup rules as follows:

Here's the stored procedure:

USE [dbTest]
GO
/****** Object:  StoredProcedure [dbo].[gNDNBY]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[gNDNBY]
	-- Add the parameters for the stored procedure here
	@i_docIdId int = NULL,
	@i_docId varchar(4),
	@i_docRev varchar(40)
AS
BEGIN

	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	Declare @systemYear as int;
	SET @systemYear = CAST(YEAR(GETDATE()) AS int);

	Declare @currentYear as int;
	SELECT @currentYear = currentYear FROM dbo.gNDNBY WHERE docIdId = @i_docIdId;

	IF (@systemYear=@currentYear)
		BEGIN
			BEGIN TRANSACTION;
			UPDATE dbo.gNDNBY WITH (TABLOCK,UPDLOCK)
			SET docNumber = docNumber + 1
			WHERE docIdId = @i_docIdId;

			SELECT dNBYC
			FROM dbo.gNDNBY
			WHERE docId = @i_docId;

			COMMIT TRANSACTION;
		END
	ELSE
		BEGIN
			BEGIN TRANSACTION;
					UPDATE dbo.gNDNBY WITH (TABLOCK,UPDLOCK)
					SET currentYear = @systemYear, docNumber=0
					WHERE docIdId = @i_docIdId;
			COMMIT TRANSACTION;

			BEGIN TRANSACTION;
			UPDATE dbo.gNDNBY WITH (TABLOCK,UPDLOCK)
			SET docNumber = docNumber + 1
			WHERE docIdId = @i_docIdId;

			SELECT dNBYC
			FROM dbo.gNDNBY
			WHERE docId = @i_docId;

			COMMIT TRANSACTION;
		END
END

It gives me the correct number, but skips to every third number. Any ideas why this could be happening?

 

0 0

Answer

SELECTED ANSWER
replied on September 13, 2024 Show version history

So, turns out, I cannot set the defaults ahead of time in the form. I set the defaults through javascript instead, and it works!

$('.docIDID input').val('14') && $('.docID input').val('B09') && $('.revision input').val('00').change();

 

0 0
replied on September 13, 2024

Clever workaround, only firing the change event when you have all three field values set also works!

1 0

Replies

replied on September 10, 2024 Show version history

Here I am reading the stored proc when the solution is more obvious. I think what is happening is you're getting the third invocation of this stored procedure. Note you have 3 input fields in this lookup rule. Laserfiche doesn't know when you want to invoke the rule so it does it each time one of those fields change. The defaults are set sequentially even if they look like they are set at the same time.

You could either:

  1. Use the autofill button and use that to start the stored procedure
  2. check in the stored procedure that you have valid inputs before inserting into the table
2 0
You are not allowed to follow up in this post.

Sign in to reply to this post.