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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Showing values in form...
Finance forum

Showing values in form , datasource of which is a temptable tempdb type.

(0) ShareShare
ReportReport
Posted on by

I have form form1, data source of this form is a tmptable tmptable1 (tempdb type)
When form1 is initialized it inserts value into this tmptable1.

However when i see the form i cannot see these values.

So for testing if code is working fine , i changed tmptable1 to regular type and voila
It was working fine, i could see the values inserted into the form during form initialized event on the form.

I am sure this has something to do with the nature of tempdb temptable, what can i do to ensure that values inserted during form insitialized event are displayed on form and table type is tempdb temptable.

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Would you mind sharing your code? It would help us help you.

    Basically this is how it should work in your form's init method:

    public void init()
    {
        super();
    
    TempTable.linkPhysicalTableInstance(MyClass::populateTmpData()); // Use this for tempDb temp tables TempTable.setTmpData(MyClass::populateTmpData()); // Use this for inMemory temp tables }


    You need to have MyClass that has method populateTmpData, and that method needs to fill the table and return the table buffer.

  • Mav Profile Picture
    on at

    I am not sure if i would be able to follow that approach as the initialized form event is having the sender which is driving the records.

    Here is the code

     [FormEventHandler(formStr(MyForm), FormEventType::Initialized)]
        public static void MyForm_OnInitialized(xFormRun sender, FormEventArgs e)
        {
            Common lcommon = sender.args().record();
            ProjTable                lprojtable1,lprojtable2;  
            UserId                   luserid =curUserId();
            MyDocumentsTmptable           letdoctmp;
            str desctest                = "hohoho";
            
    
            if (lcommon is ProjTable)
            {
                lprojtable1 = lcommon;
    
            }
           
    
       select ProjId ,OpportunityId from lprojtable2 where lprojtable2.ProjId == lprojtable1.ProjId;
            letdoctmp.Projid = lprojtable2.ProjId;
            letdoctmp.OpportunityId = lprojtable2.OpportunityId;
            letdoctmp.Description = desctest;
            ttsbegin;
            letdoctmp.insert();
            ttscommit;
    }
  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    In your code you don't assign the temp table buffer into the form data source. In your code you instantiate the tempTable in your event handler, and after the event handler is executed, it disappears (because tempTable only exists as long as the scope exists). That's why it doesn't work. So you must get the form data source from the formRun instance, and give your tempTable buffer to it.

  • Mav Profile Picture
    on at

    Can you pls share the code on how to get form data source from formRun instance.

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    There are plenty of examples if you do a simple web search. For example here you will find a complete example that solves your original question: community.dynamics.com/.../225869

  • Mav Profile Picture
    on at

    Sorry that example not helping

    Any blog where one can see working example of elements, args, formrun, formrun datasource.

    What do i need to write in this code to get form data source (ofmytemptable ) from the formRun instance

    [FormEventHandler(formStr(MyForm), FormEventType::Initialized)]
        public static void MyForm_OnInitialized(xFormRun sender, FormEventArgs e)
        {
            Common lcommon = sender.args().record();
            ProjTable                lprojtable1,lprojtable2;  
            UserId                   luserid =curUserId();
            MyDocumentsTmptable           letdoctmp;
            str desctest                = "hohoho";
            
    
            if (lcommon is ProjTable)
            {
                lprojtable1 = lcommon;
    
            }
           
    
       select ProjId ,OpportunityId from lprojtable2 where lprojtable2.ProjId == lprojtable1.ProjId;
            letdoctmp.Projid = lprojtable2.ProjId;
            letdoctmp.OpportunityId = lprojtable2.OpportunityId;
            letdoctmp.Description = desctest;
            ttsbegin;
            letdoctmp.insert();
            ttscommit;
    }


  • Verified answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Did you look at the last post in my link?

    It contains all you need. Something like this:

    FormRun formRun = sender as FormRun;
    
    YourTempTable yourTempTable;
    
    yourTempTable.clear();
    yourTempTable.Field1 = "foo";
    yourTempTable.insert();
    
    FormDataSource  YourTempTable_ds = formRun.dataSource(tableStr(YourTempTable));
    
    YourTempTable_ds.cursor().linkPhysicalTableInstance(yourTempTable); 
    


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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans