Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Sunday, August 9, 2015

X++ code to delete the employee

Hi,

static void AlfasithDeleteAnEmpl(Args _args)
{
    HcmWorker hcmWorker,hcmWorkerSel;
    HcmEmployment  hcmEmployment,hcmEmploymentSel;
    DirPartyTable  dirPartyTable,dirPartyTableSel;
    DirPerson      dirPerson,dirPersonSel;
    DirPersonName  dirPersonName,dirPersonNameSel;
    DirAddressBookParty  dirAddressBookParty,dirAddressBookPartySel ;
        int n=0;
    ;

     select hcmWorker where  hcmWorker.PersonnelNumber == "000097";
    // If you dont select particular personnel number you can delete complete employees..
    select HcmEmployment where hcmEmployment.Worker == hcmWorker.RecId;
    select dirPerson where dirPerson.RecId ==hcmWorker.Person;
    select dirPartyTable where dirPartyTable.RecId == dirPerson.RecId;
    // deleting the selected records as follows...
    delete_from dirAddressBookParty where dirAddressBookParty.Party == dirPartyTable.RecId;
    delete_from dirPersonNameSel where dirPersonNameSel.RecId == dirPerson.RecId;
    delete_from dirPartyTableSel where dirPartyTableSel.RecId == dirPartyTable.RecId;
    delete_from HcmEmploymentSel where HcmEmploymentSel.RecId == HcmEmployment.RecId;
    delete_from dirPersonSel where dirPersonSel.RecId == dirPerson.RecId;
    delete_from hcmWorkerSel where hcmWorkerSel.RecId == hcmWorker.RecId ;
    n++; // Here I'm Alfasith made n++ for printing the no of deletion in records...
    print n;
    pause;
}

Regards,

No comments:

Post a Comment

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...