Relocation of Employee

zulqzulq Member Posts: 204
Hi,
Got an employee table and other dependent tables example of which is payments. The problem is that some employees are registered twice with different employee numbers and they have multiple payments on the payments table with both employee numbers.
Now I want:
1. form which will select all employee numbers -no problem doing this.
2. Give user options to choose which account to use as the correct account -no problem doing this also.
3. Give user options to select all tables on which the rename will be applied.-Need help on this.

Any ideas please?
Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?

Answers

  • klavinklavin Member Posts: 117
    If you are looking for table relations from your employee table, you can use the Field table as a reference; where the "Relation TableNo" = your table ID, and use this for your list.

    There are some ways of "merging" accounts by deleting one record and renaming the other into it; but obviously this is pretty dangerous if you make a mistake, as it can't be reversed... it's not in my opinion recommended.

    I'm not sure I completely understand the question though, more than likely it is because I'm having a case of the monday's...
    -Lavin
    "Profanity is the one language all programmers know best."
  • DaveTDaveT Member Posts: 1,039
    Hi,

    Try this and if it work manually then you can code it, as it will depend in the table relations:

    e.g. Employee A and B are the duplicates and you want to keep Employee A

    1. Delete Employee A master record :!: (without running the ONDELETE trigger)
    2. Rename Employee B to employee A ( which should rewrite the depending data)

    This assumes that the master record for A and B are the same.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • zulqzulq Member Posts: 204
    Hi DaveT,
    the problem with your approach is that when A is deleted all of A's corresponding transactions will be deleted. As a result the renaming has to take place first then delete the unwanted record i.e. in this instance A.
    I want an option to select all tables the user wants the rename to be applied. Rename the transactions on those tables and then deleted A if user wants to.
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • DaveTDaveT Member Posts: 1,039
    Hi
    DaveT wrote:
    Delete Employee A master record (without running the ONDELETE trigger)

    You will find that the transactions are deleted in the ONDELETE trigger on the master record. If this is by-passed (either temporarily comment out the code or use DELETE( FALSE ) ) you should be ok.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • zulqzulq Member Posts: 204
    Hi,
    Got it working now but want the details of A to maintain instead losing them since that will be the employee to keep.
    To be more precise I can delete A with all details and rename B to A. However the details of A has to be maintained as that is the ID maintain

    Any ideas please?
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • DaveTDaveT Member Posts: 1,039
    Hi,

    Before the delete of A transfer the details to B and modify the record. This will overwrite B and after the rename A will look unchanged.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • zulqzulq Member Posts: 204
    Is there any way I can copy all the field values or assign them without having to do it statically.
    I want it done in a way that if a new field is added to the table I don't need to update the code.
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • DaveTDaveT Member Posts: 1,039
    Hi,

    Yes, simply save the employee B code then use
    EmpBRec := EmpARec;
    EmpBRec.code := SavedCode;

    Where EmpBRec and EmpARec are variables of type record.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • zulqzulq Member Posts: 204
    Hi DaveT below is my code but it's not working. EmpRecB is not being updated with the fields of EmpRecA
    empRecA.SETCURRENTKEY("No.");
    empRecB.SETCURRENTKEY("No.");
    empRecA.SETRANGE("No.",OldNumberToMaintain);
    empRecB.SETRANGE("No.",NewNumberToChange);
    
    IF empRecA.FIND('-') AND empRecB.FIND('-') THEN BEGIN
    empRecB := empRecA;
    empRecB.MODIFY(TRUE);
    END;
    
    IF empRecA.FIND('-') THEN BEGIN
    empRecA.DELETE;
    END;
    
    
    IF empRecB.FIND('-') THEN BEGIN
    empRecB.RENAME(OldNumberToMaintain);
    END;
    
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • DaveTDaveT Member Posts: 1,039
    Hi,

    Yuo forgot
    DaveT wrote:
    EmpBRec.code := SavedCode;

    or in your code it will be
    EmpBRec.code := NewNumberToChange;
    before the modify.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • zulqzulq Member Posts: 204
    Thanks DaveT, it's working now.
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • DaveTDaveT Member Posts: 1,039
    Glad to Help :mrgreen:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
Sign In or Register to comment.