How to write the code for greeting the user using X++.
Greeting messages such as Good morning, Good afternoon, Good evening and Good night are used to establish a positive and friendly interaction with anyone. Overall, greeting messages are a simple but effective way to make the user feel welcome, informed, and valued. To write a code for greeting a message in D365FnO using X++, you can use the following code:
class greetingUserJob
{
public static void main(Args _args)
{
// Get the current logged userName from userId
str userName = XUserInfo::find(false, curUserId()).name;
// Get the current timeOfTheDay
int timeOfTheDay = timenow();
if(timeOfTheDay > 0 && timeOfTheDay < (12*60*60)) // 0-12 O'Clock
{
// Display a good morning message with time in hours and user name
info(strFmt("%1 Good Morning %2!",timeOfTheDay/(60*60), userName));
}
else if(timeOfTheDay > (12*60*60) && timeOfTheDay <= (18*60*60)) // 12-18 O'Clock
{
// Display a good afternoon message with time in hours and user name
info(strFmt("%1 Good afternoon %2!",timeOfTheDay/(60*60), userName));
}
else if(timeOfTheDay > (18*60*60) && timeOfTheDay <= (22*60*60)) // 18-22 O'Clock
{
// Display a good evening message with time in hours and user name
info(strFmt("%1 Good evening %2!",timeOfTheDay/(60*60), userName));
}
else // 22-24 O'Clock
{
// Display a good night message with time in hours and user name
info(strFmt("%1 Good night %2!",timeOfTheDay/(60*60), userName));
}
}
}