cancel
Showing results for 
Search instead for 
Did you mean: 

How to invoke the MII URL(calling MII transaction) in background on click Post button from UI in javascript

0 Kudos

Hi All,

I need to invoke the MII URL in background i.e. asynchronously on click of post post button from UI. I am having the URL in below format which call a MII transaction and send the data to ECC and put the acknowledgement in Queue through QueuePut action block.

URL - http://<server>:<port>/XMII/Runner?Transaction=<MY-FOLDER>/LongRunningTransaction&IsAsync=true

So my target is that when user click on Post button from UI screen it call the above URL in background, so that JavaScript code never get hold.

Please send me some code patch or examples.

Thanks,

Ritim

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ritim,

  There are more than one way to call a transaction asynchronously from UI.

1. JQuery Ajax call. for example,

$.ajax({
  type
: "POST",
  url
: "/XMII/Runner?transaction=transactionPath",
  data
: "{name1:value1, name2:value2}",
  dataType: "xml",
  success
: function(result) {
  //code

  
}
);

By default, its asynchronous. Here data is your name value pairs of input parameters to the transaction. note, you need to import jQuery library in your html page for this to work. jQuery Install

Refer:: jQuery.ajax() | jQuery API Documentation

2. Using JavaScript's XMLHTTPRequest Object:: XML DOM - HttpRequest object . Just pass the parameter true in the open(method, url, isAsync) method.

3. The last I could think of is by posting a message to MII. MII internally invokes the transaction asynchronously. All you have to do is post a message to MI with data in the form of an XML.

Then you would create a processing rule that would define which transaction to execute on receipt of that message.

The URL to post a message is

http://<server>:<port>/XMII/Illuminator?service=WSMessageListener&mode=WSMessageListenerServer&NAME=<UniqueMessageName>&InputParamName=InputXML


Refer:Message Listeners - SAP Documentation

All the above methods will not stop your JavaScript from executing. All are asynchronously called. It ultimately boils down to how you want to achieve. The last method though a little complex, gives better visibility in terms of monitoring. The second one is the simple and is supported by almost all browsers with no additional resource. The first one is what I mostly use. Its easy, works as expected but you would have to import the library.

Regards

Tufale Ashai.

0 Kudos

Hi Tufale,

Thanks a lot for your response...

I can not use 1st option as i have to revamp lot of production code. So to currently resolve the issue 2nd option is appropriate.

I have tired a lot to find some example to use JavaScript's XMLHTTPRequest Object:: XML DOM - HttpRequest object  but nothing help. It would be great help if you can send me some example or some code patch for reference.

Thanks,

Ritim

Former Member
0 Kudos

Hi Ritim,

   You could check Using the XML HTTP Request object , XMLHttpRequest object and Using XMLHttpRequest - Web API reference | MDN . The basic syntax is as follows

Say you have a button with an onClick action calling post() method

<!DOCTYPE HTML>

<HTML>

<HEAD>

          <TITLE>Your Title Here</TITLE>

          <META http-equiv="X-UA-Compatible" content="IE=edge">

          <META http-equiv='cache-control' content='no-cache'>

          <META http-equiv='expires' content='0'>

          <META http-equiv='pragma' content='no-cache'>

           <SCRIPT language="JavaScript">

                function post(){

                 var xmlHttp = new XMLHttpRequest(); //create req object. Note it could be different for IE lower than 7

                var url = "/XMII/Runner?Transaction=Default/Transactions/Test"; //build your URL

               xmlHttp.open("GET",url,true); //create the connection

               xmlHttp.onreadystatechange=function() {

                 if (xmlHttp.readyState==4) {

                  alert(xmlHttp.responseText);

                 }

                }

              xmlHttp.send();  //send the request

             }

          </SCRIPT>

</HEAD>

<BODY>

<button onclick="post()">Click me</button>

</BODY>

</HTML>

Regards

Tufale Ashai.

Message was edited by: Tufale Ashai

Message was edited by: Tufale Ashai

0 Kudos

Hi Tufale,

Thanks a lot for your help.. your mentioned logic really help me a lot.

While doing more investigation i found one more way in which we can invoked the URL in background i.e. asynchronously on click of Post button from UI screen.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd
">
<HTML>
<HEAD>


<TITLE>Your Title Here</TITLE>

<SCRIPT language="JavaScript">
function Post(){
var Test_URL =
"/XMII/Runner?Transaction=Default/Transactions/Test"; //build your URL
window.frames("runner").location=Test_URL;
}
</SCRIPT>


</HEAD>
<BODY>

<tr>
<td colspan="2">
<iframe id="runner" name="runner" style="display:none" width="0" height="0"></iframe></td>
</tr>

<tr>
<td>
<input type="button" id="PostButton" name="PostButton" value="POST" onclick="Post()"/>
</td>

</tr>
</table>
</BODY>
</HTML>

Thanks,

Ritim

Former Member
0 Kudos

You are welcome .. Great.. I didn't know about this option... Thanks for sharing ..

Answers (0)