Import AlnDomain from Excel Sheet

Hello;

Now I will explain a bit about importing from excel sheet. Here I will use Jexcel Api to read excel files. This script was written for Maximo 6.2.1, and I will use Jexcel Api 2.6.9 which can be downloaded from here.
Here is the code:

/*
 * addAlnDomain.java
 *
 * Created on September 2, 2008, 4:00 PM
 */
import java.io.File;
import java.io.PrintStream;
import jxl.*;
import psdi.app.system.*;
import psdi.mbo.MboRemote;
import psdi.util.MXSession;
/**
 *
 * @author  bbolek
 */
public class addAlnDomain {
 
    /** Creates a new instance of addAlnDomain*/
    public addAlnDomain() {
    }
 
    public void add(String filename) {
        try {
            MXSession s;
            s = MXSession.getSession();
            s.setHost("localhost:9898/MXServer"); //Server Name
            s.setUserName("wilson");
            s.setPassword("wilson");
            s.connect();
 
            Workbook workbook = Workbook.getWorkbook(new File(filename + ".xls"));
            Sheet sheet = workbook.getSheet(0);
            int k = 1;
            String description, value;
                MaxDomainSetRemote maxdomain=(MaxDomainSetRemote) s.getMboSet("MAXDOMAIN");
                maxdomain.setWhere("DOMAINID='DOMAINNAME'");
                maxdomain.reset();
                MboRemote maxDomain=maxdomain.getMbo(0);
            while (sheet.getCell(0, k).getContents().length() > 1) {
                value = sheet.getCell(0, k).getContents().toString();
                description = sheet.getCell(1, k).getContents().toString();
                System.out.println("VALUE :"+value+ " DESCRIPTION: "+description );
 
                ALNValueSetRemote alnSet =(ALNValueSetRemote) maxDomain.getMboSet("ALNDOMAINVALUE");
                ALNValueRemote aln = null;
                aln = (ALNValueRemote) alnSet.addAtEnd();
                aln.setValue("VALUE", value);
                aln.setValue("DESCRIPTION", description);
	        alnSet.save();
                k++;
            }
        } catch (Exception E) {
            E.printStackTrace();
        }
}
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        addAlnDomain new_AlnDomain = new addAlnDomain();
        new_AlnDomain.add("Example");
    }
}

In here; between line 28-32 server settings are set. Then on line 34 excel workbook is opened.
On line 35 first sheet is selected. On line 39 the domain with name “DOMAINNAME” is selected.
Line 42 shows that the loop will continue if there is a value on the first column of excel.
Line 43 and 44 reads the excel and sets the variables. And on line 48 we create a new ALNDomain mbo. And on 49 we added it to the AlnDomainSet.
Then we bind the variables and save the MboSet…
On line 62 we set the excel filename…Here it is Example.xls

All Mbo’s can be read from excel and imported to Maximo in this way. It is quite easy and customizable…For example you can set some rules to import in java like
-import data that starts with 1,
-import data which is like ‘%10%’
-etc…

Have a good day…

Tags: , , ,

3 Responses

  1. sam Says:

    hello :) just thanks

  2. pacaltay Says:

    hocam,

    bu kodu volkan erdoğan arkadaşımız kopyaladı. istersen helal et.

    best regards.

  3. Janhavi Says:

    Hi,

    i want to import data through excelsheet or csv file in maximo using integration framework.
    can you please tell me how to do it.(steps)

    i have done export,import using xml and flat files.
    thanks

Leave a Reply