Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / COC ,Access to another...
Finance forum
Answered

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

Posted on by 330

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
    Community Member Microsoft Employee 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
    Martin Dráb 225,490 Super User 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
    Community Member Microsoft Employee 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
    WillWU 22,344 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
    Martin Dráb 225,490 Super User 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.

  • 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

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans