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

SQL code to upate one Legal entity banner to all the legal entity in D365

 Hi, update companyimage set  companyimage.Image  = companyimageA.Image  from  ( select Image from companyimage where dataAreaid = 'USF...