tmannais
4th September 2018, 14:21
Hi,
I created an extension type Table for tisfc001. I want it to execute some functions when a new record is created. Sounds easy, right?
Yes. I then implemented on After Save hook with the condition "mode = DAL_NEW". As a result, the functions inside the condition get executed as expected. However, the functions need to use some data that is related to the table, which is Material. The tough part comes when I realized that the data that link to the table is generated after a new Production Order is created. Therefore, my functions inside the Extension cannot perform correctly because the data is not there in time.
To make it easier to understand, let me visualize it this way. It now flows like this:
1. Create new record
2. After Save hook is executed
3. The related data is generated according to the newly created order
The desired flow:
1. Create new record
2. The related data is generated according to the newly created order
3. **a way to execute the functions here**
The generated data often have many records.
The After Save hook triggers in total of 3 times like this:
1. DAL_NEW
2. DAL_UPDATE
3. DAL_UPDATE
at the point of 2. and 3. are the only moment that the functions can perform correctly since the required data is not generated in the step 1.
I tried using CDF in this table to act as a flag.
When an order is created, the flag is initialized to 0, and when the After Save hook gets executed, it will check if this CDF is 0, which means it was just created then it will perform the functions and then update the CDF to other value such as 1 in order to trigger it only once.
The problem is that updating in the same table as the table in the After Save here is not allowed because it will cause a recursion. So, this method is not valid.
In case who wants to see the code, it's as simple as this:
function extern long after.save.object(long mode)
{
if mode = DAL_UPDATE then
some.functions.to.run() |* Gets executed 2 times on creating new record
endif
return (0)
}
Please help.
Regards,
Thana
I created an extension type Table for tisfc001. I want it to execute some functions when a new record is created. Sounds easy, right?
Yes. I then implemented on After Save hook with the condition "mode = DAL_NEW". As a result, the functions inside the condition get executed as expected. However, the functions need to use some data that is related to the table, which is Material. The tough part comes when I realized that the data that link to the table is generated after a new Production Order is created. Therefore, my functions inside the Extension cannot perform correctly because the data is not there in time.
To make it easier to understand, let me visualize it this way. It now flows like this:
1. Create new record
2. After Save hook is executed
3. The related data is generated according to the newly created order
The desired flow:
1. Create new record
2. The related data is generated according to the newly created order
3. **a way to execute the functions here**
The generated data often have many records.
The After Save hook triggers in total of 3 times like this:
1. DAL_NEW
2. DAL_UPDATE
3. DAL_UPDATE
at the point of 2. and 3. are the only moment that the functions can perform correctly since the required data is not generated in the step 1.
I tried using CDF in this table to act as a flag.
When an order is created, the flag is initialized to 0, and when the After Save hook gets executed, it will check if this CDF is 0, which means it was just created then it will perform the functions and then update the CDF to other value such as 1 in order to trigger it only once.
The problem is that updating in the same table as the table in the After Save here is not allowed because it will cause a recursion. So, this method is not valid.
In case who wants to see the code, it's as simple as this:
function extern long after.save.object(long mode)
{
if mode = DAL_UPDATE then
some.functions.to.run() |* Gets executed 2 times on creating new record
endif
return (0)
}
Please help.
Regards,
Thana