Determining DIALSTATUS after executing dial from AGI

Hello everyone. I am an asterisk newbie. Currently I want to dial some number from my AGI server using exec(“Dial”,…) command and I would like to be able to know when no one’s answering the call by checking DIALSTATUS == noanswer.
I have tried transferring the dial command to the dialplan and getting the DIALSTATUS from there but its always empty. I have tried getting the DIALSTATUS in the AGI but it didnt work.


first try:

public void service(AgiRequest request, AgiChannel channel)
exec(“Dial”,“SIP/” + “7004” + “,60,G(from-internal-custom,1301,1)”);

  String dialStatus = request.getParameter("DIALSTATUS");
  exec("NoOp","dial status is = " + dialStatus);    //it is always empty (i think its because the        moment the first dialplan goes to the AGI,DIALSTATUS is not initialized yet since I havent even issued dial command)


second try:

in the dialplan:

exten => 1301,1,NoOp(dial status is = ${DIALSTATUS})
exten => 1301,2,NoOp(dial status is = ${DIALSTATUS})
exten => 1301,3,NoOp(dial status is = ${DIALSTATUS})
exten => 1301,4,NoOp(dial status is = ${DIALSTATUS})

//all of them is empty

so how can I get the value of DIALSTATUS if I issue the dial command from AGI?
thank you so much for the kind answer