Coding best practices to overcome merge conflicts?

In an attempt trying to understand the merge commandlet and dealing with conflicts, I came accross some situations I would like to get some more explanations about the 'why' of these conflict situations.

Example 1 (OnModify Customer)
Original code
...
MODIFY;
CallSyncCodeunit;
FIND;
...
Modified code
...
MODIFY;
CallSyncCodeunit;
CallOtherSyncCodeunit; // Added
FIND;
...
The above would automatically merge without any conflicts, if my target version would remain unchanged. However, if changes are applied to the target version, the modified change can no longer be automatically merged and a conflict is created.

Target code (recent cumulative update)
MODIFY;
CallSyncCodeunit;
IF FIND THEN; // Added IF THEN
If you look at the code on a line by line level, the delta between original / modified is
CallOtherSyncCodeunit; // Added
and the delta between original / target is
IF FIND THEN; // Added IF THEN
So why can't both deltas be applied to the result version?

I'm experiencing several similar conflict situations on changes in the modified / target version on adjacent lines. Are there any best practices to come around these type of conflicts?

Example 2

If the requirement would be not to get the salesperson from the customer, but to get if from the user setup (using a custom field), how would one best integrate this change?

Original code
...
IF Customer.GET("Customer No.") THEN 
  "Salesperson Code":= Customer."Salesperson Code";
...
Modified code
...
IF UserSetup.GET(USERID) THEN
  "Salesperson Code":= UserSetup."Salesperson Code";
...
- Commenting the original code would lead to a conflict if the target code is changed.
- Embedding the original code in a surrounding IF THEN (or via a preceding function) might be an option. In that case, it's advised not to change the indentation I guess?
- Leave the code 'as is' and add the modified code at the end (or via eventing in 2016). This would execute the redundant original code / database calls whereas it's no longer needed.

Comments

Sign In or Register to comment.