While we position SmartConnect as a tool where you don’t need to be a developer to create integrations, we have quite a few developers that want to take advantage of our interface but have all of the power to call a map whenever needed. In the example below we will explore using the GETMAPXML funtion with the VAR tag to provide maximum flexibility in getting back just the records you want.

The GETMAPXML function is defined in the manual at the link below:

GETMAPXML documentation

This allows us to run a map and then get the output of the integration (if it was set to file, XML). There is also an option to pass in variables so you can control your datasource. What this means is you now have the ability to take a SQL Server datasource (as an example) and pass in a criteria like below:

¬† select * from Customer where CustomerID = ‘GBL_CUSTOMER’

The GBL_CUSTOMER can be set globally, on the map as a default or through pre-tasks or through the web service. The code sample below shows how you can pass in this value in either XML or JSON to get the results back.

var url = “http://webServiceAddress:5557/smartconnect.svc”;
var password = “xxxxxxxxx”;
var username = “user”;
var domain = “domain”;
var RunMapId = “MAP”;
var method = “getmapxml/var”;
var accept = “”;

//JSON Section
var varString = @”[{“”Key””:””GBL_CUSTOMER””,””Value””:””C””},{“”Key””:””GBL_VAR2″”,””Value””:””XXXXXXXXX””}]”;
accept = “application/json”;
//XML Section
//var varString = @”<ArrayOfVariableOfstringstring http://schemas.datacontract.org/2004/07/eOne.SmartConnect.Engine””><VariableOfstringstring><Key>GBL_CUSTOMER</Key><Value>c</Value></VariableOfstringstring><VariableOfstringstring><Key>GBL_THIS</Key><Value>THAT</Value></VariableOfstringstring></ArrayOfVariableOfstringstring>”;
//accept = “text/xml”;

var urlCalled = string.Format(“{0}/{1}/{2}”, url, method, RunMapId);

var sendString = varString;
var req = (HttpWebRequest)WebRequest.Create(urlCalled);
req.Credentials = new NetworkCredential(username, password, domain);
req.Method = “POST”;
req.Accept = accept;

var reqStream = req.GetRequestStream();
reqStream.Write(Encoding.ASCII.GetBytes(sendString), 0, sendString.Length);

var res = req.GetResponse();
var rdr = new StreamReader(res.GetResponseStream());
var response = rdr.ReadToEnd();

//Do Something with the Data
catch (Exception ex)

As you can see this will give you an incredible amount of flexibility to pull back the data you need for applications like eCommerce sites, Portals, etc.