A longer time ago I presented here the possibility to use Notepad++, with the CS-Script Plugin, to develop your own activities. UiPath offers the possibility to use C# with the Invoke Code activity, so that this approach can now also be used here.
The code in the C# Invoke Code activity looks like this:
//-Begin----------------------------------------------------------------
SAP.Middleware.Connector.RfcConfigParameters cfgParams;
SAP.Middleware.Connector.RfcDestination destination;
SAP.Middleware.Connector.IRfcFunction rfcFunction;
SAP.Middleware.Connector.IRfcStructure RFCSI;
cfgParams = new SAP.Middleware.Connector.RfcConfigParameters();
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Name, "Test");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.AppServerHost, "ABAP702");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.SystemNumber, "00");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Client, "001");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.User, "BCUSER");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Password, "minisap");
destination = SAP.Middleware.Connector.RfcDestinationManager.GetDestination(cfgParams);
rfcFunction = destination.Repository.CreateFunction("RFC_SYSTEM_INFO");
rfcFunction.Invoke(destination);
RFCSI = rfcFunction.GetStructure("RFCSI_EXPORT");
//-Get a few information------------------------------------------------
Host = RFCSI.GetValue("RFCHOST").ToString();
SysID = RFCSI.GetValue("RFCSYSID").ToString();
DBHost = RFCSI.GetValue("RFCDBHOST").ToString();
DBSys = RFCSI.GetValue("RFCDBSYS").ToString();
//-End------------------------------------------------------------------
To use this code inside Notepad++ with CS-Script PlugIn is it necessary to add a few lines on the top and bottom. At the end the code looks like this:
//-Begin----------------------------------------------------------------
//css_host /platform:x86
//css_reference sapnco.dll
//css_reference sapnco_utils.dll
using System;
using SAP.Middleware.Connector;
class test {
static void Main() {
string Host;
string SysID;
string DBHost;
string DBSys;
//-Begin of Invoke Code-------------------------------------------------
SAP.Middleware.Connector.RfcConfigParameters cfgParams;
SAP.Middleware.Connector.RfcDestination destination;
SAP.Middleware.Connector.IRfcFunction rfcFunction;
SAP.Middleware.Connector.IRfcStructure RFCSI;
cfgParams = new SAP.Middleware.Connector.RfcConfigParameters();
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Name, "Test");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.AppServerHost, "ABAP702");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.SystemNumber, "00");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Client, "001");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.User, "BCUSER");
cfgParams.Add(SAP.Middleware.Connector.RfcConfigParameters.Password, "minisap");
destination = SAP.Middleware.Connector.RfcDestinationManager.GetDestination(cfgParams);
rfcFunction = destination.Repository.CreateFunction("RFC_SYSTEM_INFO");
rfcFunction.Invoke(destination);
RFCSI = rfcFunction.GetStructure("RFCSI_EXPORT");
//-Get a few information------------------------------------------------
Host = RFCSI.GetValue("RFCHOST").ToString();
SysID = RFCSI.GetValue("RFCSYSID").ToString();
DBHost = RFCSI.GetValue("RFCDBHOST").ToString();
DBSys = RFCSI.GetValue("RFCDBSYS").ToString();
//-End of Invoke Code---------------------------------------------------
Console.WriteLine(Host);
Console.WriteLine(SysID);
Console.WriteLine(DBHost);
Console.WriteLine(DBSys);
}
}
//-End------------------------------------------------------------------
At the beginning I add the platform and references. Also I add the usings, the class and Main. This is something that Uipath does for us. Now I define four variables, exact the same as the parameters of the Invoke Code activity in UiPath. At the end the output of the variables, also exact the same as the WriteLine activity. And that’s it.
This approach can be used to pre-develop C# Invoke Code activities. This makes it much easier to test your code, also because the behavior of the code can be explore with a debugger line by line. Notepad++ and CS-Script plugin are a great combination to develop C# programs and therewith Invoke Code sequences for UiPath. Both are easy to handle, easy to install and both needs tiny space.