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.
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. ??
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.