Monday, March 5, 2018

Loop through all the records on a form in D365O

Below sample code can be used to loop through all the records on a form in D365O

Assuming that we want to infolog a field value for all the records on the screen on the click of a button.

Step 1: Create a new class
Step 2: Add the below code which should be called on the click of the button and info the required field details

static class Test_LoopThruRecords_Extension
{
    /// <summary>
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(InventItemOrderSetup, Test_BtnLoopThruRecords), FormControlEventType::Clicked)]
    public static void Test_BtnLoopThruRecords_OnClicked(FormControl sender, FormControlEventArgs e)
    {        
        FormDataSource              InventItemPurchSetup_ds  = sender.formRun().dataSource("InventItemPurchSetup"); //DataSource form InventItemPurchSetup

        InventItemPurchSetup        localInventItemPurchSetup = InventItemPurchSetup_ds.getFirst() as InventItemPurchSetup;


        if(localInventItemPurchSetup)
        {
            while(localInventItemPurchSetup)
            {
                    info(localInventItemPurchSetup.FieldName);
             
                localInventItemPurchSetup = InventItemPurchSetup_ds.getNext() as InventItemPurchSetup;
            }
        }


Cheers!

2 comments:

  1. Techlancers Middle East is a digital transformation company in Dubai helping organizations reshape their future through technology. We focus on streamlining operations, integrating smart solutions, and building digital strategies that drive real business results. From legacy system upgrades to end-to-end automation, we empower businesses to adapt, grow, and lead in a digital-first world.

    ReplyDelete
  2. Interesting post and visit CMOLDS a leading and authentic web development service company in dubai.

    ReplyDelete