EONE BLOG

Tech Tuesday: SmartConnect WCF REST Service Methods – runmap


One of the components of SmartConnect is the WCF REST service that may be installed on a machine where IIS is also installed. This document is a series of KnowledgeBase Articles that are written to show how the use and execute existing SmartConnect API methods.

runmap

The runmap method allows you to run a map from your application or website. This would be the equivalent to running the map from within the SmartConnect user interface or on a schedule.

 

Map Setup

Create the map as you would any other map within SmartConnect.

You will not be able to run Real-Time maps from a WCF REST method call.

 

URL

The URL to call will be based on the server where the SmartConnect WCF REST Web Service was installed. The default Port for the SmartConnect WCF REST service is 5557 but can be changed in IIS as desired.

For example.

http://myserver:5557/smartconnect.svc/runmap/MYMAP

Review the documentation on setting up the SmartConnect WCF REST Web Service. https://www.eonesolutions.com/Manuals/SmartConnect/SmartConnect%202018/?page=sc_configure_wcf_rest_service

 

Variables

With the runmap method, you can pass variables into the map but the URL will change slightly as well as the payload.

http://myserver:5557/smartconnect.svc/runmap/var/MYMAP

The payload for the map will be the following where the GBL_VARIABLE_NAME would be set to the global variable being used in the map

<ArrayOfVariableOfstringstring xmlns=http://schemas.datacontract.org/2004/07/eOne.SmartConnect.Enginexmlns:i=http://www.w3.org/2001/XMLSchema-instance>

<VariableOfstringstring>

<Key>GBL_VARIABLE_NAME</Key>

<Value>My Value</Value>

</VariableOfstringstring>

<VariableOfstringstring>

<Key>GBL_VARIABLE_NAME_TWO</Key>

<Value>My Value</Value>

</VariableOfstringstring>

</ArrayOfVariableOfstringstring>

Return Result

The results of the map run will be returned in an XML format.

<RunMapResponse>

<ErrorCount>0</ErrorCount>

<ErrorMessage/>

<Errors/>

<MapDescription>Send Data to ERP</MapDescription>

<MapId>MYMAP</MapId>

<RecordCount>11</RecordCount>

<RunNumber>21</RunNumber>

<Status>Successful</Status>

</RunMapResponse>

 

NOTE: The < > symbols will actually come back as &lt; &gt; . This means we need to replace those values with the actual less than/greater than values in the return string.

result.Replace(“&gt;”, “>”).Replace(“&lt;”, “<“);

 

Sample Code

Below is sample C# code that you can use to execute your map from your application or web site, using the GET method since we are not posting any data in the body.

try

{

var httpWebRequest = (HttpWebRequest)WebRequest.Create(“http://myserver:5557/smartconnect.svc/runmap/MYMAP“);

httpWebRequest.Credentials = new NetworkCredential(“User”, “Password”, “Domain”);

httpWebRequest.Method = “GET”;

 

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

 

string result = string.Empty;

using (var responseStream = new StreamReader(httpResponse.GetResponseStream()))

{

result = responseStream.ReadToEnd();

}

// load the results into an XML document to save it to a file

var doc = new System.Xml.XmlDocument();

doc.LoadXml(result);

 

// or display the results to the user

MessageBox.Show(result.Replace(“&gt;”, “>”).Replace(“&lt;”, “<“));

}

catch (WebException ex)

{

MessageBox.Show(ex.ToString());

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

finally

{

}

 

In this example, we using the POST method and including the list of global variables as the payload to the call.

try

{

// Build the payload with the global variable and the value

 

System.Text.StringBuilder payload = new System.Text.StringBuilder(250);

 

payload.Append(“<ArrayOfVariableOfstringstring xmlns=\”http://schemas.datacontract.org/2004/07/eOne.SmartConnect.Engine\” “);

 

payload.Append(“xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”><VariableOfstringstring>”);

 

payload.Append(“<Key>GBL_JOURNAL_NUMBER<Key><Value>123346</Value>”);

 

payload.Append(“</VariableOfstringstring></ArrayOfVariableOfstringstring>”);

 

 

var httpWebRequest = (HttpWebRequest)WebRequest.Create(“http://myserver:5557/smartconnect.svc/runmap/var/MYMAP“);

httpWebRequest.Credentials = new NetworkCredential(“User”, “Password”, “Domain”);

httpWebRequest.Method = “POST”;

httpWebRequest.ContentLength = payload.Length;

 

using (var reqStream = httpWebRequest.GetRequestStream())

{

reqStream.Write(Encoding.ASCII.GetBytes(payload.ToString()), 0, payload.Length);

}

 

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

 

string result = string.Empty;

using (var responseStream = new StreamReader(httpResponse.GetResponseStream()))

{

result = responseStream.ReadToEnd();

}

// load the results into an XML document to save it to a file

var doc = new System.Xml.XmlDocument();

doc.LoadXml(result);

 

// or display the results to the user

MessageBox.Show(result.Replace(“&gt;”, “>”).Replace(“&lt;”, “<“));

}

catch (WebException ex)

{

MessageBox.Show(ex.ToString());

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

finally

{

}

 

Map

The global variable that is passed into the map using the runmap method can be used in a Pre-Map task. It could be used to restrict a query on SQL or CRM or Salesforce data source, as an example. Below I have set up a SQL data source that would use a passed in value to restrict the data query to the provided value from the runmap execution.

 

 

Additional Notes

  • The map runs on the IIS Server
    • Any Errors will also be logged in the SmartConnect Event Viewer on the IIS Server
    • Access to files, either as the source or destination, will be from the IIS Server. Ensure the correct path exists and is accessible from this server
    • The Map is executed in the context of the user assigned to the Web Service Application Pool.

4 Comments

  1. Soma on April 3, 2019 at 3:16 am

    We are followed above steps to run map. But, we are getting 404 not found error.
    Do we need to add any dll in our coding? or need to follow any steps?

    Kindly update us.

  2. Soma on April 3, 2019 at 5:13 am

    Can you tell us if any steps needs to do it on Map Pre Task?

    • Lorren Zemke on April 8, 2019 at 9:52 am

      Soma, Not sure what your map is doing but you could call runmap using a Pre map Task but when you call the runmap method it does not require any pre map processing to run

Leave a Comment




RECENT POSTS


What is a Popdock Widget?
Tech Tuesday: Conditionally Auto Opening an Extender Window with Extender Enterprise
Sign Up Ends Soon! SmartConnect Bootcamp for GP or BC/NAV in Las Vegas
A Recap: SmartConnect Excel Templates for Business Central
The eOne Team Heading to Directions NA 2019

POPULAR POSTS


2016 SmartConnect Integration Bootcamps
Tech Tues: Automatically refreshing Pivot Tables in Excel Refreshable Reports
Happy Thanksgiving from the eOne team!
New Releases of Extender and SmartList Builder
2017 SmartConnect Integration Bootcamps

CATEGORIES

ARCHIVES

open all | close all

TAGS

CRM Demo Dynamics 365 dynamics crm Dynamics GP Dynamics NAV Econnect Employee Spotlight eone eOne News eOne Spotlight ERP Events Excel Excel Report Builder Extender Extender Enterprise Flexicoder GP GPUG integration integration manager Meet the Team Microsoft dynamics crm Microsoft Dynamics GP Office Relationships partners Popdock release SalesForce SalesForce.com scripting SmartConnect SmartConnect.com SmartConnect Office Hours SmartList SmartList Builder SmartList Designer SmartView SQL Support Tech Tuesday Templates training Zendesk

Integrate & Automate without Any Code.

SmartList Data has Never Been Faster.

The Easiest Way to Report on GP Data.