Skip to main content

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.

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 :)


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?


@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.


Reply