Showing posts with label CE Custom Object API. Show all posts
Showing posts with label CE Custom Object API. Show all posts

Wednesday 11 May 2016

Java Sample Code for Creating Custom Object in FileNet

// Java Sample Code for Creating Custom Object in FileNet

public void CreateCustomObject(Connection conn) {


try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);

System.out.println("del"+folderOj.get_Name());

//Creaing Custome Object and setting properties

CustomObject myObject= Factory.CustomObject.createInstance(objStore,"Student"); //Object store, Costome Object Class Name
com.filenet.api.property.Properties props = myObject.getProperties();
props.putValue("TitleName","stuInfo022");
props.putValue("StuID", "RK1234");
props.putValue("StuMailID", "p8@filenet.com");
props.putValue("age", 13);
DateFormat date = new SimpleDateFormat("dd/MM/yyyy");
Date memeberDate= date.parse("20/12/2015");
props.putValue("JoiningDate", memeberDate);
myObject.save(RefreshMode.REFRESH);
System.out.println("Customobject " + myObject.get_Name() + " created");

//Saving the Custome Object into folder
String folder= "/Test";
com.filenet.api.core.Folder folderOj= Factory.Folder.fetchInstance(objStore,folder, null);
ReferentialContainmentRelationship rel = folderOj.file(myObject,AutoUniqueName.AUTO_UNIQUE,null,DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
rel.save(RefreshMode.REFRESH);

} catch (Exception e) {
e.printStackTrace();
}
}

Java Sample code to retrieve a custom object in FileNet

//Java Sample code to retrieve a custom object in FileNet

public void FetchCEObjects(Connection conn) {



try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore objStore = Factory.ObjectStore.fetchInstance(domain,"OSNAME", null);
String customeObjectPath= "/Test/stuInfo022"; // Full Path of Custome Object

CustomObject myObject= Factory.CustomObject.fetchInstance(objStore,customeObjectPath, null);

 
String TitleName= myObject.get_Name();
System.out.println(TitleName+ " Name is retrieved");
 
com.filenet.api.property.Properties props = myObject.getProperties();
 
   String StuID = props.getStringValue("StuID");
String StuMailID= props.getStringValue("ICCMailUID");
Integer age = props.getInteger32Value("age");
Date dateCreated= props.getDateTimeValue(PropertyNames.DATE_CREATED);
Date JoiningDate= props.getDateTimeValue("JoiningDate");
 
   System.out.println("Student ID: " + StuID );
System.out.println("Student age: " + age);
System.out.println("Mail ID: " + StuMailID);
System.out.println("Date created: " + dateCreated);
System.out.println("Joining Date : " + JoiningDate);

} catch (Exception e) {

e.printStackTrace();
}
}