Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

How to handle "No Checkout Authority could be found for PO" Error Message in SQL Server?

Dear, I have written a trigger, when user voilates trigger gives proper Error Message, but user need to close that PO and reopen it to make it correct. if user does not re-open the PO. he gets the error which is in attached file.
trigger code is given eblow.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [POSOProcessing]  
   ON  [dbo].[InvNum]
   AFTER UPDATE

AS
      SET NOCOUNT ON;
Begin
      If exists(select * from _btblInvoiceLines      Where iInvoiceID in ( Select AutoIndex From Inserted) and fUnitpriceincl >1000)
      Begin
            RAISERROR ('Enter Price for KG',16,1)
      End
End


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER TRIGGER [POSOProcessing]  
   ON  [dbo].[InvNum] 
   AFTER UPDATE 
	
AS 
	SET NOCOUNT ON;

Begin
	If exists(select * from _btblInvoiceLines	Where iInvoiceID in ( Select AutoIndex From Inserted) and fUnitpriceincl >1000)
	Begin
		RAISERROR ('Enter Price for KG',16,1)
	End
End

Open in new window

Check-out-Authority.bmp
0
mahmood66
Asked:
mahmood66
  • 2
  • 2
2 Solutions
 
Larissa TCommented:
Not sure what it means "user need to close that PO and reopen it"
Even if user gets error message all updated on a table  will be already done
In general This type of validation is better to do in UI level.

here is test for your trigger:
create table mytable (c int)
go
create TRIGGER tr_mytable   ON  mytable    AFTER UPDATE
AS
Begin
            RAISERROR ('Enter Price for KG',16,1)
End
go
insert into mytable values(5)
go
select * from  mytable
update mytable set c=10
select * from  mytable
0
 
mahmood66Author Commented:
Dear, i cannot do at UI level, because the source code we are not having, that's why i am trying to ristrict using trigger.
"Even if user gets error message all updated on a table will be already done" ( your are right but when my statement RaisError executes it rollbacks the transaction so my database is not save the wrong data).
0
 
Larissa TCommented:
execute all actions needed for
"user need to close that PO and reopen it"  
and then raise error
0
 
mahmood66Author Commented:
with the help of experts idea, i have done.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now