Solved

error "'Graph' is a variable but used like a type" when trying to dynamically get a graph full name

  • 22 August 2022
  • 3 replies
  • 103 views

Userlevel 7
Badge +9

Hello Everyone,

 

I have a funtion that depending on what graph is calling it should do different stuff. I would like to pass the graph calling the function then compare it to some graphs and do what I need. Inside the function when I try to compare the input graph I get an error that "'Graph' is a variable but used like a type". Below is the code snippet. How can I make it work?

 

public static string TestFunction(PXGraph Graph)
{
if (Graph == null) return null;

if (typeof(Graph).FullName == typeof(APInvoiceEntry).FullName)
{
// Do stuff here
}

if (typeof(Graph).FullName == typeof(ChangeOrderEntry).FullName)
{
// Do stuff here
}

// and so on for some more graphs

return null;
}

I can get the graph FullName from the caller and pass to the function but I prefer not.

icon

Best answer by Dioris Aguilar 22 August 2022, 22:18

View original

3 replies

Userlevel 5
Badge +2

@aaghaei Try the following code: 

public virtual void UpdateFSCacheInAPDoc(PXGraph graphHelper)
{
if (graphHelper is AppointmentEntry)
{
var appGraph = (AppointmentEntry)graphHelper;
...
}
else if (graphHelper is ServiceOrderEntry)
{
var soGraph = (ServiceOrderEntry)graphHelper;
...
}
}

It’s an actual method from SM_APInvoiceEntry extension.

Userlevel 7
Badge +9

Thanks @jinin. My goal is not to hard code variables otherwise I could just gt the graphname from the graph that calls the function and pass it as a parameter to function. Here you have hard coded the screenID. I want this to be dynamic based on whatever graph calls the function. Any other though?

Userlevel 7
Badge +11

Hi @aaghaei 

If we use the ScreenUtils, will get all graph information based on the screenID.

We can get the screenID based on the accessinfo(Base.Accessinfo.ScreenID) 

 

Please try like below.

Add name space PX.API and PX.MetaData 


 if (ScreenUtils.ScreenInfo.TryGet("AR301000").GraphName == typeof(APInvoiceEntry).FullName)
            {
                // Do stuff here
            }

Hope this will help you :)

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved