Tuesday, May 20, 2014

looping through a forms datasource

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);
}




2 comments:

  1. I am using the same approach as described above. I am first applying ranges on my dataset and then iterating through the datasource but I am not getting any record in localRetailCustEmailNotificationLog. If I set a delay of some seconds between execute query and iterating through the dataset I am able t get record in localRetailCustEmailNotificationLog. Please suggest. below is the code snippet.
    queryBuildRange = RetailCustEmailNotificationLog_ds.query().dataSourceNo(1).addRange((fieldNum(RetailCustEmailNotificationLog,EmailMessage)), 1, QueryRangeType::FullText);

    quryValue = '((RetailCustEmailNotificationLog.EmailMessage freetext "' + searchTextValue + '")' + searchString + '|| (RetailCustEmailNotificationLog.EmailSubject like "' + searchTextValue + '") || (RetailCustEmailNotificationLog.ReceiverEmailAddress like "' + searchTextValue + '"))';
    queryBuildRange.value(quryValue);
    RetailCustEmailNotificationLog_ds.executeQuery();

    // if set delay like system.threading.thread(10000). localRetailCustEmailNotificationLog returns record.

    localRetailCustEmailNotificationLog = RetailCustEmailNotificationLog_ds.getFirst() as RetailCustEmailNotificationLog;

    ReplyDelete
  2. Have you tried putting your filter on execute_Query() (of the datasource) then putting the loop within the run method? that way it follows the forms loading sequence and filters your records first then would allow you to loop through the filter records.

    ReplyDelete