Using a Replace Web Service in a Sharepoint Web Based InfoPath form
December 10th, 2008 . by <Patrick/>|
Due to the lack of an easy way to do a find and replace in InfoPath, I developed a simple web service with a web method called replace that uses managed code to call the replace method of the string data type. Here’s how I call the web method in a browser-based Sharepoint InfoPath form.
First create a form like so..
With fields txtFind, txtReplace and txtText The idea in this sample form is to replace mother with sister in the text “Don’t forget to call your mother today!”
You should first see if your Sharepoint server already has a data connection to the Replace web method
Enter the URL of the site like in the above image and then expand the data connections. Select the Replace.udcx data connection. If you do not see this data connection you must create a new data connection to receive data and then select the web service Once you have created the web service data connection you must convert it to a data connection file that you must store in a data connection library in your Sharepoint site. Now you will be presented with the data connection wizard
The web method requires three parameters: Text: the text you want to do the search and replace on For now don’t set default values and click on next, next deselect Automatically retrieve data when form is opened and then click on finish So the next thing we need to do is create some rules for our button The rule will have the following actions - set each of the parameters of the data connection , then query the data connection and then set the txtText value to the result of the data connection query Then create the following actions so that it looks something like this:
Now test out your rule by previewing the form
Click on the Replace button and the text shoudl read Don’t forget to call your daughter today!
Here’s the code for my web method: _ _ If escapeSpaces.ToUpper = “TRUE” ThenstringToFind = stringToFind.Replace(” “, “%20″) End If Return text.Replace(stringToFind, stringToReplace) |








