How to: Call a WCF Web Service from a Nintex Form and work with the returned JSON object

Probably, the best way to go about calling a web service from your Nintex form would be to do it in client side scripting. In fact, calling the WCF from your Nintex form will not be much different from calling it from any other web page. What is different is that instead of using the jQuery library ($), you will have to use the Nintex optimised NWF$.

Having said that, the following method calls the WCF and gets a JSON object in return. The lookupValue variable is a field on the form. We’re getting its value and pass it to the WCF as an input parameter.

If the call succeeds, we pass the JSON object as a parameter to another JS function (which, in our case, populates the fields on the form with the values from the JSON).

It pushes the error message to an alert box on the screen, if the call fails.

Notice that, in the end, we return false. That is needed as, if we don’t, the page will reload/postback.

 

function event_LookupProperty()
{
var lookupValue = NWF$(‘#’+ txtPropertyCode).val();
NWF$.ajax
(
{
type: ‘GET’,
url: L_Menu_BaseUrl+’/_vti_bin/PropertyService.svc/GetProperty/’+lookupValue+’/Lloyds Banking Group’,
dataType: ‘json’,
success: function (response, type, xhr)
{
onPropertyLookupSucceeded(this, response);
},
error: function (xhr)
{
window.alert(‘error: ‘ + xhr.statusText);
}
}
);
return false;
}

Once the method completes, we will have a JSON object with the response from the WCF web service. We can very easily get the values from the JSON and use them in our form. The following JS method accepts a JSON object as an argument and populates fields on the Nintex form with the correct values.

function onPropertyLookupSucceeded(sender, args)
{
NWF$(‘#’+ txtSiteName).val(args.PropertyName);
NWF$(‘#’+ outSiteName).val(args.PropertyName);

NWF$(‘#’+ txtSiteAddress).val(args.PropertyAddress);
NWF$(‘#’+ outSiteAddress).val(args.PropertyAddress);

NWF$(‘#’+ txtListedBuilding).val(args.ListedBuilding);
NWF$(‘#’+ outListedBuilding).val(args.ListedBuilding);
NWF$(‘#’+ txtConservation).val(args.Conservation);
NWF$(‘#’+ outConservation).val(args.Conservation);
NWF$(‘#’+ txtHeritage).val(args.Heritage);
NWF$(‘#’+ outHeritage).val(args.Heritage);
NWF$(‘#’+ txtLeaseStatus).val(args.LeaseStatus);
NWF$(‘#’+ outLeaseStatus).val(args.LeaseStatus);
NWF$(‘#’+ txtFmName).val(args.FM_Name);
NWF$(‘#’+ outFmName).val(args.FM_Name);
NWF$(‘#’+ txtRegion).val(args.Region);
NWF$(‘#’+ outRegion).val(args.Region);
NWF$(‘#’+ txtPostcode).val(args.Postcode);
NWF$(‘#’+ outPostcode).val(args.Postcode);
NWF$(‘#’+ txtSiteUse).val(args.SiteUse);
NWF$(‘#’+ outSiteUse).val(args.SiteUse);
//nintexForms.log(listItemInfo.toString());

}

Reference One and Reference Two were used.

MGR: the Intelogist

About MGR: the Intelogist

SharePoint Server developer, turned Sitefinity developer, turned Angular developer, turned SharePoint Online consultant, turned Unily consultant, turned O365 consultant... Never a dull moment!

2 thoughts on “How to: Call a WCF Web Service from a Nintex Form and work with the returned JSON object

  1. Kristi Gift

    This is really good information and exactly what we are trying to do here. However, what is actually put in the Nintex form itself? We have the web service created, however I cannot find any documentation on how to make this functional in the Nintex form in a field from the form list. ??

    • MGR

      Good morning Kristi,
      not sure if you’ve figured this out already (apologies for the delay), but, if you’re following my example, you would create the form fields on the Nintex form, as you normally would, and then use JavaScript to pass the values from the web service to the form fields. Does that makes sense? The JS code goes into the “Custom JavaScript” section of the Nintex form settings. Things are a bit more complicated if you’re working with Nintex Forms on Office 365, but you should still be able to make it work.
      Let me know if that helps, or if you need anything else, I’ll try to help.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.