cancel
Showing results for 
Search instead for 
Did you mean: 

Failed validation with SBO_SP_TransactionNotification

0 Kudos

Hi.

I'm trying to see if there is a document type 18 PCH, when you add a new one, but does not work to add validation to test the update, it works. Can anyone help me where I am going wrong.

Code:

IF @object_type = '18' AND @transaction_type = 'A'

BEGIN

    DECLARE @numeroDoc int

    DECLARE @CodPn nvarchar(50)

    DECLARE @Serial int

    SELECT @numeroDoc = CONVERT(int,@list_of_cols_val_tab_del)

    SELECT @CodPn = OPCH.CardCode, @Serial = OPCH.Serial FROM OPCH WHERE OPCH.DocEntry = @numeroDoc

    SELECT @COUNT_PCH = COUNT(1) FROM OPCH WHERE serial = @Serial and cardcode = @CodPn

 

   

    IF @COUNT_PCH > 0

    BEGIN 

       

        SELECT @error = 1,

        @error_message = 'FAILED' 

    END 

   

END

Accepted Solutions (0)

Answers (2)

Answers (2)

edy_simon
Active Contributor
0 Kudos

Hi Bruno,

You did not say what you meant by not working.

Your code :

     SELECT @COUNT_PCH = COUNT(1) FROM OPCH WHERE serial = @Serial and cardcode = @CodPn

    IF @COUNT_PCH > 0

    BEGIN

          SELECT @error = 1,

        @error_message = 'FAILED'

    END

Should always return you @COUNT_PCH > 0.

Means each time you add, you will be stopped by this SP.

Your newly added record will be available in the table already when you do the select.

Hence your @COUNT will at least 1.

If you want to block duplicate entry you should either check @COUNT_PCH>1 or

add 'DocEntry <> @numeroDoc' in your where clause.

Regards
Edy

0 Kudos

Hy Edy.

I want to block the insertion of documents and validation of Serial CardCode fields, if already locked. My code is not correct?


Thanks,

Bruno.

edy_simon
Active Contributor
0 Kudos

Hi Bruno,

Try this change this part

IF @COUNT_PCH > 1

    BEGIN

        SELECT @error = 1,

        @error_message = 'FAILED'


        SELECT @error, @error_message     --I put here because i dont know the rest of your SP. Just in case

    END


Regards

Edy


0 Kudos

Hi Edy.

At the end of my SP had SELECT @ error, @ error_message. I added the code suggested by you, but it worked.




Thanks.

Bruno.

0 Kudos

Hi.

Nothing?

Thanks.

former_member413321
Contributor
0 Kudos

In the query do not observe the DECLARE @ COUNT_PCH of.

You can test the results of the consultation to see the problem,

comment "if @ COUNT_PCH> 0" to always define an error.

And the error message says @ error_message = 'FAILED' + convert (varchar, @ Serial) + ',' + Convert (varchar, @ COUNT_PCH).

Thus the message you know the value of variables to make decisions.

I could not do the test because they do not define it as a value to the serial

edy_simon
Active Contributor
0 Kudos

Hi Bruno,

Have you tried

SELECT @CodPn = OPCH.CardCode, @Serial = ISNULL(OPCH.Serial,0) FROM OPCH WHERE OPCH.DocEntry = @numeroDoc

    SELECT @COUNT_PCH = COUNT(1) FROM OPCH WHERE ISNULL(serial,0) = @Serial and cardcode = @CodPn

Regards

Edy

0 Kudos

Hi.

Edy, thank you for me help.

I've ran one debug the query, it returns true. The problem is valid when adding a document, even if invalid if it goes right.



Thanks.

former_member413321
Contributor
0 Kudos

How do you define the Field Serial, pero in my case it is always null.

edy_simon
Active Contributor
0 Kudos

Hi Bruno,

Before and After this block of code, is there any other query that handles the same object type ?

Regards

Edy

pedro_magueija
Active Contributor
0 Kudos

Hi Bruno,

Might not be anything but shouldn't the select just select?

SET @error = 1
SET @error_message = 'Failed.'

  

select @error, @error_message  


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

0 Kudos

Hi Pedro.

In my code snippet is:



select @error, @error_message

With update works.



0 Kudos

Hi.

has anyone ever experienced this?