Skip to main content
Answer

The function will be called several times when the form is loading

  • May 25, 2021
  • 3 replies
  • 190 views

Hi Experts,

I have a data view called ‘ReportCredential’ in my PXGraph. I set ‘ReportCredential’ as a primary view for a PXFormView. Also I have a funtion called ‘reportCredential’. When the form is loading, I find the function will be called several times. Since I will call external web services in this function, I need this function to be called only once. Is there any other event handlers for the screen loading? The following is my code.

 

Thanks,

Best answer by Naveen Boga

Hi @DennyYang14,

You have written the view delegate i.e “reportCredential”, which will invoke multiple times when commits happened on the form document level.

Still, you can have a flag i.e. in side this viewdelegate like below, and which invoke only when you are making an API call.

 

public virtual IEnumerabel reportCredential()

{

         if(Base.IsContractBasedAPI == true)

          { 

              // logic here

          }

}

 

 

 

3 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • May 25, 2021

Hi @DennyYang14,

You have written the view delegate i.e “reportCredential”, which will invoke multiple times when commits happened on the form document level.

Still, you can have a flag i.e. in side this viewdelegate like below, and which invoke only when you are making an API call.

 

public virtual IEnumerabel reportCredential()

{

         if(Base.IsContractBasedAPI == true)

          { 

              // logic here

          }

}

 

 

 


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • May 25, 2021

Hello Denny, 

I suggest you to cache the result somewhere and return the cached result instead of calling the external web service every time. 

Also, I’m not sure if having the call to external web service in a view delegate is a good design overall. 

I’d recommend you to implement a separate process to sync the data and to display the cached data on the screen. 


  • Author
  • Freshman I
  • May 26, 2021

Hi @Naveen B ,

Thanks. It works!