4

Is it possible to reply to a MSGW job in AS400 from JT400?
I've got the Job element and I can know if it's in MSGW status by Job.MESSAGE_REPLY_WAITING

Ex: normally I use "C" via WRKACTJOB

LppEdd
  • 20,274
  • 11
  • 84
  • 139

3 Answers3

4

David's correct...but missing a couple steps I think..and note I've not tried this either..

Get the joblog:
Job.getJobLog()

Get the queued messages
JobLog.getMessages

Get the Message Queue
QueuedMessage.getQueue()

Then reply
MessageQueue.reply()

Charles
  • 21,637
  • 1
  • 20
  • 44
  • Tomorrow at work I'll get a MSGW and I'll let you know! – LppEdd Aug 23 '16 at 19:49
  • Mmmh it return null on every MessageQueue! – LppEdd Aug 24 '16 at 12:13
  • @LppEdd, edit your question to include your code...or perhaps post a new question. – Charles Aug 24 '16 at 12:46
  • 1
    The typical approach for a job in MSGW is to inquire of the job, *What is the **message key** to which a reply needs to be sent?* See the QUSRJOBI API, and investigate what the toolbox offers similarly. Essentially, the "joblog" is not the direct approach that normally would be taken with the APIs when performed locally at the server, so likely is also not the expected path when done via the toolbox. – CRPence Aug 24 '16 at 18:06
  • Done it guys! Tomorrow I'll update this post to show you! JobLog isn't needed. – LppEdd Aug 24 '16 at 19:33
  • 1
    @LppEdd , I thought it was a roundabout way...but just browsing through the Javadocs backwards from MessageQueue.reply()...I didn't see a better way. Feel free to post your code as another answer and accept it as the best answer. – Charles Aug 24 '16 at 20:59
2

I haven't actually tried this, but take a look at the reply function in MessageQueue (JTOpen).

David G
  • 3,940
  • 1
  • 22
  • 30
0

This is the code that works. I think it can be shortened and optimized.
There must be a better way!

public boolean answer(String answer) throws MyOperationException {
   if (answer == null || answer.length() > 1) {
      throw new MyOperationException();
   }

   MessageQueue msgq = new MessageQueue(as.getAS400(), QSYSObjectPathName.toPath(MyAS400.LIBRARY_LIST, "QSYSOPR", "MSGQ"));
   msgq.setSelectMessagesNeedReply(true);
   msgq.setListDirection(false);

   try {
      Enumeration m = msgq.getMessages();

      while (m.hasMoreElements()) {
         QueuedMessage msg = (QueuedMessage) m.nextElement();

         if (msg.getFromJobNumber().trim().equals(getNumber())) {
            msgq.reply(msg.getKey(), answer);

            return true;
         }
      }
   } catch (AS400SecurityException | ErrorCompletingRequestException | InterruptedException | IOException | ObjectDoesNotExistException ex) {
      ex.printStackTrace();
   }

   return false;
}

If you don't know the message queue, you can use ObjectList.

LppEdd
  • 20,274
  • 11
  • 84
  • 139