Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

Using Tmp table of form in batch job class x++

(0) ShareShare
ReportReport
Posted on by 163
I created a new form with temp tables data source , I need to use all of temp tables in select statement but when I select any of them it doesn't has any data . 
How can I use them ?
//
 
this is my form I need when I clicked on Ok button to call batch job class and loop on all temp tables 
there is any way to do this ?
  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    Using Tmp table of form in batch job class x++
    Thank you, Martin. This is simpler approach.
     
    Will try the approach you suggested next time when inserting code. Thank you.
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Using Tmp table of form in batch job class x++
    This approach is possible, but only for a single data source.
     
    Also, it's over-complicated:you take a record, then its data source and then again the record from the data source. You can skip all of that and just use args.record() straight away. You also populate ds variable but never use it for anything and you call the same code again.
     
    The option to insert code is the next-t-last button in the post editor toolbar. In my case, no icon is displayed, but the button still works:
    // Orig code
    if (args.dataset() == tableNum(Table))
    {
        FormDataSource ds = FormDataUtil::getFormDataSource(args.record());
        Table tableBuffer = FormDataUtil::getFormDataSource(args.record()).cursor();
    }
    
    // Simplified code - variant 1:
    if (args.dataset() == tableNum(Table))
    {
        Table tableBuffer = args.record();
    }
    
    // Simplified code - variant 2:
    Table tableBuffer = args.record() as Table;
    if (tableBuffer)
    {
        ...
    }
  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    Using Tmp table of form in batch job class x++
    You can try getting the table or formdatasource using FormDataUtil class.
     
     if(args.dataset() == tableNum(Table))
            {
                   FormDataSource ds = FormDataUtil::getFormDataSource(args.record());
                   Table tableBuffer = FormDataUtil::getFormDataSource(args.record()).cursor();
            }
     
    As I could not find the right way to insert code, I have to write directly like a normal text. 
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Using Tmp table of form in batch job class x++
    That's the bug. You aren't passing information about the current form - element.args() contains information about how the form was called. These are the arguments that were passed to your form by its caller. You should learn to use the debugger, because it can show you things like these.
     
    The best approach will be throwing this code away and using a menu item button. It means that you don't need any code at all, so you also can't introduce any bugs, it'll make security setup much simpler and do on.
  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    Using Tmp table of form in batch job class x++
    I already show you my code , I call class by classobj::main(element.args()) 
    so in batch class how can I get formRun 
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Using Tmp table of form in batch job class x++
    This code makes no sense at all. By classFactory.formRunClass(), you created a new empty form, which has absolutely no data and therefore it's useless for you. What you want is the form instance where you added the data.
     
    If args.caller() contains a wrong object, you have problem either in how you're calling your class or in your expectations. If you need our help, you'll need to give us more information about your solution.
  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    Using Tmp table of form in batch job class x++
    I tried your solution now also no data selected (datasource of cursor )
     
     formRun SetUpForm = classFactory.formRunClass(args);
    I got formRun by this way beacause args.caller () saw the caller of my form not my form so Is it right or not ?
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Using Tmp table of form in batch job class x++
    Yes, I understand you want multiple records. You'll use a select statement to fetch the records you want, the difference is that you'll query a buffer that actual contains data, instead of an empty buffer.
     
    It seems that you have little idea about how to use temporary tables and you'll make your job much easier if you learn the basics. For example, this article may give you a lot of important information.
  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    Using Tmp table of form in batch job class x++
    I need to loop on all records doesn't need one record 
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Using Tmp table of form in batch job class x++
    Yes, categoryContractTmpCFMobj doesn't contain any records. You declared a new temporary buffer in main() and didn't insert any data to it, therefore it can't contain any data. It has nothing to do with the in your form.
     
    If you want data from the form, you need to get the buffer used by the form data source used by the form. You have the form in contractForm variable. Then you can use SysFormDataSource::findDataSource(), for example, to find the data source, and cursor() to get the buffer from the data source.

    Also note that you can't simply refer to a temporary buffer from a batch, because such a memory location with the data won't exists on a batch server. You need to serialize the data in some way.

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,971 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,846 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans