Skip to main content

Notifications

Community site session details

Community site session details

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

COC ,Access to another data source from init data source method on form

(0) ShareShare
ReportReport
Posted on by 332

Hello..

form has two data sources, I created a class Extended the form data source init method using the COC, and added some ranges ,also I need to access the other data source in the form ,to know the active record

Thanks all .

  • Community Member Profile Picture
    on at
    RE: COC ,Access to another data source from init data source method on form

    Thanks Martin, I've updated the code.

  • Martin Dráb Profile Picture
    232,858 Most Valuable Professional on at
    RE: COC ,Access to another data source from init data source method on form

    I've seen this pattern in vendor's code and I don't understand it's purpose:

    FormDataObject          formDataObject = any2Object(this) as FormDataObject;

    Why don't you simply refer to 'this'?

    any2Object() isn't useful, because 'this' already is an object instance.

    'as FormDataObject' doesn't look useful either. No casting isn't needed, AFAIK, and we also don't need to check whether the current object has the right type.

  • Community Member Profile Picture
    on at
    RE: COC ,Access to another data source from init data source method on form

    Hi Ahmed

    I see this is an old post, but just in case it helps someone else ... 

    I had a similar requirement where I had to access datasource 1 (let's call it that), whilst extending the 'modified' field on datasource 2. This is the code I used to achieve this:

    public void modified()
    {
        FormDataSource  dataSource2 = this.datasource();
        
        next modified();
    
        QueryRun queryRun = dataSource2.queryRun();
        Table1 table1 = queryRun.get(tableNum(Table1));
    
    }

  • Verified answer
    WillWU Profile Picture
    22,352 on at
    RE: COC ,Access to another data source from init data source method on form

    Hi Ahmed Osama,

    The code "FormDataSource     smmBusRelTable_ds = this.formRun().dataSource(formDataSourceStr(PurchEditLines, PurchParmUpdate));" doesn't make any sense here.

    You could try to use OnInitialized eventhandler of your formdatasource.

  • Verified answer
    Martin Dráb Profile Picture
    232,858 Most Valuable Professional on at
    RE: COC ,Access to another data source from init data source method on form

    You're in init() method - no data has been loaded from database at this point. Loading of data happens later, after the data source is initalized and executeQuery() gets called. That's why the table buffer is always at this point.

  • Ahmed Osama Ibrahim Profile Picture
    332 on at
    RE: COC ,Access to another data source from init data source method on form

    Same issue , can't access to the other DS

    [ExtensionOf(formdatasourcestr(PurchEditLines, InventDim))]
    final class BT_PurchEditLines_Form_Extension
    {
        public void init()
        {
            QueryBuildDataSource    qbds,qbdsUser,qbdsLocation,qbdsInventDim;
            PA_WarehousesUsers      PA_WarehousesUsers;
            InventLocation          inventlocation;
            PurchParmUpdate PurchUpdate;
            PurchUpdate     qty;
    
            FormDataSource     smmBusRelTable_ds = this.formRun().dataSource(formDataSourceStr(PurchEditLines, PurchParmUpdate));
            PurchUpdate = smmBusRelTable_ds.cursor();
    
            next init();
            
    
            str user = curUserId();
            
    
            select PA_WarehousesUsers where PA_WarehousesUsers.UserId == user;
    
            if(PA_WarehousesUsers )//&& purchParmUpdate.SpecQty == PurchUpdate::PackingSlip)
            {
                qbds = this.query().dataSourceTable(tableNum(InventDim));
    
                qbdsUser = qbds.addDataSource(tableNum(PA_WarehousesUsers));
                qbdsUser.addLink(fieldNum(PA_WarehousesUsers, InventLocationId), fieldNum(InventDim, InventLocationId));
                qbdsUser.addRange(fieldnum(PA_WarehousesUsers, UserId)).value(queryValue(user));
    
            }
        }
    
    }

    6862.error.png

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,069 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,858 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans