Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to create notification alert for employee and its supervisor for expire employee contract D365 X++ batch job

Posted on by 17

My requirement is to send notification alert to employee and its supervisor that the employee contract expire within a few days
I have created a class and get employee and its supervisor but looking for the notification syntax who fit in my scenario

here is my code and  i want to notify the employee and its supervisor
Guide me
thanks in advance

internal final class notification_SYNPR
{
    /// 
    /// Class entry point. The system will call this method when a designated menu 
    /// is selected or when execution starts and this class is set as the startup class.
    /// 
    /// The specified arguments.
    public static void main(Args _args)
    {
        HcmPositionWorkerAssignment  HcmPositionWorkerAssignment,HcmPositionWorkerAssignmentloc;
        HRMParameters                HRMParameters,HRMParametersloc;
        HcmPosition                  HcmPosition,HcmPositionloc;
        HcmPositionHierarchy         hcmPositionHierarchy,hcmPositionHierarchyloc;
        HcmWorker                    hcmWorker,hcmWorkerloc;
        DirPerson                    dirPerson,dirPersonloc;
        DirPartyTable                DirPartyTable,DirPartyTableloc;
        LogisticsElectronicAddress   logisticsElectronicAddress,logisticsElectronicAddressloc;
        utcDateTime                  rangeStart, rangeEnd;
        date                         startDate, endDate;
        TimeOfDay                    startTime, endTime;
        SYNPR_SendNotification       sendmail;
        EmailBase                    emailId;
        SysEmailTable                sysEmailTable;
        Map      mappings            = new Map (Types::String, Types::String);
        List strlist                 = new List(Types::String);
        ListIterator                 iterator;
        EventInbox                   EventInbox;
        SysUserInfo                  SysUserInfo;
        str   _strtoSplit,_delimiter,forTag,_mailsubject,_mailBody,_recieveraddress,employeemail,senderemail;
        System.Exception  e;
        SysEmailSystemTable             sysEmailSysTable;
        sysEmailSysTable = SysEmailSystemTable::find("D365");
        sendmail = new SYNPR_SendNotification();
        select firstonly HRMParameters;
        
        Timezone userTimeZone  = DateTimeUtil::getUserPreferredTimeZone();
        employeemail = 'mian55028@gmail.com';
        senderemail = 'usama.mansaib02@gmail.com';
        //for range on table to filter records

        startDate   = today()   HRMParameters.ContractEndDate;       // day\month\year
        endDate     = today()   HRMParameters.ContractEndDate;       // day\month\year
        startTime   = str2time("00:00:00 am");
        endTime     = str2time("23:59:59 pm");
        rangeStart = DateTimeUtil::newDateTime(startDate,startTime,DateTimeUtil::getUserPreferredTimeZone());

        rangeEnd   = DateTimeUtil::newDateTime(endDate,endTime,DateTimeUtil::getUserPreferredTimeZone());

        while select * from HcmPositionWorkerAssignment
        where (HcmPositionWorkerAssignment.ValidTo >= rangeStart
         && HcmPositionWorkerAssignment.ValidTo <= rangeEnd)
        {
            select * from hcmWorker
             where hcmWorker.RecId == HcmPositionWorkerAssignment.Worker
            join dirPerson
             where dirPerson.RecId == hcmWorker.Person
            join dirPartyTable
             where dirPartyTable.RecId == dirPerson.RecId
            join logisticsElectronicAddress
                where dirPartyTable.PrimaryContactEmail == logisticsElectronicAddress.RecId;

            // supervisor
            select * from hcmPositionHierarchy
            where  hcmPositionHierarchy.Position == HcmPositionWorkerAssignment.Position
            join HcmPositionloc
            where HcmPositionloc.RecId == hcmPositionHierarchy.ParentPosition
            join HcmPositionWorkerAssignmentloc
            where  HcmPositionWorkerAssignmentloc.Position == HcmPositionloc.RecId
            join hcmWorkerloc
             where hcmWorkerloc.RecId == HcmPositionWorkerAssignment.Worker
            join dirPersonloc
             where dirPersonloc.RecId == hcmWorkerloc.Person
            join DirPartyTableloc
             where DirPartyTableloc.RecId == DirPartyTableloc.RecId
            join logisticsElectronicAddressloc
             where DirPartyTableloc.PrimaryContactEmail == logisticsElectronicAddressloc.RecId;
 
           // select SysUserInfo order by SysUserInfo.Id where SysUserInfo.Id!= curUserId();
            //while select maxof(inboxId) from inbox where
            {
               // select maxof(inboxId) from inbox;
                EventInbox.initValue();

                //EventInbox.AlertTableId                   = tablenum(Address);
                //EventInbox.AlertFieldId                   = fieldnum(Address, Name);
                //EventInbox.TypeTrigger                    = EventTypeTrigger::FieldChanged;
                EventInbox.SendEmail                        = false;
                EventInbox.TypeId                           = classnum(EventType);
                EventInbox.CompanyId                        = curext();
                EventInbox.InboxId                          = EventInbox::nextEventId();
                EventInbox.AlertCreatedDateTime             = DateTimeUtil::getSystemDateTime();
                EventInbox.IsRead                           = NOYES::No;
                EventInbox.Subject                          = "Worker Contract";
                EventInbox.AlertedFor                       = "Contract Expiry Alert";
                EventInbox.UserId                           = curUserId();
                EventInbox.ShowPopup                        = NOYES::Yes;
                EventInbox.Visible                          = NOYES::Yes;
                EventInbox.Message                          = strfmt("%1 your contract has been expire",HcmWorker::find( HcmPositionWorkerAssignment.Position).name());
                EventInbox.insert();
            }
        }
  }

}

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: How to create notification alert for employee and its supervisor for expire employee contract D365 X++ batch job

    Hi Usama,

    You need to pass the employee userId and its supervisor user id to the EventInbox Table.

    I think you need to insert record into EventInbox table 2 times - One for the employee and other for the supervisor.

    To get the userId for the worker you can refer to the table "DirPersonUser" - This table will have field named "PersonParty"  which will be linked to the field named "Person" in the HcmWorker table.

    You can join this table and get the field "User" from the "DirPersonUser" table.

    Thanks,

    Girish S.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans