53) For looping through a forms datasource in d 365

This will show you how to look through all of the records of a forms data source or just the selected records without affecting what is populated within the data source



How to loop through all records of a datasource with the name of InventTrans



InventTrans                 localInventTrans = InventTrans_DS.getFirst() as InventTrans;
ItemId                      itemId;

while(localInventTrans)
{
  //access fields by using localInventTrans.fieldname
  itemId = localInventTrans.ItemId;

  //get the next record from the datasource
        localInventTrans = InventTrans_DS.getNext() as InventTrans;

}

 
How to loop through ONLY the selected records of a datasource with the name of InventTrans. This could be used if you have a grid and want the user to select only certain records then pass those records to a class, form, method, etc...


InventTrans                 localInventTrans;
ItemId                         itemId;

//get the first selected record of the datasource and loop through all of the selected records
for(localInventTrans = InventTrans_DS.getFirst(true) ? InventTrans_DS.getFirst(true) : InventTrans_DS.cursor(); localInventTrans; localInventTrans = InventTrans_DS.getNext())
{
                   itemId = localInventTrans.ItemId;
                   info(itemId);
}
=================================================================

Second case : -

/// <summary>
/// The <c>AVAEntAssetWorkOrderTableFrm_WorkOrderLineDS_Extension</c> xxxxxxx <c>EntAssetWorkOrderTable</c> form.
/// </summary>
[ExtensionOf(formDataSourceStr(EntAssetWorkOrderTable, WorkOrderLine))]
final class AVAEntAssetWorkOrderTableFrm_WorkOrderLineDS_Extension
{
    /// <summary>
    /// enable / disable the "AVAStandardJobIvaraHistoricalReportLink" menu item on form.
    ///  <returns>
    ///   true false.
    ///   <returns>
    /// </summary>
     public int active()
    {
        int                             ret = true;
        FormRun                         formRun                                 = this.formRun();
        FormControl                     ivaraStandardJobIvaraHistoricalReport   = formRun.design().controlName(formControlStr(EntAssetWorkOrderTable, AVAStandardJobIvaraHistoricalReportLink));
   
        FormDataSource                  workOrderLine_ds = this as FormDataSource;
        EntAssetWorkOrderLine           entAssetWorkLine = workOrderLine_ds.getFirst() as EntAssetWorkOrderLine;

        ret = next active();

        ivaraStandardJobIvaraHistoricalReport.enabled(!ret);

        while(entAssetWorkLine)
        {         
            if(entAssetWorkLine.RefTableId == tableNum(EntAssetRoundTable))
            {
                ivaraStandardJobIvaraHistoricalReport.enabled(ret);
                break;
            }

            entAssetWorkLine = workOrderLine_ds.getNext() as EntAssetWorkOrderLine;
        }
     
        return ret;
    }

}

===================================================================
Example 3 : -

/// <summary>
/// The <c>AVAEntAssetWorkOrderTableFrm_WorkOrderLineDS_Extension</c> xxxxxx <c>EntAssetWorkOrderTable</c> form.
/// </summary>
[ExtensionOf(formDataSourceStr(EntAssetWorkOrderTable, WorkOrderLine))]
final class AVAEntAssetWorkOrderTableFrm_WorkOrderLineDS_Extension
{
    /// <summary>
    /// Determines maintance round in workorderline.
    /// </summary>
    /// <returns>true if one record found, otherwise false.</returns>
     public int active()
    {
        int                             ret = true;
        FormRun                         formRun                                 = this.formRun();
        FormControl                     ivaraStandardJobIvaraHistoricalReport   = formRun.design().controlName(formControlStr(EntAssetWorkOrderTable, AVAStandardJobIvaraHistoricalReportLink));
     
        FormDataSource                  workOrderLine_ds = this as FormDataSource;
        EntAssetWorkOrderLine           entAssetWorkLine = workOrderLine_ds.getFirst() as EntAssetWorkOrderLine;

        ret = next active();

        ivaraStandardJobIvaraHistoricalReport.enabled(!ret);

        while(entAssetWorkLine)
        {           
            if(entAssetWorkLine.RefTableId == tableNum(EntAssetRoundTable))
            {
                ivaraStandardJobIvaraHistoricalReport.enabled(ret);
                break;
            }

            entAssetWorkLine = workOrderLine_ds.getNext() as EntAssetWorkOrderLine;
        }
       
        return ret;
    }

}

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++