Dec 6, 2016

Read Profile Settings from ISO SDK App

Background

Accessing  Web Services, external data sources from a SDK app is common like other technologies do. To store these access points, parameters etc. can be done in various ways. In a .net application common scenario is store then in the .config file or setting file. Why we want to do like this is, avoid hassles of deployment. When ISO SDK application is considered, we can achieve same thing by using .manifest file.

Problem

I need to get database connection string from the M3 profile.

Solution

  1. Using Profile Editor, add a setting to store database connection string. For this example, I’m going to use setting name as “DbConnection”.
    image
  2. Use the following code to extract above information.
    txtDBConStr.Text= ApplicationServices.SystemProfile.GetProperty("M3", "SDKApp", "DbConnection");
    

Sep 5, 2016

MEC: How to Set Message Counter for EDI Message


When you sending/creating EDI messages it is necessary to include unique message interchange number. This is to ensure each message that we are sending is unique.

In EANCOM/EDIFACT

Element 0020 of UNB segment:
UNB+UNOA:4+xxxxxxx:14+xxxxxx+20160905:0831+00000000000057+    +ORDERS++1'

In X12

Element ISA13 of ISA segment:
ISA*00* *00* *ZZ*167520391 *ZZ*39319445 *991201*1248*U*00200*000000001*0*P*>

This number need to be persistent. The middleware we are using for EDI transformation should cater this requirement. I used MS-BizTalk  Server for two EDI projects, which cater the same. (just by a configuration)

M3 e-Collaborator (MEC) does the same thing in a different way. In the MEC database (e.g. MEC_Storage_TST) has a table (UTIL_Message_Counters) for this purpose.

Table structure is like this:

image

Note 1: To be able to use this class you must first create this table (use the SQL script MeC_Utilities_db_script.sql).

You don’t have to enter a record or write code to save/get data. Instead, you have to write 2 lines of java code in your mapper to get the Value. ( Unique Message Interchange Number)

Note 2: Values in Key fields are case sensitive.

Steps:

  1. Initialize the message counter for the map.
    myMap is reference to the Map.
    MessageCounter mc = new MessageCounter(myMap);
    
  2. Get a new counter value using one of 3 overloads

    /*
    * getNewValue(String counterId)
    * counterID = Choose suitable name (max 20 chars)
    *
    * Returns new counter for the map
    */
     String newVal = mc.getNewValue("MsgCounter");
    

    Or
    /*
    * getNewValue(String counterId, int keyFields);
    * counterID = Choose suitable name (max 20 chars)
    *
    * Returns new counter for the map AND parnter ID
    */
     String newVal = mc.getNewValue("MsgCounter",mc.MAP_NAME + mc.PARTNER_ID);
    

    Or
    /*
    * getNewValue(String counterId, int keyFields, String cono, String divi, String date) 
    * counterID = Choose suitable name (max 20 chars)
    *
    * Returns new counter for the map AND parnter ID AND cono AND divi AND date.
    * you can omit cono and divi by setting null 
    * below code resets the counter for each day (format CCYYMMDD).
    */
     String newVal = mc.getNewValue("MsgCounter",mc.MAP_NAME + mc.PARTNER_ID, null, null, DATE);
    

If, everything OK, you will return the new counter other wise –1.

If you look at the table (UTIL_Message_Counters) , a record has been added and value will be incremented each time when getNewValue() is called.

image

Aug 8, 2016

Compare 2 Word Documents

Microsoft Word came with a handy feature to compare 2 Word documents. But I’ve got to know this very recently.

Background

When I’m getting multiple revisions of the same MS-Word document, how can I make sure that I have seen the changes effectively?

Solution

  1. In MS Word, go to “Review” and select “Compare
    image
  2. Select files to compare
    image
  3. Output looks like this
    image
  4. Double click on red colored line, then you can see the changes. (deletion, insertion etc.)
    image

Jul 22, 2016

MEC: Call Web Service in a cleaner way

Background

In the MEC mapper, calling a web service is a general scenario. There are few ways to do it. One method is build the SOAP request Payload in a string and submit via POST method. (as below code snippet)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
java.net.URL obj = new java.net.URL(iURL);
java.net.HttpURLConnection con = (java.net.HttpURLConnection) obj.openConnection();

con.setRequestMethod("POST");
con.setRequestProperty ("Content-Type","text/xml");
con.setRequestProperty ("Accept","text/xml");

String itemStr = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
			+ "<soap:Body>"
			+ "<GetItem xmlns=\"http://tempuri.org/\">"
			+ "<itemNumber>KelumG</itemNumber>"
			+ "</GetItem>"
			+ "</soap:Body></soap:Envelope>";		
con.setDoOutput(true);
java.io.DataOutputStream wr = new java.io.DataOutputStream(con.getOutputStream());
wr.writeBytes(itemStr);
wr.flush();
wr.close();

This is very primitive and takes lot of times of developer. Also it hinders the code readability & maintainability.

From this post I’m going to tell you a cleaner way, rather simple way. We, programmers, know easy way to call web service is using Proxy objects/classes.

Proxy objects are type of representations of the web service for the programming language we are using.

Solution

  1. Create Proxy class from the web service.
    The service I’m using for this post is http://localhost:4599/HelloService.asmx?wsdl  (refer below P.S. section). There are few tools to create proxy classes in java (wsimport, axis2, java2wsdl etc. ). Here I’m using wsimport with following argument.

    -d KG : store generated class into KG folder

    wsimport -d KG http://localhost:4599/HelloService.asmx?wsdl command to create proxy classes.

    image
  2. Create jar file for the generated files.
    Using command line: https://docs.oracle.com/javase/tutorial/deployment/jar/build.html
    Using Eclipse: http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-33.htm

    Note:
    There are limitations for customer JARs. ( Page # 85, Business Document Mapper, Version 11.4.3.0)
    Package
    To use a Java class from a Custom JAR in a mapping, the class has to use a package. The default package, that is no package, will not work. Note that you have to enter this package for all references to the custom class in the code for Java functions within a mapping.

    Javadoc, encoding
    If you want to get Javadoc in the mapping Java editor when using a Java class from a Custom JAR, the Java source code, that is, the .java file, must be included in the Custom JAR. The .java file must use the character encoding UTF-16, otherwise no Javadoc will be shown in the mapper. This is because the files for the mapping use that encoding.
  3. In the map add reference to this custom JAR file.
    image
  4. Simply call the service just like a method.
    1
    2
    3
    4
    5
    6
    private void callWebSvc() throws Throwable {
    	// Please implement me
    	org.tempuri.HelloService hs = new org.tempuri.HelloService(new java.net.URL(iUrl));
    	org.tempuri.HelloServiceSoap hsoap= hs.getHelloServiceSoap();
    	oItem = hsoap.getItem(iItem);
    }
    


P.S:

For this post I have created a mock web service (.asmx ) using C# and hosted in IIS. Sample code as below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
namespace WebServiceApp
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class HelloService : System.Web.Services.WebService
    {
        [WebMethod]
        public string GetItem(string itemNumber)
        {
            return new ItemService().GetItem(itemNumber);
        }
    }

    public class ItemService
    {
        public string GetItem(string itno)
        {
            return string.Format("Item {0}",itno);
        }
    }

image

Jun 30, 2016

MEC: Change out file name dynamically

Background

Manipulating the out file name generated by the middle ware is a common scenario. By default file names are generated with a GUID (13a7a838-a706-4273-b190-9d58a79bf04e). It is more practical if the file name is human readable.

Solution

  1. In the Mapper add User function to change the file name. (Note: this function should the last function in the map)
    image
  2. Add similar code to the function. This code set file name to the manifest information of the map.
    1
    2
    3
    4
    5
    6
    String date = new java.text.SimpleDateFormat("yyMMdd").format(new java.util.GregorianCalendar().getTime());
    String time = new java.text.SimpleDateFormat("HHmmss").format(new java.util.GregorianCalendar().getTime());
    
    String fileName  = "EDI_832_OUT_"+ date+time;
    
    setManifestInfo("map:FileName", fileName);
    
  3. Then, configure the relevant Send (in partner agreement) object to take the given file name.
    image
  4. And you are done. !!!

Jun 5, 2016

Development with MEC older version

Presently I’m working with a MEC older version (Ver 9.1).

This version is not part of an Eclipse plugin. It’s a standalone application that use for MEC mapper development. Very tedious to work with.

MEC Mapper different than the Eclipse version. But Flat file definition tool, it’s manager & the partner agreement tool looks the same.

Mapping manger looks like this.

Mapping Manger

  1. Load button to retrieve all the existing mappings.
  2. New button to create a new one
  3. Generate & Publish buttons to compile the map & deploy to the server
  4. Import & export button: Once you create a map, you cannot change it. Instead, import existing version and export with a new changes and new version number

Mapper looks like this.

Mapper

  1. Mapping flow is organized in “tree-view” like structure.
  2. You can generate the map from this screen. But to publish you have to close this and go back to Mapping manger & publish.
  3. Two options to save (to DB & to File)
  4. Validate map option also available on this screen.

Mar 28, 2016

ISO SDK : Unkown Error

Problem

I’ve got following error when I try to testing after configuring ISO SDK.
ISO_ERROR_Unknown

Solution

When you configure “SERVER” path in the registry entry  (HKEY_CURRENT_USER\Software\Lawson\MangoDev)  make sure correct path of LSO server path is set.  

How to get correct LSO PATH?

  1. Go to the log viewer of the LSO by clicking
    LogView
  2. Then select following entry & copy LSO server path
    LSOServerPath

What I got wrong?

I’ve set LSO client installation path (that can be access through Web browser) to the “Server” registry entry.