Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / To pass the range on t...
Finance forum
Answered

To pass the range on the form using caller form record

Posted on by 1,437
 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 .
 
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,437 on at
    To pass the range on the form using caller form record
    hi 
    Martin thanks for reply ,
    I have put the execute query in last of my code now my range is getting applied to the form i have removed 
    "inventSiteFieldId = inventDimFormSetup.callerInventSiteFieldId();" from my code as it is blank , now code is working fine ,
     
     
    Thanks,
    Regards,
    Dinesh
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 223,760 Super User on at
    To pass the range on the form using caller form record
    There are many problems in your code. First of all, you change the query after it was already executed. I'm pretty sure you want to modify the query before it executes, therefore you need to do it before calling next executeQuery().
     
    Refering to currectly selected records just after executing the query is suspicous at least. I think it's a bug; think it through once more and if it makes sense to yo, please share your reasoning with us.
     
    Instead of all the extra queries to database, you should add joins to the actual query.
     
    You again made a  mistake by trying to do many things at once without ever testing whether even the basic things work. Now you have no idea what's going on. Instead, start simple. For example, test that you can add a single range with a hard-coded value. If you did it, you'd have found that you call next executeQuery() at the very beginning. You'd have fixed it, added one more step, test it, and so on. You wouldn't have ended up with so bad code and without any idea what to do.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,437 on at
    To pass the range on the form using caller form record
    hi i have debugged the code the range is getting applied to the form but still the form is not opening , i will share the standard form code and below that my extension code is there plz let me know what i am doing wrong .
      [DataSource]
        class InventLocation
        {
            void executeQuery()
            {
                QueryBuildDataSource    qbdsInventLocation;
                DictRelation            dr;
                Counter                 i;
                FormDataSource          callerFormDatasource;
                DictType                dt;
                ExtendedTypeId          extendedTypeId;
                FieldId                 inventSiteFieldId;
                Common                  cursor;
    
                //if queryRun object is created use query from it
                //this allows to modify query that is used in filtered lookups
                if (this.queryRun())
                {
                    qbdsInventLocation = this.queryRun().query().dataSourceTable(tableNum(InventLocation));
                }
                else
                {
                    qbdsInventLocation = this.query().dataSourceTable(tableNum(InventLocation));
                }
    
                inventSiteFieldId = inventDimFormSetup.callerInventSiteFieldId();
    
                qbdsInventLocation.clearDynalinks();
    
                if (inventSiteFieldId)
                {
                    cursor = inventDimFormSetup.callerInventSiteIdCursor();
    
                    if (cursor.TableId != tableNum(Common) && cursor.(inventSiteFieldId))
                    {
                        qbdsInventLocation.addDynalink(
                            fieldNum(InventLocation,InventSiteId),
                            cursor,
                            inventSiteFieldId);
                    }
                }
    
                FormStringControl ctrl = element.selectTarget() as FormStringControl;
                if (ctrl)
                {
                    extendedTypeId = ctrl.extendedDataType();
                    if (extendedTypeId)
                    {
                        dt = new DictType(extendedTypeId);
                        dr = dt.relationObject();
                    }
                    else
                    {
                        callerFormDatasource    = inventDimFormSetup.callerFormDatasource();
                        if (callerFormDatasource)
                        {        
                            dr = new DictRelation(callerFormDatasource.table());
                            dr.loadFieldRelation(ctrl.dataField());
                        }
                    }
                }
                if (dr)
                {
                    for (i=1;i<=dr.lines();i++)
                    {
                        switch (dr.lineType(i))
                        {
                            case TableRelation::ExternFixed:
                                qbdsInventLocation.addRange(dr.lineExternTableValue(i)).value(queryValue(dr.lineTableValue(i)));
                                break;
                        }
                    }
                }
    
                super();
            }
    my extension code is below ,
    [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;
            FieldId         inventSiteFieldId;
    
            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,",");
                inventSiteFieldId = inventDimFormSetup.callerInventSiteFieldId();
                qdbs = this.query().dataSourceTable(Tablenum(InventLocation));
               
                qdbs.addRange(fieldnum(InventLocation, InventLocationId)).value(invLocationId);
            }
        }
    
    }
    thanks, 
    Regards,
    Dinesh
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,502 Super User on at
    To pass the range on the form using caller form record
    It is not required to explicitly call executequery on init and it goes with sequence of method call and executequery will be called by standard. 
     
    If your form is not getting opened, then you need to give us more details like if you are getting some error or details of customisations you did for that form or about the data etc so that we will be able to narrow down the issue and can resolve it.
     
    Debug the code and understand it more. 
  • Waed Ayyad Profile Picture
    Waed Ayyad 2,689 on at
    To pass the range on the form using caller form record
    Hi,
     
    Can you share your code and what the error you're getting?
     
     
    Thanks,
    Waed Ayyad 
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,437 on at
    To pass the range on the form using caller form record
    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 
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 4,565 User Group Leader on at
    To pass the range on the form using caller form record
    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
    Dineshkarlekar 1,437 on at
    To pass the range on the form using caller form record
    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 
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,437 on at
    To pass the range on the form using caller form record
    [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);
            }
        }
    }
    
     
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 2,689 on at
    To pass the range on the form using caller form record
    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
     

Helpful resources

Quick Links

Contextual content recommendations & SharePoint Q&A

Instantly access relevant sales materials…

Beyond the DRA Cloud Label Printing

Explore cloud-based label printing within Dynamics 365…

HR Infrastructure Customer merge

Important considerations for HR Customer migrations…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,418 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,760 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,142

Featured topics

Product updates

Dynamics 365 release plans