web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Facing issue while accessing display method

(0) ShareShare
ReportReport
Posted on by 505

Hi Experts,

I have created a custom field named 'ItemClass' in  EcoResProduct through table extension.

I want to show this field on InventOnhandItem form.

I have created a display method for InventSum table which is one of the datasources of the form as shown below.

[ExtensionOf(tableStr(InventSum))]
public final class MyPrefixInventSum_Extension
{
    display public String15 ItemClass()
    {
        return enum2Str(EcoResProduct::find(this.inventTable().Product,false).ItemClass);
        
    }

}

Now, I want to use this as display method for the string field on the Grid control but I don't see it in the DataMethod's dropdown list.

What am I doing wrong here?

I have the same question (0)
  • ergun sahin Profile Picture
    8,826 Moderator on at

    Can you try adding Static to method

  • Suggested answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Use MyPrefixInventSum_Extension.ItemClass in DataMethod.

    By the way, be careful about performance of your display method. Maybe you should rather use joins to fetch the data.

    Also, method names should begin with lowercase and you should prefix them with your company prefix (to avoid name conflicts).

  • ergun sahin Profile Picture
    8,826 Moderator on at

    robscode.onl/.../

  • Priyank Bhavsar Profile Picture
    505 on at

    Hi Martin,

    As per your suggestion, I used MyPrefixInventSum_Extension.ItemClass in DataMethod.

    I also changed my code to use table joins as below:

    display public static String15 myPrefixItemClass()
        {
            EcoResProduct product;
            InventTable inventTable;
            InventSum inventSum;
    
            select firstonly  myPrefixItemClass
                from product
                join inventTable where inventTable.Product == product.RecId
                join inventSum where inventSum.ItemId == inventTable.ItemId;
    
    
            return enum2Str(product. myPrefixItemClass);
            
            
        }

    Now I'm getting the following exception.

    pastedimage1621507235737v1.png

    Can you please let me know what is causing this exception?

  • Suggested answer
    Sumit Loya Profile Picture
    2,230 on at

    Hi Priyank,

    If you are writing static display method, then you need to pass the Buffer as a parameter as shown below:

    display public static String15 myPrefixItemClass(InventSum _inventSum)
        {
            EcoResProduct product;
            InventTable inventTable;
            InventSum inventSum;
    
            select firstonly  myPrefixItemClass
                from product
                join inventTable where inventTable.Product == product.RecId
    	      && inventTable.ItemId == _inventSum.ItemId;
    
            return enum2Str(product.myPrefixItemClass);        
        }

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Ignore the AccessViolationException for a moment and fix your code, because it doesn't make a good sense. Maybe the AccessViolationException will disappear when we fix known problems. There are indeed weird things in your code that may get the system confused.

    First of all, your method is now called myPrefixItemClass(), therefore you must update the value in DataMethod.

    Then, your display method will always return the same thing, because it has no information about the InventSum record which is should be related to. It takes no input at all.

    In your previous version, you referred to the current InventSum record by 'this' variable, which is a good approach. Switching to a static method isn't necessary, but if you want, you can do it - but then you must add a method parameter for the current record and using it instead of 'this'. Then you would also refer to the method by MyPrefixInventSum_Extension.::myPrefixItemClass instead of MyPrefixInventSum_Extension.myPrefixItemClass.

    Now you're refering to the method as if it was not static, but it is, and it's not implemented correctly.

    Try something like this instead:

    display String15 myPrefixItemClass()
    {
    	EcoResProduct product;
    	InventTable inventTable;
    
    	select firstonly MyPrefixItemClass from product
    		exist join inventTable
    		where inventTable.Product == product.RecId
    		   && inventTable.ItemId == this.ItemId;
    
    	return enum2Str(product.MyPrefixItemClass);
    }

    Using a single joined select rather than two separate statements may be an improvement, nevertheless it may be even worse because of less caching. What I meant was using joined data sources in a form rather then display methods.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    By the way, why do you convert the enum to string? Why don't you want to return the enum value?

  • Priyank Bhavsar Profile Picture
    505 on at

    Martin,

    I tried your code. I'm still getting  access violation exception.

     I used enum2str because I need to use this display method for string field. It may not be needed. Here's my updated code.

    display public MyPrefixItemClass myPrefixItemClass()
        {
            EcoResProduct product;
            InventTable inventTable;
    
            select firstonly MyPrefixItemClass from product
             exists join inventTable
            where inventTable.Product == product.RecId
               && inventTable.ItemId == this.ItemId;
    
            return product.MyPrefixItemClass;
            
            
        }

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    What value do you have ibn DataMethod property?

    What do you mean by "I need to use this display method for string field"? Could you tell us more about your scenario? Why can't you create a control of the correct type? Maybe you're making workaround of something that should be actually fixed.

  • Priyank Bhavsar Profile Picture
    505 on at

    Martin,

    I was referring to this:

    pastedimage1621517471358v1.png

    I have this field on my grid control which I need to bind to my custom field MyprefixItemClass.

    Datamethod has the value 'MyPrefixInventSum_Extension'.

    But after removing static keyword this value doesn't appear in the list of values for datamethod.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans