Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to add display method to the form datasource?

(0) ShareShare
ReportReport
Posted on by 737

Hello,

I'm trying add additional display method to InventSum datasource on InventOnhandItem form.

I attached my code below. I'm have debbuged this and always _inventSum equals "No data selected".

Can anyone suggest how it should be done correctly?

Thanks.

[ExtensionOf(formDataSourceStr(InventOnhandItem, InventSum))]
final class InventOnhandItem_XXX_Extension
{
    display Qty MyDisplay(InventSum _inventSum)
    {
        InventSum inventSum;
        FormDataSource InventSum_ds = _inventSum.datasource();
        FormDataSource InventDim_ds  = InventSum_ds.formRun().dataSource("InventDim");

        return InventSum.MyMethod(_inventSum, InventDim_ds);
    }
}

  • Shooowtek Profile Picture
    Shooowtek 737 on at
  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to add display method to the form datasource?

    Thank you, but unfortunately it doesn't work

  • Suggested answer
    RE: How to add display method to the form datasource?

    Hi,

    [ExtensionOf(formDataSourceStr(InventOnhandItem, InventSum))]
    final class InventOnhandItem_InventSum_XXX_Extension
    {
        display Qty myDisplay(InventSum _inventSum)
        {
            FormDataSource inventDim_ds = this.formRun().dataSource("InventDim");
    
            return _inventSum.MyMethod(inventDim_ds);
        }
    
    }

    [ExtensionOf(tableStr(InventSum))]
    final class InventSum_XXX_Extension
    {
        public Qty myMethod(FormDataSource _ds)
        {
            InventDim inventDim;
    
            inventDim = _ds.cursor();
            
            if(inventDim.InventLocationId)
            {
                return 99;
            }
    
            return 0;
        }
    
    }

    Please try the above logic and check if it works.

  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to add display method to the form datasource?

    Could someone please help?

  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to add display method to the form datasource?

    Does anyone have any suggestions?

  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to add display method to the form datasource?

    I have a display method created on the InventSum datasoure of the InventOnhandItem form. Based on the debugging I did on this method, _inventSum is "No data selected"

    This method calls the myMethod from the InventSum table extension.

    [ExtensionOf(formDataSourceStr(InventOnhandItem, InventSum))]
    final class InventOnhandItem_InventSum_XXX_Extension
    {
        display Qty myDisplay(InventSum _inventSum)
        {
            FormDataSource inventSum_ds = _inventSum.datasource();
            InventSum inventSum = inventSum_ds.cursor();
            FormDataSource inventDim_ds = inventSum_ds.formRun().dataSource("InventDim");
    
            return InventSum.MyMethod(_inventSum, InventDim_ds);
        }
    
    }

    [ExtensionOf(tableStr(InventSum))]
    final class InventSum_XXX_Extension
    {
        public Qty myMethod(InventSum _inventSum, FormDataSource _ds)
        {
            InventTrans inventTrans;
            InventDim inventDim;
    
            Common common = formJoinedRecord(_inventSum, _ds);
    
            if(common.TableId == tableNum(InventDim))
            {
                inventDim = common as InventDim;
            }
    
            if(inventDim.InventLocationId)
            {
                return 99;
            }
    
            return 0;
        }
    
    }

    The requirement is that the display is to show a value of 99 if the 'Location' storage dimension is enabled and not empty for the row.
    I have the same logic in AX12 and there it works without any problem. I'm trying to get it into D365, but with no results.

    Could you please help me?

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to add display method to the form datasource?

    Hi, You can get InventDim table buffer using below code, provided InventSum_ds is not empty.

    InventDim inventDim = InventDim_ds.cursor();

  • Shooowtek Profile Picture
    Shooowtek 737 on at
    RE: How to add display method to the form datasource?

    How on the InventSum table will I be able to get inventDim_ds?

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: How to add display method to the form datasource?

    Instead of inventsum.datasource, give this.cursor();

    I am not sure you can create a display method in form datasource. Ideally I will create that in table level and add that to a form as a new field.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans