Skip to main content
Answer

Row updated and row inserted gets called twice

  • April 3, 2023
  • 6 replies
  • 342 views

Forum|alt.badge.img

how do I resolve Row updated and row inserted getting called multiple times which executions logic twice 

Best answer by sweta68

Hi @robert38 

I am unsure why it is executing twice, but the below code snippet can handle multiple executions.

class ClassMaint : PXGraph<ClassMaint, FRClass>
{
public PXSelect<FRClass> Class;
public PXSelect<FRClassTeacher,
Where<FRClassTeacher.ClassNbr, Equal<Current<FRClass.ClassNbr>>>> ClassTeachers;

protected bool IsUpdating = false;
protected bool IsInserting = false;

protected void _(Events.RowUpdated<FRClass> e)
{
if (!IsUpdating)
{
IsUpdating = true;
var row = e.Row; // breakpoint here
// Perform your logic for RowUpdated event

IsUpdating = false;
}
}

protected void _(Events.RowInserted<FRClass> e)
{
if (!IsInserting)
{
IsInserting = true;
var row = e.Row; // breakpoint here
// Perform your logic for RowInserted event

IsInserting = false;
}
}
}

 

IsUpdating and IsInserting, are added to track whether the events are already being processed. By using these flags, you can ensure that the logic inside the events is executed only once.

Hope it helps!

Regards,

Sweta

6 replies

aaghaei
Captain II
Forum|alt.badge.img+10
  • Captain II
  • April 3, 2023

Please share your code so that people can have a look. Other than RowSelected event which is called multiple times, the rest of the Events are called only one. See the below event model for your reference.

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • April 3, 2023

@robert38  As requested above, please share the code and issue details, so that everyone can review and suggest the best solution.


Forum|alt.badge.img
  • Author
  • Freshman II
  • April 3, 2023

@Naveen Boga @aaghaei 
 

class ClassMaint : PXGraph<ClassMaint, FRClass>

{

     

    public PXSelect<FRClass> Class;

 

    [PXCopyPasteHiddenView()]

    public PXSelect<FRClassTeacher,

        Where<FRClassTeacher.ClassNbr, Equal<Current<FRClass.ClassNbr>>>> ClassTeachers;

 

      protected void _(Events.RowUpdated<CTRMCollateralFinFacility> e)

        {

           

            var row = e.Row;  //break point here

                //other operations

        }

 

        protected void _(Events.RowInserted<CTRMCollateralFinFacility> e)

        {

           

            var row = e.Row;  //break point here

                //other operations

        }

   

}

     

so I have a form grid with FRClass as the form data member and ClassTeachers as the grid ... when I add a new grid the RowUpdated and RowInserted get triggered twice 


aaghaei
Captain II
Forum|alt.badge.img+10
  • Captain II
  • April 3, 2023

The provided context is a mishmash and doesn’t say much. Please provide

CTRMCollateralFinFacility View

CTRMCollateralFinFacility DAC Key fields

CTRMCollateralFinFacility Grid Properties and it’s  parent-child relationship definitions.

 

Also what triggers the events either entering from UI or calling from code like View.insert …


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • May 17, 2023

Hi @robert38 were you able to find a solution? Thank you!


Forum|alt.badge.img+9
  • Semi-Pro III
  • Answer
  • May 18, 2023

Hi @robert38 

I am unsure why it is executing twice, but the below code snippet can handle multiple executions.

class ClassMaint : PXGraph<ClassMaint, FRClass>
{
public PXSelect<FRClass> Class;
public PXSelect<FRClassTeacher,
Where<FRClassTeacher.ClassNbr, Equal<Current<FRClass.ClassNbr>>>> ClassTeachers;

protected bool IsUpdating = false;
protected bool IsInserting = false;

protected void _(Events.RowUpdated<FRClass> e)
{
if (!IsUpdating)
{
IsUpdating = true;
var row = e.Row; // breakpoint here
// Perform your logic for RowUpdated event

IsUpdating = false;
}
}

protected void _(Events.RowInserted<FRClass> e)
{
if (!IsInserting)
{
IsInserting = true;
var row = e.Row; // breakpoint here
// Perform your logic for RowInserted event

IsInserting = false;
}
}
}

 

IsUpdating and IsInserting, are added to track whether the events are already being processed. By using these flags, you can ensure that the logic inside the events is executed only once.

Hope it helps!

Regards,

Sweta