Reading the response of a web service problem.

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

LKirby
Ebase User
Posts: 37
Joined: Wed Mar 13, 2013 11:33 am
Contact:

Reading the response of a web service problem.

#1

Postby LKirby » Tue May 14, 2013 11:59 am

In Ebase I've got web service resource that calls an external web service (in this case, its called AuthenticateUser) and gets back the following response document: http://pastebin.com/Y9hv1x3h

I want to be able to get the error, success and ticket attributes (not userid) from the response element but I haven't had much luck so far as I'm fairly new to this stuff. How should I go about doing this?

Thanks,
Luke.

Edit:

Got it working now.

Code: Select all

importPackage(com.ebasetech.xi.api);
importPackage(com.ebasetech.xi.services);


try {
	// call the web service.
	resources.IRWS_AUTHENTICATEUSER.call();
	resources.IRWS_AUTHENTICATEUSER.fetch();
}
catch (e) {
	event.owner.addErrorMessage(e.javaException.message); 
}

//get the response document
var response = resources.IRWS_AUTHENTICATEUSER.getDocument("Response");

var xmlDoc = new XML(response);
// variable xmlResponse get the response element from the response document
var xmlResponse = xmlDoc.child(0).child("response");

// now get the attrubutes error, ticket and success from the response element.
fields.RESPONSE_ERROR.value = xmlResponse.attribute("error").toString();
fields.RESPONSE_TICKET.value = xmlResponse.attribute("ticket").toString();
fields.RESPONSE_SUCCESS.value = xmlResponse.attribute("success").toString(); // this is a boolean field set to checkbox
0 x

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

#2

Postby Wai » Fri May 17, 2013 2:18 pm

If you are using an Ebase web service resource which looks like you are from your call:

Code: Select all

resources.IRWS_AUTHENTICATEUSER.call(); 
You can map your document elements directly to your Form fields, including element attributes. So you don't need to do any of the scripting to get response document.

In your web service resource, right click the element/attribute and select attach field. This creates a resource field which you can map to a form field so the value is fetched as soon as you issue the command.
0 x

LKirby
Ebase User
Posts: 37
Joined: Wed Mar 13, 2013 11:33 am
Contact:

#3

Postby LKirby » Mon May 20, 2013 8:57 am

I forgot that i could use XPath to do this easily! So like you said I mapped the response element to a field and changed the XPath to say:

Code: Select all

/tem:AuthenticateUserResponse/tem:AuthenticateUserResult/response/@ticket
. I'll create 2 more fields for the error and success attributes but its a lot easier that the long script I had before.


Thanks :)
0 x


Who is online

Users browsing this forum: No registered users and 12 guests