Users of interactions do not need to create interaction pages. This is only of use to workflow and service developers

Within the HTML page you will need access to pmrpc.js which is used for retrieving and sending the data.

Getting the input data

To access the input data for the interaction, you need to call getInputData

pmrpc.call({
             destination : "publish",
             publicProcedureName : "getInputData",
             params : [],
             onSuccess : function(retVal) {
			   myInputValue = retVal.returnValue.myInputPort;
               // Code to fill in your page's document
             },
			 onFailure : function() {
				// Code to deal with inability to read input values
			 }
          });

getInputData has a field returnValue that has a map from the name of the input port to the data value. So in the above code, retVal.returnValue.myInputPort contains the data that was entered into the port called myInputPort.

This is normally done when the interaction HTML is loaded, for example:

window.onload = function() {

     pmrpc.call *...*

};

If the data has been published so that it is available as a URL, then you may wish to retrieve the value of the data. This can be done by calling getDataFromUrl

pmrpc.call({
       destination : "publish",
       publicProcedureName : "getDataFromUrl",
       timeout : 10000,
       params : [url, mimetype],
       onSuccess : function(retVal) {
         retVal.returnValue;
      },
      onFailure: function() {p.innerHTML = 'Failed to read alignements';}
 });

The url is the data value returned from getInputData. The mimetype specifies the mime type to use when getting the data from the URL.

Sending results

You can send the results of the interaction using reply. reply takes two parameters:

pmrpc.call({
             destination : "publish",
             publicProcedureName : "reply",
             params : ["OK", {"a_simple_result" : "hello", "a_list_of_results" : {"a", "b", "c"}}],
             onSuccess : function() {** code to change the interaction page to show results were returned **},
             onFailure: function() {** code to change the interaction page to show failure to return results **}
          });

The above code, returns the string "hello" and the list ["a", "b", "c"] to the ports a_simple_result and a_list_of_results

Cancelling an interaction

The interaction can be cancelled by using reply with a status of "Cancelled". You currently cannot return values if the interaction is cancelled, so the map should be left empty.

pmrpc.call({
             destination : "publish",
             publicProcedureName : "reply",
             params : ["Cancelled", {}],
             onSuccess : function() {** code to change the interaction page to show interaction was cancelled **},
             onFailure: function() {** code to change the interaction page to show failure to cancel **}
          });

Getting the run id

In some interactions it is useful to access the run id that identifies the workflow run that is causing the interaction. This information can be accessed by calling getWorkflowRunId

pmrpc.call( {
            destination : "publish",
            publicProcedureName : "getWorkflowRunId",
            params : [],
            onSuccess : function(retVal) {
               ** Do something with retVal.returnValue
            },
	    onFailure: function() {

	    }
});

The workflow run id is returned in retVal.returnValue.

Setting the title of the window

The interaction page can set the title to be used for the window/tab displaying the interaction.

     pmrpc.call({
       destination: 'publish',
       publicProcedureName: 'setTitle',
       params: \["My interesting interaction"\]
    });

This sets the title of the interaction window or tab to My interesting interaction