Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

Question about database trigger (CRM 4.0)

$
0
0

Hello,

First of all I know what I'm about to ask is highly unsupported and shouldn't be done on a normal basis but it will save me so much development I'm willing to give it a try:

I'm  creating a "for insert" trigger on the InvoiceExtensionBase table and when an Invoice gets created I want to get the id from the inserted record and update a custom field on the same InvoiceExtensionBase table.

That value comes from the InvoiceBase Table:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER TRIGGER [dbo].[InsertSetTotalAmountBaseCurrency] ON [dbo].[InvoiceExtensionBase] 
FOR INSERT
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @taxaconversao DECIMAL(12,3)
	DECLARE @idsalesorder NVARCHAR(200)
	declare @idfactura uniqueidentifier
	SET @idfactura = (SELECT InvoiceId from inserted)
	declare @cash DECIMAL(12,3)
	SET @cash =(SELECT TotalAmount FROM InvoiceBase where InvoiceId = @idfactura)
	
	UPDATE [InvoiceExtensionBase]
	SET ESRI_totaldatadeencomenda = @cash
	where InvoiceId = @idfactura
	

END
GO

Now, the question is the TOTALAMOUNT is always 0 for some reason although that's not the value reflected on the InvoiceBase table.

If I set the @cash variable to any other value it gets updated correctly so I'm wondering what the problem is.

I'm assuming InvoiceBase is already created by the time InvoiceExtensionBase inserts the record so the value should be there.

Any ideas?

Appreciate the help.


Viewing all articles
Browse latest Browse all 1000

Trending Articles