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, ...
Suggested Answer

avoid repeated code

(0) ShareShare
ReportReport
Posted on by 172
Hi,

Isn't there a way to not repeat code for table1 and 2? the fields are the same, it's just that i want to fill the contract based on type.
There is also more common fields, but just wrote some for the sake of the question

if there is a way to somehow say
common = salesTable or projTable
then directly poss common and repeat code once..is the only way to create a map?
    private void method1(Table1 _table1, Table2 _table2, ContractClass1 _contractClass1)
    {
        UnknownNoYes enumValue;

        if (_table2 && _table1.Type == Enum1::A)
        {
            _contractClass1.parmPurchOrderFormNum(_table2.PurchOrderFormNum);
            _contractClass1.parmField1(str2Enum(enumValue, enum2Value(_table2.Field1)));
            _contractClass1.parmField2(str2Enum(enumValue, enum2Value(_table2.Field2)));
            _contractClass1.parmField3(str2Enum(enumValue, enum2Value(_table2.Field3)));
            _contractClass1.parmMainContactName(_table2.Name);
            _contractClass1.parmMainContactPhone(_table2.Phone);
            _contractClass1.parmMainContactEmail(_table2.Email);
            
  
        }
        else if (_table1.Type == Enum1::B)
        {
            _contractClass1.parmPurchOrderFormNum(_table1.PurchOrderFormNum);
            _contractClass1.parmField1(str2Enum(enumValue, enum2Value(_table1.Field1)));
            _contractClass1.parmField2(str2Enum(enumValue, enum2Value(_table1.Field2)));
            _contractClass1.parmField3(str2Enum(enumValue, enum2Value(_table1.Field3)));
            _contractClass1.parmName(_table1.Name);
            _contractClass1.parmPhone(_table1.Phone);
            _contractClass1.parmEmail(_table1.Email);
        }
    }
 
Categories:
I have the same question (0)
  • Suggested answer
    Anton Venter Profile Picture
    20,674 Super User 2026 Season 1 on at
    Hi,
     
    If you want to reduce the number of lines of your code, the way to go is to create a table Map. You will be then able to cast your two tables to the table Map containing the common fields and access the the common fields in the map object.
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    303,988 Super User 2026 Season 1 on at
    Hi,

    You can achieve it in the next way in case the field names are exactly the same in both tables. I only don't know what exactly is being evaluated using the value of table1.type. The common variable can receive the buffer of any table.
     
    private void method1(Common _common, ContractClass1 _contractClass1)
    {
        UnknownNoYes enumValue;
    
        _contractClass1.parmPurchOrderFormNum(_table2.PurchOrderFormNum);
        _contractClass1.parmField1(str2Enum(enumValue, enum2Value(common.(fieldName2Id(_common.TableId, "Field1"))));
        _contractClass1.parmField2(str2Enum(enumValue, enum2Value(common.(fieldName2Id(_common.TableId, "Field2"))));
        _contractClass1.parmField3(str2Enum(enumValue, enum2Value(common.(fieldName2Id(_common.TableId, "Field3"))));
        _contractClass1.parmMainContactName(common.(fieldName2Id(_common.TableId, "Name"))));
        _contractClass1.parmMainContactPhone(common.(fieldName2Id(_common.TableId, "Phone"))));
        _contractClass1.parmMainContactEmail(common.(fieldName2Id(_common.TableId, "Email"))));
    }

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 653

#2
André Arnaud de Calavon Profile Picture

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

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 317 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans