web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

To pass the range on the form using caller form record

(2) ShareShare
ReportReport
Posted on by 1,836
 hi every one  i was trying to filter the inventlocationid lookup form by passing the range of caller but i am not able to pass the args to the form can u please suggest me how can i get it done below is my code .
 
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    class DTInventlocationidlookupEventhandler
    {
      
    
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormEventHandler(formStr(InventLocationIdLookup), FormEventType::PostRun)]
        public static void InventLocationIdLookup_OnPostRun(xFormRun sender, FormEventArgs e)
        { 
            Args         args = new args(formstr(InventLocationIdLookup));
          
            Container    LocationId;
            FormRun      formRun = sender;
            FormRun      callerForm = sender.args().caller();
            //TableId     callerTableId    = sender.args().dataset();
            //common         common      = sender.args().record();
    
            FormDataSource  SalesLine_ds,InventDim_ds,SalestableInventDim_ds;
            UserId           userId = curUserId();
            DTUserInfo       dtUserInfo;   
            InventLocation   inventLocation;
            DTSalesTransactionAccess         salesTranAccess,salesTranAccess1;
            InventDim                        inventDim,inventDimLoc;
            var overrideds = new DTInventlocationidlookupEventhandler();
    
           // InventDim_ds = formRun.dataSource(formDataSourceStr(InventLocationIdLookup, InventDim));
            SalesLine_ds = callerForm.dataSource(formDataSourceStr(SalesTable, SalesLine));
            SalestableInventDim_ds = callerForm.dataSource(formDataSourceStr(SalesTable, InventDim));
           
            SalesLine    salesLine = SalesLine_ds.cursor();
                         inventDim = SalestableInventDim_ds.cursor();
            select firstonly InventLocation
                where inventLocation.InventLocationId == inventDim.InventLocationId;
    
            args.record(InventLocation);
           formrun = classfactory.formrunclass(args);
            ;
            select firstonly  salesTranAccess
                where salesTranAccess.UserId == userId
                && salesTranAccess.Stock == NoYes::Yes
                && salesTranAccess.inventLocationId == inventDim.InventLocationId
                && salesTranAccess.UserId == salesLine.CreatedBy;
    
            if( salesTranAccess.RecId != 0 )
            {
                while select * from salesTranAccess
                where salesTranAccess.UserId == userId
                  && salesTranAccess.Stock == NoYes::Yes
                {
                    LocationId += salesTranAccess.inventLocationId;
                }
                str   invLocationId = con2Str(LocationId,",");
               
               formRun.query().dataSourceName(formDataSourceStr(InventLocationIdLookup,InventLocation )).addRange(fieldNum(InventLocation, InventLocationId)).value(invLocationId);
              // InventDim_ds.query().dataSourceTable(Tablenum(InventLocation)).addRange(fieldnum(InventLocation, InventLocationId)).value(invLocationId);
               
            }
        }
    
    }
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,801 Super User 2026 Season 1 on at
    Hi @Dineshkarlekar,
     
    in this case i think you must use COC instead of event handler.
    you must create a datasource extension
    try this
    [ExtensionOf(formDatasourceStr(InventLocationIdLookup, InventLocation))]
    final class InventLocationIdLookup_InventLocationDS_Extension
    {
        public void executeQuery()
        {
    		QueryBuildDataSource		qdbs;
            next executeQuery();
    
    		qdbs = this.query().dataSourceTable(Tablenum(InventLocation));
            // your code
            qdbs.addRange(fieldnum(InventLocation, InventLocationId)).value(...);
        }	
    }
    Best regards,
    Mohamed Amine MAHMOUDI
  • Dineshkarlekar Profile Picture
    1,836 on at
    the reason of using event handler is caller form is different , if this gets form gets call from purchline the how can i will be appling the condition do i have to make different coc for purchline also , i am getting caller form caller ds bu my range is not getting applied on form .
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Your code doesn't make any sense to me. For filtering purpose you need to use either init or executequery of the form datasource. In these methods you need to get the caller form and perform the next steps. 
  • Suggested answer
    Waed Ayyad Profile Picture
    9,100 Super User 2026 Season 1 on at
    Hi Dinesh,
     
    Try to trace the code and see when the code is executed. What is the result of your code? Does the lookup open as usual without any filters? Or you got an error?
     
    After you try your code tell us the result, then we can check the next options.
     
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    [ExtensionOf(formDatasourceStr(InventLocationIdLookup, InventLocation))]
    final class DTInventLocationIdLookup_InventLocationDS_Extension
    {
        public void executeQuery()
        {
            QueryBuildDataSource		qdbs;
            next executeQuery();
            FormRun    formrun = this.formRun().args().caller();
    
            FormDataSource  SalesLine_ds,InventLocation_ds,SalestableInventDim_ds;
            UserId          userId = curUserId();
            DTUserInfo      dtUserInfo;
            InventLocation  inventLocation;
            DTSalesTransactionAccess         salesTranAccess,salesTranAccess1;
            Common          common;
            InventDim       inventDim;
            Container       LocationId;
    
            common = formrun.dataSource(formDataSourceStr(SalesTable, SalesLine)).cursor();
            inventDim = formrun.dataSource(formDataSourceStr(SalesTable, InventDim)).cursor();
    
              select firstonly inventLocation
                 where inventLocation.InventLocationId == inventDim.InventLocationId;
               ;
                select firstonly  salesTranAccess
                   where salesTranAccess.UserId == userId
                    && salesTranAccess.Stock == NoYes::Yes
                    && salesTranAccess.inventLocationId == inventDim.InventLocationId
                    && salesTranAccess.UserId == common.CreatedBy;
    
               if( salesTranAccess.RecId != 0 )
            {
                while select * from salesTranAccess
                   where salesTranAccess.UserId == userId
                     && salesTranAccess.Stock == NoYes::Yes
                {
                    LocationId += salesTranAccess.inventLocationId;
                }
                str   invLocationId = con2Str(LocationId,",");
    
                qdbs = this.query().dataSourceTable(Tablenum(InventLocation));
                // your code
                qdbs.addRange(fieldnum(InventLocation, InventLocationId)).value(invLocationId);
            }
        }
    }
    
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    i have made the coc of the execute query method do i have to call it in init method of form ,
    how can i call it in init of form .please let me know 
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,801 Super User 2026 Season 1 on at
    Hi @Dineshkarlekar,
     
    to call executeQuery from init method of form;
    [ExtensionOf(formStr(InventLocationIdLookup))]
    final class InventLocationIdLookup_Extension
    {
       void init()
       {
          next init();
          InventLocation_ds.executeQuery();
       }
    }
    Best regards,
    Mohamed Amine MAHMOUDI
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi my execute query method is getting hit but without getting call the init method but the another issue is there due to which form is not opening 
     
  • Waed Ayyad Profile Picture
    9,100 Super User 2026 Season 1 on at
    Hi,
     
    Can you share your code and what the error you're getting?
     
     
    Thanks,
    Waed Ayyad 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 689

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 258 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans