This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Displaying the value of the service in Aras Innovator

ashu_vik - Thursday, December 24, 2009 2:11 AM:

Hi All,

I have a scenario at hand where I have to call an external web-service at the "OnClick" event of a button in a form. The value returned by the web-service is a string and I want to assign the value to a textbox in the same form.

For this, I am creating a field event on a button's "onClick" of a form.

Could someone help me in writing the code to fetch the value from the service and display it on the textbox. 

Find the scenario attached.( the service is called on "OnClick" event of the View button and the returned value is to be displayed on "Service Value" textbox.



tstickel - Thursday, December 31, 2009 10:21 AM:

1.  You first have create the OnClick method to invoke the web service.  There are many examples on the web showing how to use SOAP to call a web service viaJavascript (e.g. see http://articles.techrepublic.com.com/5100-10878_11-5887775.html#).  The SOAP code would look something like this (you need to get details of your web service to substitue in the code below):

varoXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
    oXmlHttp.open("POST",
"somewhere.com/GetServiceValue.asmx'",
false);
    oXmlHttp.setRequestHeader("Content-Type", "text/xml");
    oXmlHttp.setRequestHeader("SOAPAction", http://tempuri.org/GetServiceValue);
    oXmlHttp.send("

<soap:Envelopexmlns:xsi='www.w3.org/.../XMLSchema-instance'
xmlns:xsd='www.w3.org/.../XMLSchema'
xmlns:soap='schemas.xmlsoap.org/.../'>
  <soap:Body>
    <GetServiceValue xmlns='http://tempuri.org/'>
      <Parm>" + id + "</Parm>
    </GetServiceValue>
  </soap:Body>
 </soap:Envelope> ");

2. The last thing you need to do in the OnClick method is to take what is returned by SOAP and update the "Service Value" textbox.  Assuming that service_value is the name of your textbox and GetServiceValueResult is the Node that service returns its reponse in; You will need code like: document.getElementById('service_value').value = oXmlHttp.responseXML.selectSingleNode("//GetServiceValueResult").text;



ashu_vik - Monday, January 11, 2010 4:25 AM:

Hi Terry,

Your reply to the post has got me very near to the solution. But I am stuck in the last stage. My web-service is returning an string(xml) embedded under the SOAP. The XML which is returned to Aras from the service is as follows(I checked it in Aras application through alerts):

<?xml version="1.0"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetPartDetailsResponse xmlns="http://Infosys.org/"><GetPartDetailsResult>
&lt;part&gt;
 &lt;name&gt;MyPart&lt;/name&gt;
 &lt;description&gt;Value from service&lt;/description&gt;
 &lt;owner&gt;Ashutosh Vikram&lt;/owner&gt;&lt;/part&gt;</GetPartDetailsResult></GetPartDetailsResponse></soap:Body></soap:Envelope>

That means the the returned XML is the desired one but I am not able to get values of the nodes of the XML(that is being sent by the web-service). Suppose I want to retrieve the value of owner of the part("Ashutosh Vikram" in this case)

The line of codes I tried to retrieve the value is :

1. document

.getElementsByName("owner")[0].value = oXmlHttp.responseXML.selectSingleNode("//owner").text;

2.  document.getElementsByName("owner")[0].value = oXmlHttp.responseXML.selectSingleNode("//owner");

On using the code1, it gives an error "Event handler failed with message: object required"

On using the code2, it assigns a "null" to the "owner" textbox.

I have tried a lot on this issue. Not able to fix it out.

Any suggestions.

Best,

Ashu



ashu_vik - Monday, January 11, 2010 4:25 AM:

Hi Terry,

Your reply to the post has got me very near to the solution. But I am stuck in the last stage. My web-service is returning an string(xml) embedded under the SOAP. The XML which is returned to Aras from the service is as follows(I checked it in Aras application through alerts):

<?xml version="1.0"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetPartDetailsResponse xmlns="http://Infosys.org/"><GetPartDetailsResult>
&lt;part&gt;
 &lt;name&gt;MyPart&lt;/name&gt;
 &lt;description&gt;Value from service&lt;/description&gt;
 &lt;owner&gt;Ashutosh Vikram&lt;/owner&gt;&lt;/part&gt;</GetPartDetailsResult></GetPartDetailsResponse></soap:Body></soap:Envelope>

That means the the returned XML is the desired one but I am not able to get values of the nodes of the XML(that is being sent by the web-service). Suppose I want to retrieve the value of owner of the part("Ashutosh Vikram" in this case)

The line of codes I tried to retrieve the value is :

1. document

.getElementsByName("owner")[0].value = oXmlHttp.responseXML.selectSingleNode("//owner").text;

2.  document.getElementsByName("owner")[0].value = oXmlHttp.responseXML.selectSingleNode("//owner");

On using the code1, it gives an error "Event handler failed with message: object required"

On using the code2, it assigns a "null" to the "owner" textbox.

I have tried a lot on this issue. Not able to fix it out.

Any suggestions.

Best,

Ashu



ashu_vik - Tuesday, January 12, 2010 1:54 AM:

Hi terry,

I have an issue again. I am able to retrieve the values from the web-service on "on-click" event of the button into a textbox in  the Innovator. But the problem is that the new values set(from the web-service) does not persist on saving the form. The textbox is reset to the old value when the form is saved.  

The code is:

 

 

 

 

 

 

 

var

 

 

.open("POST","localhost/.../Service.asmx",false);

oXmlHttp

.setRequestHeader("Content-Type", "text/xml");

oXmlHttp

.setRequestHeader("SOAPAction", http://abc.org/GetPartDetails);

oXmlHttp

.send("<soap:Envelope xmlns:xsi='www.w3.org/.../XMLSchema-instance' xmlns:xsd='www.w3.org/.../XMLSchema' xmlns:soap='schemas.xmlsoap.org/.../'><soap:Body><GetPartDetails xmlns='Infosys.org/.../soap:Envelope>");

oXmlHttp

.responseXML.setProperty("SelectionLanguage", "XPath");

oXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");

oXmlHttp

document

.getElementById('value').value = oXmlHttp.responseXML.selectSingleNode('//value').text;

Any suggestions to make the values persist on saving the form.

Best,

Ashu



ashu_vik - Monday, January 11, 2010 6:49 AM:

I am now able to fix the issue. The issue was that the service was returning the xml in a string variable. I just changed the return type to XmlDocument to fix the issue.

Thanks and Best Regards,

Ashu



scottmahr - Thursday, June 9, 2011 2:26 PM:

Try using 

handleItemChange("service_value", value);

This will change the value, and automatically update the form field as well.

 

Scott