Database trigger on a temp table.

Microsoft Axapta Development, Management, Functional and Technical Support Discussions.

Database trigger on a temp table.

Post by usenet » Sun Jun 28, 2009 7:53 pm

Hi everybody,

I raised this issue before and failed to resolve it, but now it's important
for me to get it done.

I want to trigger the Update event on a temp table to modify its content
before it gets back to the form.

Here's the registration script:
//////////////////////////////////////
NotReg = Trigger_RegisterDatabaseByName (346, "MOP_Comp_Trx_Items_Tab_Temp",
"MOP_Component_Trx_Entry", 8, script MOTRXENTRY);
if NotReg <> 0 then
warning getmsg(32000);
end if;
//////////////////////////////////////

And here's MOTRXENTRY procedure:
//////////////////////////////////////
inout anonymous table MOP_Comp_Trx_Items_Tab_Temp;

change first table MOP_Comp_Trx_Items_Tab_Temp;

while err() = OKAY do
if column("CB") of table MOP_Comp_Trx_Items_Tab_Temp then
set column("CB") of table MOP_Comp_Trx_Items_Tab_Temp to false;
save table MOP_Comp_Trx_Items_Tab_Temp;
else
release table MOP_Comp_Trx_Items_Tab_Temp;
end if;
change next table MOP_Comp_Trx_Items_Tab_Temp;
end while;

release table MOP_Comp_Trx_Items_Tab_Temp;
////////////////////////////////////////////////
This procedure has a random result, sometimes it works for somerows, other
times works for the first row only. I tried it with a temp table in the Main
dictionary and it gives me the same random resuts.

Could you please advise on this?

Thanks.

MH.
More available at Technology Forums
usenet
 
Posts: 80094
Joined: Wed Jun 24, 2009 8:14 am

RE: Database trigger on a temp table.

Post by usenet » Mon Jun 29, 2009 7:35 am

Hi MH

Is there a reason that you are working on the entire table rather than just with the one record that was passed with the positioned
table buffer.

Also, you will probably need to restore the position in the table buffer by setting the key fields back to the values that were passed
in.

If you need to work on the entire table, then why don't you capture a reference to the table buffer with this trigger, then disable the
trigger until the next time form is opened again.

Once you have the reference you can use another trigger when the processing of the temporary table is finished to make your
changes using the table('Table Reference' of globals) syntax to re-instantiate your table. Look at the Assign dex command.

David

David Musgrave [MSFT]
Escalation Engineer - Microsoft Dynamics GP
Microsoft Dynamics Support - Asia Pacific

Microsoft Dynamics (formerly Microsoft Business Solutions)
http://www.microsoft.com/Dynamics

mailto:David.Musgrave@online.microsoft.com
http://blogs.msdn.com/DevelopingForDynamicsGP

Any views contained within are my personal views and not necessarily Microsoft policy.
This posting is provided "AS IS" with no warranties, and confers no rights.
More available at Technology Forums
usenet
 
Posts: 80094
Joined: Wed Jun 24, 2009 8:14 am

RE: Database trigger on a temp table.

Post by usenet » Mon Jun 29, 2009 8:23 am

Yes, actually I need to modify each record in this table according to some
criteria.

If I used a Table Reference (the thing which I did before I test this code
and failed) would I need to position the table back?

Here was my code which uses the Table Reference:

/////////////////////
local string ErrMsg;
local text ExecMe;

pragma(disable warning LiteralStringUsed);

ExecMe = "inout reference Table_Ref;assign Table_Ref as reference to table
MOP_Comp_Trx_Items_Tab_Temp;";

if execute(346, ExecMe, ErrMsg, 'BK-MOCmpTrxRef' of globals)<>0 then
warning getmsg(32005) + ": " + ErrMsg;
end if;

change first table('BK-MOCmpTrxRef' of globals);

while err() = OKAY do
column("CB") of table('BK-MOCmpTrxRef' of globals)=true then
column("CB") of table('BK-MOCmpTrxRef' of globals) = false;
save table('BK-MOCmpTrxRef' of globals);
else
release table('BK-MOCmpTrxRef' of globals);
end if;
change next table('BK-MOCmpTrxRef' of globals);
end while;

release table('BK-MOCmpTrxRef' of globals);

pragma(enable warning LiteralStringUsed);
//////////////////////////

Actualy the "if" statement has more conditions, but I wrote one condition
for simplicity purpose.

Thanks David.

MH

"David Musgrave [MSFT]" wrote:

> Hi MH
>
> Is there a reason that you are working on the entire table rather than just with the one record that was passed with the positioned
> table buffer.
>
> Also, you will probably need to restore the position in the table buffer by setting the key fields back to the values that were passed
> in.
>
> If you need to work on the entire table, then why don't you capture a reference to the table buffer with this trigger, then disable the
> trigger until the next time form is opened again.
>
> Once you have the reference you can use another trigger when the processing of the temporary table is finished to make your
> changes using the table('Table Reference' of globals) syntax to re-instantiate your table. Look at the Assign dex command.
>
> David
>
> David Musgrave [MSFT]
> Escalation Engineer - Microsoft Dynamics GP
> Microsoft Dynamics Support - Asia Pacific
>
> Microsoft Dynamics (formerly Microsoft Business Solutions)
> http://www.microsoft.com/Dynamics
>
> mailto:David.Musgrave@online.microsoft.com
> http://blogs.msdn.com/DevelopingForDynamicsGP
>
> Any views contained within are my personal views and not necessarily Microsoft policy.
> This posting is provided "AS IS" with no warranties, and confers no rights
More available at Technology Forums
usenet
 
Posts: 80094
Joined: Wed Jun 24, 2009 8:14 am

RE: Database trigger on a temp table.

Post by usenet » Thu Jul 02, 2009 9:15 am

How are you capturing the Table Reference in the first place?

David Musgrave [MSFT]
Escalation Engineer - Microsoft Dynamics GP
Microsoft Dynamics Support - Asia Pacific

Microsoft Dynamics (formerly Microsoft Business Solutions)
http://www.microsoft.com/Dynamics

mailto:David.Musgrave@online.microsoft.com
http://blogs.msdn.com/DevelopingForDynamicsGP

Any views contained within are my personal views and not necessarily Microsoft policy.
This posting is provided "AS IS" with no warranties, and confers no rights.
More available at Technology Forums
usenet
 
Posts: 80094
Joined: Wed Jun 24, 2009 8:14 am

RE: Database trigger on a temp table.

Post by usenet » Sat Jul 04, 2009 10:36 pm

Thanks David,

I was capturing the table reference through the DatabaseTrigger, but finally
I got to know that it was failing to update the records for a different
reason (a procedure was reversing my changes).

I'm okay now.... Thanks a lot.

MH.

"David Musgrave [MSFT]" wrote:

> How are you capturing the Table Reference in the first place?
>
> David Musgrave [MSFT]
> Escalation Engineer - Microsoft Dynamics GP
> Microsoft Dynamics Support - Asia Pacific
>
> Microsoft Dynamics (formerly Microsoft Business Solutions)
> http://www.microsoft.com/Dynamics
>
> mailto:David.Musgrave@online.microsoft.com
> http://blogs.msdn.com/DevelopingForDynamicsGP
>
> Any views contained within are my personal views and not necessarily Microsoft policy.
> This posting is provided "AS IS" with no warranties, and confers no rights
More available at Technology Forums
usenet
 
Posts: 80094
Joined: Wed Jun 24, 2009 8:14 am


Return to Axapta



Who is online

Users browsing this forum: No registered users and 1 guest

cron