This may come in handy as you define different messages for different purposes depending on the functionality you implement. These messages may be in the same message set and each message may require a different number of parameters to be passed in your PeopleCode program.
So in this case and depending on the context it may be good idea to define a function where you pass your message set, message number and parameter list (as a string array) and get the Explain Text or Message Text and display a message to the user.
Here is the example. In this function you can pass populated string array (as &ParmArray) and depending on number of parameters you want to populate in you message you can call this function and return the message text you want.
/* population of a message &MsgSet The message set of the message &MsgId the Message Id, based on the message set &ParmArray the array of parameters for the message specified, if no parameters are needed null can be passed*/ Function messagetoString(&MsgSet As number, &MsgID As number, &ParmArray As array of string) Returns string Local string &messageString = ""; If (&ParmArray <> Null) Then Evaluate &ParmArray.Len When 0 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found"); When 1 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1]); When 2 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2]); When 3 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3]); When 4 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4]); When 5 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5]); When 6 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6]); When 7 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6], &ParmArray [7]); When 8 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6], &ParmArray [7], &ParmArray [8]); When 9 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6], &ParmArray [7], &ParmArray [8], &ParmArray [9]); When 10 &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6], &ParmArray [7], &ParmArray [8], &ParmArray [9], &ParmArray [10]); End-Evaluate; Else &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found"); End-If; Return &messageString; End-function;
Here I used MsgGetText function. Similarly you can use MsgGetExplainText as well.
0 comments :
Post a Comment