Skip to main content
Dynamics 365 Community / Forums / Finance forum / Get all the records in...
Suggested answer

Get all the records in grid for iteration

editSubscribe (0) ShareShare
ReportReport
Posted on by 62
Hi I am facing a issue while running my validation on EcoResCategoryAddProduct form. I have added the code at closedOk method but it selects only first product from the selected grid  but it actually should iterate for loop for all the products in selected product grid as u can see in below image it is throwing error for first product which ideally should should validate all the records from the selected grid
 

How do I change my for loop, to get all the records from selected grid?
 
Also how to do the db refresh?
 public void closeOk()
    {
        FormRun         callerForm = this.args().caller();
        EcoResProduct           selectedProduct;
        EcoResProductCategory   tmpEcoResProductCategory;
        EcoResProductCategory   existingEcoResProductCategory;
        container       productErrorMessages;
        if (callerForm && this.args().Caller().name() == formStr(EcoResCategory))
        {
            EcoResCategory ecoResCategory = callerForm.dataSource(formDataSourceStr(EcoResCategory, EcoResCategory)).cursor() as EcoResCategory;
            for ( selectedProduct = EcoResProductSelected_ds.getFirst(1)?EcoResProductSelected_ds.getFirst(1):EcoResProductSelected_ds.cursor();
            selectedProduct;
            selectedProduct = EcoResProductSelected_ds.getNext())
            {
                productErrorMessages += this.checkGroup(selectedProduct, ecoResCategory);
            }
            if(productErrorMessages != conNull())
            {
                throw error (strfmt(/@SYS82282/, productErrorMessages));
            }
        }
        next closeOk();
    }