Invoking a Web Service from a SmartForm Programmatically

Why?

LiveCycle Designer has a graphical way of defining a Web Service invocation – you simply create a new Data Connection based on a WSDL definition, and Designer creates all the input and output fields you need, along with a Submit button.

However, you can also quite easily invoke a Web Services from a PDF SmartForm without this visual designer – you just have to write a little code. Luckily the thoughtful PDF team gave us some really easy ways to invoke Web Services programmatically and you can do it in just a few lines.

Using code actually has some benefits over the visual technique that Designer uses, because:

  • Often you don’t simply want to simply display the result, you want to process it in some way. For example, you may want to use the results to populate a drop-down list, or use the return value to validate some data.
  • You may want to call a different instance of the web service depending on whether you are in a development, test or production environment. This can be quite hard to do in the visual paradigm, but is very easy to do in code.
  • You get more control over error handling – as we shall soon see.
  • There are some Web Services that are too complex to be handled by the graphical designer – but can still be invoked programmatically.

A Simple Example

Let’s start by looking at a very simple Web Service that converts temperatures from Fahrenheit To Celcius. (Note – you would almost certainly NOT use a web service to implement such a simple service – this could be implemented in a few lines of JavaScript within your form – but it serves as a useful example.)

The code to invoke this service is shown below:

var cURL = "http://webservices.daehosting.com/services/TemperatureConversions.wso?WSDL";
SOAP.wireDump = false;
var service = SOAP.connect(cURL);
var Input = {nFahrenheit:33};
var result = service.FahrenheitToCelcius(Input);
xfa.host.messageBox(result);

The bits displayed in blue are the bits you need to change for different web services – most of the code is the same every time.

Let’s look at it line by line.

var cURL = "http://webservices.daehosting.com/services/TemperatureConversions.wso?WSDL";

First we need to identify to Acrobat/Reader the definition of the service. You do this by specifying the WSDL (or Web Services Definition Language) for the service. Acrobat/Reader will use this to understand where and how to invoke the service. The WSDL URL is exactly the same URL you would use in Designer when defining the WSDL Data Connection. Your IT department should be able to give you the URL for any services you may want to invoke.

In this case, we have hard-coded the location of the web service. But you could also insert a different hostname depending on whether your form was running in a test or production environment.

SOAP.wireDump = false;

This line can be very useful. If you set it to “true” instead of “false”, it will output a whole lot of really useful information to the Reader/Acrobat console. If you set it to “true”, you should always set it back to false when you’re done, as this is a global setting, which affects any other web-services invocations.

var service = SOAP.connect(cURL);

This line “connects” Reader/Acrobat to the web service. This line is always the same for any web service.

I’m going to skip the Input line for the moment, and come back to it later. Let’s take a look at the actual invocation:

var result = service.FahrenheitToCelcius(Input);

How did I know what method to invoke on the service object? Or more simply, how did I know to type “FahrenheitToCelcius”?

One way would to become a Web Services guru, and actually read the WSDL file. But that’s way too hard for most of us, so it’s easiest to use an existing software tool to work it out for us. My two favourite options are:

  • LiveCycle Designer. Just add the WSDL Data Connection in Designer. As part of the Data Connect Wizard, it will ask you which operation you want to invoke. Take a note of this operation name, or copy it to your clipboard. You can see this in the screenshot below.
Operations In Designer

Operations In Designer

  • SOAPUI. http:// http://www.soapui.org/ This handy (and free) tool generates a sample XML document for any Web Service you point it at.
Operations In SoapUI

Operations In SoapUI

Now let’s go back and look at the input to this Web Service.

var Input = {nFahrenheit:33};

Normally when you think of Web Services, you think of XML – however, Reader expects the input parameters in the form of a JavaScript object that is structurally similar to the input XML (although quite a bit simpler). The curly braces define the object, and the “nFahrenheit:33” define a single element with a value of 33.

How did I know what values to put in the curly braces? Well, again I use either Designer or SOAPUI, as shown in these screenshots:

Input Fields In Designer

Input Fields In Designer

Input Fields in SoapUI

Input Fields in SoapUI

You can ignore the “soapenv” (or SOAP envelope) or “Message Body”, the namespace prefix (“tem:”), and the root node (FahrenheitToCelcius) – the only important thing is the nFahrenheit input parameter.

Normally, the value would not be hard coded to a fixed number, but would come from a field in the form, so you may in fact use something like this:

var tempF = DecimalField1.rawValue;
var Input = {nFahrenheit: tempF};

Finally, we need to process the results.

xfa.host.messageBox(result);

Again, instead of giving us raw XML, Reader presents us with the data as a JavaScript object. In this case, there is only a single value returned, and this comes back as a single string value. In this case, we’ve simply displayed this value in a Message Box, although we could assign this to another field.

A Slightly More Complex Example

Let’s look at a slightly more complicated example:

try {
  var cURL = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL";
  SOAP.wireDump = false;
  var service = SOAP.connect(cURL);
  var Input = {sCountryISOCode:countryTextField};
  var result = service.FullCountryInfo(Input);
  tfCurrency.rawValue = result.sCurrencyISOCode;
  tfCapital.rawValue = result.sCapitalCity;
} catch (e) {
  xfa.host.messageBox("The web service could not be invoked. This may either be because you are running in Reader instead of Acrobat,"
    + " or you do not have a ReaderEnabled form, or the Web Service is unavailable.Underlying error: " + e);
}

We have changed the WSDL url to a different Web Service. The method to invoke, and the structure of the Input and results variables have all changed, but most of the code is unchanged. In this case the input comes from a field, and the results are inserted into other fields rather than simply being displayed in a dialog. You could of course do more complex processing, such as populating a drop down list.

We’ve also added some basic error handling. Remember that you can only invoke a Web Service if you are using Acrobat, or in Reader if the form has been Reader Enabled. The standard Reader behavior is to fail silently if the form is not Reader Enabled, and this control over error handling is one of the big advantages of using a programmatic model.

Mapping Inputs and Outputs

I determined the structure of inputs and outputs using Designer is shown below. Only a few of the possible output values are used, and are highlighted in red.

Designer Inputs and Outputs For Country Information

Depending on the structure of the returned XML data, Reader will construct a slightly different JavaScript object. To the best of my knowledge, this is not explicitly documented, but based on my explorations, the rules are as follows:

  1. All values are strings. Reader does not differentiate between different data types. Fortunately JavaScript does a good job of casting strings to other data types.
  2. A single return value will result in a single string contained in the “result” variable. (Like our temperature converter service.)
  3. Multiple return values can be accessed using JavaScript “dot” notation. For example, in the “country information” example, result contains result.sCurrencyISOCode and result.sCapitalCity and other sub-objects.
  4. If repeating data is encountered, it will be added as an array. So for the multiple languages in the country info, you might get something like:
result.Languages.tLanguage[0].sName; and
result.Languages.tLanguage[1].sName; etc
  1. You need to be a little careful – for an element which can repeat, if there is only one row of data, Reader won’t realize that the data is repeating, and will not create an array, instead just creating a single sub-element. So if there is just one row, instead of
    result.Languages.tLanguage[0].sName;

    you will need to use:

    result.Languages.tLanguage.sName;

    Similarly, if there are no rows of data, then there will be no objects. Your code will need to check whether there are zero, one or multiple objects available. To check for the existence of an element, compare it with the JavaScript “undefined” keyword.

  2. In some cases, the Web Service may return an error message rather than the data. Again, check for the existence of this error message by comparing against the JavaScript “undefined” keyword. For example:
    if (result.some_error_element != undefined) { etc...

For the Input variables, if you need to create more than one input variable, you can simply separate them with commas. For more information on constructing and using JavaScript objects, there are many resources on the web. This is one: http://www.hunlock.com/blogs/Mastering_JSON_(_JavaScript_Object_Notation_)

Both of the Web Services referenced in this blog are real Web Services that you can use in your own experiments. However, as they are hosted by third-parties, they may or may not be available when you try them.

Note: There is a more sophisticated version of Web Service invocation using the SOAP.request(…) method call. This is documented in the AcroJSGuide.pdf file available from the Adobe web site. It’s more complicated to use than the technique shown above, and generally I’ve found that I don’t need the sophistication that it provides.

Conclusion

It’s actually quite simple to invoke Web Services from PDF SmartForms programmatically. In many cases, this is more powerful than using the visual design technique. Hopefully this blog gives you the techniques to help you do that.

Two Key Ingredients for Successful Field Mobility Solutions

Mix

I recently attended the Australian Field Mobility Summit 2010 and got a chance to see a number of organisations showcasing the steps they are making towards providing their staff great technical field mobility solutions. The conference was abuzz with debate about what the next great device would be or which was the best operating system for mobile.  Perhaps most interesting though,  was  the multitude of devices that the successful field mobility implementations were deployed on – smartphones, tablets, purpose built mobile computers, laptops, Toughbooks – and across a whole range of operating  systems.

However, the two things all the successful projects had in common was not the device or operating system, but the solution’s ‘usability’ and ability to ‘empower’ their users. These two factors were stressed by every presenter that had been involved in a successfully field mobility solution.

Usability is King!!!

Usability becomes even more important when working with mobile devices due to the small screens and the user’s inability to easily access support/training.  Let’s face it, staff in the field are out there to do a job, not to use field mobility applications! If the application does not assist them with inspecting sites, undertaking maintenance, auditing clients, making sales (whatever it might be) the uptake of your application is going to suffer. Xerox found that additional field testing and an increased focus on usability was required to get their WINGS application really firing:

“Xerox had a 46% increased adoption of the WINGS 2 mobile application after user interface improvements were made to the first deployment” – Gregg Bullen Program Manager Xerox Systems (USA)

Usability on devices has always been a challenge, but with Rich Internet Application (RIA) frameworks like Adobe’s Flex 4 becoming available for mobile development, we are hitting a tipping point where the best of the web usability will soon be available on mobile devices with very little compromise at all.

Empower the User

Don’t underestimate the “what’s in it for me” factor. Almost all successful projects discussed at the conference offered some functionality that while perhaps not a priority to the organisation, improved the user’s ability to plan or organise their day.  Introducing things like calendars and maps can allow field staff to manage their tasks and feel more in control of their work days. The technology also opens up opportunities for field staff to swap tasks between themselves, or bid for tasks’ real time, giving some of the power of scheduling back to the workforce. The holy grail of field worker empowerment is applications that allow staff to complete all aspects of their job without having to contact the office at all. Superior Food Services reduced sales reps calls back to the office by 20% after implementing a field mobility application.

 

It doesn’t have to be complicated

Recently we developed a solution that provided BroadCast Australia with an occasionally connected AIR application that allowed site data to pre-populate site inspection forms – the application holds all the forms as well as ad-hoc incident reports which might be required. Then the field worker can work with these PDF forms and AIR will manage the submission and synchronisation of any new/amended data back to the systems back in the office.  

Learn more about why Mobility is so significant now – check out our Mobility Solutions.

Age of the Mobile Worker?

Technology companies have been talking about the dawning of the age of the mobile worker for some time, but the reality is that it is already here. International Data Corporation (IDC) has estimated that by the end of 2010 there will be more than “1 billion mobile workers”. Devices like smartphone and tablets have become cheaper and more powerful, the user interfaces richer and the speed of mobile internet (like 3G) has become quicker, the time is now right for the wide spread adoption of Field Mobility applications.

The challenge is for technology providers and business to work together to make good ones!

The Internet – Coming to a Screen Near You (and not just at the movies)

I recently caught a glimpse of the future – and it’s not far away.Robot Vacuum Cleaner

Samsung have just released a TV advertisement showcasing how technology will soon change our home lives. And everything they show in the ad is available today.

A robot vacuum cleaner that detects things to clean up3D TV

3D Home Theatre for a cinematic experience right in your living room.

But the one that really caught my eye because I work with a company that can make this a reality – was the scene showing video chat, on a TV.

Now the idea of Video Chat on a TV may not seem that impressive – we can do it on phones (Apple FaceTime has been clogging up the TV with advertising lately) and I believe some of the Game Consoles support it also.

But what’s happening with the current generation of televisions is that they are supporting some key internet technologies directly on the TV’s hardware – namely, Adobe Flash and Google Android. This means, the experiences we create for the web, expecting to be used by people with computers – can now be accessed from the living room, from the TV.

Now, when most people think of things like Flash and Android on a television it is unsurprising that they might assume we’re talking about streaming YouTube and other internet video content to the TV.

And they’d be right…  but that’s only the start of what’s possible.

Technology companies like our own (Avoka) can build software applications that run inside the Adobe Flash player. To-date, the main benefit of this for our clients has been that we can create rich and engaging web experiences that work on Windows, Apple Mac and Linux… but now those experiences also work on Android devices AND on the television in your own home.

So what does this mean… ?

Breaking news stories could pop up on your TV with the option to CLICK to read more – just as they do on your PC screen or your Smartphone.

If your postal service could deliver digital mail – it could be delivered directly to a secure account… on your TV.

If your bank thinks a fraudulent transaction has been put through on your bank account – you could receive an instant notification whilst watching your favourite comedy “Have you made a purchase on eBay in the last 30 minutes for $159.00 YES/NO?” and you could interact with this message to say “NO” and have the transaction stopped immediately.

Or you could order a pizza whilst watching a movie.

You get the idea.

The core principle of the TV to-date has been that it is a 1-way communication device. The broadcasters ‘stream’ content to you through Channels. The Cable operators have taken a small step towards 2-way communication with interactive coloured buttons – where you can, for example, press a Red or Green button on your remote to have your say in a Poll.

But with Flash and Android on your TV – the TV becomes a 2-way window of connectivity and interactivity for the internet.TV

The defining concept here is – if you can do it online, you can do it on your TV… browse, shop, communicate… etc. etc.

Adobe is spear-heading a global initiative called the Open Screen Project –and the list of partners that have signed up is a who’s who of the technology industry. Everyone from the aforementioned Samsung to Sony, BBC to NBC, Disney to The New York Times, Nokia to Toshiba.

For more information – check out http://www.openscreenproject.org/ it’s an exciting prospect.

Data Dictionary for Form Factory is Here!!

If your organization is like most, you have lots of forms. And one of the interesting things we’ve found as we’ve built electronic forms for many organizations, is that there are numerous common fields across forms.  Your organization is probably similar. For example, how many of your organization’s forms contain information about a generically named description such as “customer details”? It is not surprising then, that much information can end up duplicated across forms.

This duplication leads to some problems:

  • How do you define and organize the data that you collect across forms?
  • How do you ensure that your fields are consistently used across different forms? For example, if it’s the same field, it really should have the same label, tooltip, maximum length, etc. Partly because consistency makes life easier for you customers, but also because your forms are often the first impression a customer has of your organization, and you want to appear organized and consistent.
  • How do you specify which fields should be pre-populated from some backend system? Or which fields should be stored in some backend system once the form is submitted? How do you communicate this information between designers and IT?
  • Do you duplicate effort for yourself? Every time you need to create a new field, do you find yourself having the same conversations with the form owners about how that particular field should be named, what the tooltip should be, what values should be in dropdown lists, and more? Wouldn’t it be nice to simply refer them to the corporate standards?

SmartForm Composer Data DictionaryIf any of these issues resonate with you, then a Data Dictionary may help to solve your problems. A Data Dictionary allows you to define all the data items that your organization collects, and associate “meta-data” about these data items – the default label, tooltip, maximum length, field type, storage location, etc.

A Data Dictionary that is tightly integrated with your Form Design tool will also improve your productivity – instead of dragging a generic Text Field onto your form – you’ll drag a very explicit CustomerFirstName field onto your form – along with the appropriate label, tooltip and other values pre-defined.

SmartForm Composer Data Dictionary Fields
You can also expedite the business analysis portion of creating a new form. Instead of selecting generic fields, laying them out on a page, and then discussing each one with the subject matter expert, you can decide what data you want to collect, choose existing elements from the data dictionary or create new ones as needed – any fields that already exist in the Data Dictionary don’t require any discussion, and you can also avoid being sidetracked on the look-and-feel of the form, and just focus on the data that needs to be collected.

The Data Dictionary is one of many new features that have been included in the Avoka Form Factory for Adobe LiveCycle. Form Factory is a solution suite that opens the LiveCycle innovation process to business teams, so that organizations can create more LiveCycle SmartForms at less cost and in less time. Form Factory is comprised of Avoka SmartForm Composer, an intuitive SmartForms creation tool and Avoka FormCenter, a comprehensive SmartForms enterprise management solution.

To learn more please visit:

Designing Multi-Language Forms the Easy Way

If you’ve ever had to translate a form into another language, you need to keep reading this blog.

If you’ve never translated a form into another language, you should still keep reading this blog – because if you’re not producing forms in multiple languages, you probably should be. You may be leaving entire market segments untapped and un-serviced simply because some of your potential customers may happen to speak a different language to the one you normally publish your forms in.

In the past, translating forms was really difficult to do, and even more difficult to maintain. Generally, one way or another, you ended up with multiple copies of the same base form, with each copy being translated to a different language. So if you support forms in 5 languages, you now have 5 forms to update every time the business decides they want to capture a new field. You have to be incredibly disciplined to do this properly, it takes a lot of time, and it’s very easy for the various copies of the form to get out of sync. Translation can also be quite costly, as you generally need to pay for specialized translation services.
Multi-Language in SmartForm Composer
Avoka SmartForm Composer has changed all that. Composer V2 – a key part of Avoka Form Factory,  allows you to maintain a single copy of a form (with all the business rules, styles, layout, etc, intact), in several different languages. We extract all the translatable text from the form, and display it to translators in a simple spreadsheet metaphor. We support the standard translation file formats most third-party translators are familiar with. And we even do the first pass of translation for you automatically – we will translate 90% of your form correctly into French (for example), even if you don’t know a word of French. In some cases, it’s as simple as having a native French speaker review the translation just to ensure it’s all grammatically correct and no misspellings.
Multi-Language Wizard
So, if you do need to translate forms into multiple languages – and even if you don’t – you’ll definitely want to take a look at Avoka Form Factory.

For more info – check these out:

A Newbie’s Experience at Adobe MAX

Adobe MAX AudienceAs someone who is new to Adobe LiveCycle, Adobe MAX offered me the opportunity to really get to know what is on the leading edge of new developments at Adobe. As an SE at Avoka Technologies this gives me the tools I need to talk about LiveCycle to potential customers, to offer consultancy services in designing great user experiences for the enterprise.

After a decade of working for European based companies, it was my first time to visit USA.  The size of this conference was bigger than any conference I have ever attended. The conference comprised of:

-          3 general sessions held in the Nokia Theatre L.A. Live (a real Hollywood icon seating up to 7,100),

-          Conference Sessions scheduled over 3 days,

-          Some informal “unconference” discussions,

-          Exhibition stands,

-          Areas to relax or work, and

-          Copious amounts of great American Style food.

As a sponsor, Avoka had an exhibition stand, to show off our Form Factory solution for Adobe LiveCycle ES. This proved to be a popular demonstration during lunch breaks and in between scheduled sessions.Adobe MAX Avoka Stand

Of course the creative side of Adobe dominated activities, however there were many interesting scheduled sessions around enterprise solutions, and some big announcements! Mostly though, as technologies overlap between creative and enterprise, the message was clear: Great Customer Experiences on Multiscreen.

Multiscreen

To design a great multiscreen experience, we need to consider not only different sized screens on PC, mobile and TV, but also the way that we interact with these devices. HTML, the flash platform and the AIR runtime offer designers and developers great ways to distribute content and apps for a plethora of devices. Now this doesn’t mean “compile once, and run anywhere”. This issue is too complex, due to the differences in these devices. However, these differences are indeed what we should be embracing.

My opinion is: Why on earth, would you want to use the same app on your phone as on your PC, when the context is completely different? When I use my PC, I want to embrace the screen real-estate. When I am on my mobile, I want to take advantage of the camera and GPS. When I’m on my TV I want to be able to navigate with my remote (or indeed with my mobile). When designing for multiscreen we must pay close attention to how the user’s context will affect the way that their experience should be engineered. Some great examples of this are seen with virtual reality apps: Why would you want one on your PC at all? But I digress…

Big Announcements

For me, the big announcements at Adobe MAX were:

  • The acquisition of Day Software, to add Day’s CQ5 to Adobe’s ‘Customer Experience Management’ offering
  • The release of LiveCycle ES2.5 and updated solution accelerators for

o   iStatements

o   Correspondence Management

  • Release of Acrobat X
  • Release of AIR2.5

Let’s take a look at a few of these in closer detail…

Acquisition of Day Software

Day Software DemoIn the keynote session, Kevin Lynch (CTO Adobe) and David Nüscheler (CTO Day Software), gave a quick demonstration of how CQ5 can be used to by the business (not IT), to customise media rich websites for multiscreen. The concept is that a mobile website inherits content from the main website, but can be overridden with more effective content for different screens.

I was lucky enough to personally meet David Nüscheler at the LiveCycle exhibition stand, where I received a personal demonstration of what CQ5 can do in the CEM space. The advantage comes when the website can be optimised and targeted for specific user groups. For example – What’s the point in trying to sell your customer something they already have? Find the unique feature for individual users by detecting which language should be displayed or by filling the  homepage with local content (a banner with Parliament House, instead of the Whitehouse). And so on. And CQ5 can also be used to enable communications between the organisation and the customer via social media and collaboration. For the business user, this becomes less about the technology, and more about the message.

I think Avoka’s Form Factory fits beautifully into the same business model: Business driven content without necessarily having to start a massive project with IT, developers, and project managers. The web is becoming a place where the business intelligently controls the customer experience, based on what the customer wants, by measuring the way that groups behave. Technology-driven systems are on the way out. There is no longer a need to force a business process down a customer’s throat! Rather, rich online experiences can be designed to make your customers advocates of your brand. This will be a paradigm-shift in any paperbased organisation.

iStatements

The scheduled session on iStatements was by far the most interesting session I attended. A few of my colleagues were in the same session, and the presenter was bombarded by questions from all the Aussies in blue shirts! With the iStatement Solution Accelerator for LiveCycle ES2.5 it is possible to create rich custom communications which your customers will love. This session demonstrated how a credit card statement could be generated from a design template and a process orchestration including a query to Adobe Omniture for fine-grain targeted advertising. The result was a secure interactive flash-enabled PDF statement which included interactive content that the user could use to easily:

-          pay the bill – from within the bill,

-          analyse spending habits,

-          dispute a charge or

-          chat with a customer service operator.

Interactive Credit Card Statement PDF Demo

What’s exciting about this is that the statement, some apps and application forms are all packaged together in a secure standalone file, which can be used online or taken offline. If the user wants to print the statement, a flattened version displays the same data formatted for print. From a technology point of view, that fact that a Flash application could act as a user interface to a PDFportfolio excited our developers about the endless possibilities.

Finally, the conference included an awards session and a ‘sneak peeks’ presentation at what research is being conducted by Adobe, hosted by none other than Captain Kirk (or Denny Crane) himself: William Shatner. With a Star Trek theme, awards were presented to Adobe Partners across six categories including Enterprise (not Kirk’s Enterprise). The sneak peeks included some new concepts at what might come in the not too distant future.

Conclusion

For me, Adobe MAX offered a great insight into what could be done in the Enterprise, given the right strategic business direction. All these technologies must be implemented correctly in each organisation based on needs and value to the business. Furthermore, as the technologies benefit multiple divisions in the organisation, a high level strategic commitment must be made to engage the customer, and to analyse which parts of the business can utilise LiveCycle as a platform to deliver great customer experiences. This discussion, however, is for another time and possibly on a personal level.