user2678195
user2678195

Reputation: 11

Creating Lotus Notes plugin for calendar entries via Java

I have a project to create a plugin for Lotus Notes, which can create new calendar entries and gets data of existing calendar entries.

Preferences

What I've done so far:

I did a toolbar button where a calendar entry is created with when clicked. After pressing 'F9' the created calendar entry is displayed on the lotus notes calendar, but when I click on it, I'm getting an error warning 'IBM Notes: Object variable not set'. I searched this issue via Google and found out, that I have to set up access rights on the ACL. I tried this in different ways, but nothing worked so far.

Here my code:

package com.acme.plugin;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

        try {

            NotesThread.sinitThread();
            Session session = NotesFactory.createSession();

            DbDirectory dir = session.getDbDirectory(null);
            Database db = dir.openMailDatabase();
            Document document = db.createDocument();

            MeetingInformation dummyData = createDummyData(session);

            // Testing if calendar read and write rights are given
            int accLevel = db.queryAccess(dummyData.getUsername());
            int accPriv = db.queryAccessPrivileges(dummyData.getUsername());
            boolean blnCanWriteCalendar = ((accPriv & Database.DBACL_WRITE_PUBLIC_DOCS) > 0)
                    | accLevel > ACL.LEVEL_AUTHOR;
            boolean blnCanReadCalendar = ((accPriv & Database.DBACL_READ_PUBLIC_DOCS) > 0)
                    | accLevel >= ACL.LEVEL_READER;

            if ((blnCanWriteCalendar && blnCanReadCalendar) == false) {
                ACL acl = db.getACL();
                ACLEntry entry = acl.getEntry(dummyData.getUsername());
                entry.setPublicReader(true);
                if (entry.isPublicReader())
                    System.out.println("PublicReader = true");
                entry.setPublicWriter(true);
                if (entry.isPublicWriter())
                    System.out.println("PublicWriter = true");
                acl.save();
            }

            createCalenderEntry(document, session, dummyData);

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

    private void createCalenderEntry(Document document, Session session,
            MeetingInformation meetingInformation) {

        try {
            // Appointment Type
            document.replaceItemValue("Form", "Appointment");
            document.replaceItemValue("AppointmentType", meetingInformation
                    .getAppointmentType());

            // Subject, Location
            document.replaceItemValue("Categories", "Meeting");
            document.replaceItemValue("Location", meetingInformation
                    .getLocation());
            document.replaceItemValue("Subject", meetingInformation
                    .getSubject());
            document.replaceItemValue("Body", meetingInformation
                    .getDescription());

            // Creator of meeting
            document
                    .replaceItemValue("Chair", meetingInformation.getUsername());
            document.replaceItemValue("AltChair", meetingInformation
                    .getUsername());
            document.replaceItemValue("From", meetingInformation.getUsername());
            document.replaceItemValue("Principal", meetingInformation
                    .getUsername());
            document.replaceItemValue("$AltPrincipal", meetingInformation
                    .getUsername());

            // Remind settings
            document.replaceItemValue("Alarm", 1);
            document.replaceItemValue("AlarmOffset", -15);
            document.replaceItemValue("Alarms", 1);

            // Icon
            switch (Integer.parseInt(meetingInformation.getAppointmentType())) {
            case 0:
                document.replaceItemValue("_ViewIcon", 160);
                document.replaceItemValue("$IconSwitcher", "Appointment");
                break;
            case 1:
                document.replaceItemValue("_ViewIcon", 63);
                document.replaceItemValue("$IconSwitcher", "Anniversary");
                break;
            case 2:
                document.replaceItemValue("_ViewIcon", 9);
                document.replaceItemValue("$IconSwitcher", "AllDayEvent");
                break;
            case 3:
                document.replaceItemValue("_ViewIcon", 158);
                document.replaceItemValue("$IconSwitcher", "Meeting");
                break;
            case 4:
                document.replaceItemValue("_ViewIcon", 10);
                document.replaceItemValue("$IconSwitcher", "Reminder");
                break;
            default:
                document.replaceItemValue("_ViewIcon", 158);
                document.replaceItemValue("$IconSwitcher", "Meeting");
            }

            /* date and time ----- */
            // date in format dd/mm/yyyy
            DateTime startDay = session.createDateTime(meetingInformation
                    .getStartDay());

            // time in format hh/mm/ss (AM|PM)
            DateTime startTime = session.createDateTime(meetingInformation
                    .getStartTime());
            DateTime endTime = session.createDateTime(meetingInformation
                    .getEndTime());

            document.replaceItemValue("CalendarDateTime", startDay);
            document.replaceItemValue("StartDateTime", startTime);
            document.replaceItemValue("EndDateTime", endTime);
            document.replaceItemValue("StartDate", startDay);
            document.replaceItemValue("EndDate", startDay);
            document.replaceItemValue("EndTime", endTime);
            document.replaceItemValue("$NoPurge", endTime);
            document.replaceItemValue("tmpStartTime_Local", startTime);
            document.replaceItemValue("tmpEndTime_Local", endTime);

            // save document and alarm
            document.save(true);
            document.putInFolder("$Alarms", true);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private MeetingInformation createDummyData(Session session) {

        MeetingInformation meetingInformation = new MeetingInformation();
        try {
            meetingInformation.setUsername(session.getUserName());
            meetingInformation
            .setSubject("Created Meeting by plugin");
            meetingInformation.setAppointmentType("3");
            meetingInformation.setStartTime("01:00:00 PM");
            meetingInformation.setEndTime("02:00:00 PM");
            meetingInformation.setStartDay("12/08/2013");
            meetingInformation.setEndDay("12/08/2013");
            meetingInformation.setRecipient("[email protected]");
            meetingInformation.setDescription("Description: hidden feature");       
            meetingInformation.setLocation("Everywhere");

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

        return meetingInformation;
    }
}

So how do I solve this problem? What has to be done to fix that issue?

I have looked around but just can't seem to find any solution to this issue, any help is appreciated.

Upvotes: 0

Views: 1361

Answers (2)

user2678195
user2678195

Reputation: 11

Now I have a solution for that issue.

The entries are created as drafts, so they must be saved after creating it via java, but they are editable without any error warnings.

Here code example in java:

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

        try {

            NotesThread.sinitThread();
            Session session = NotesFactory.createSession();

            DbDirectory dir = session.getDbDirectory(null);
            Database db = dir.openMailDatabase();

            createCalenderEntry(db, session, createDummyData(session));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void createCalenderEntry(Database database, Session session,
            MeetingInformation meetingInformation) {

        try {
            Document document = database.createDocument();

            // Appointment Type
            document.replaceItemValue("Form", "Appointment");
            document.replaceItemValue("AppointmentType", meetingInformation
                    .getAppointmentType());

            // Subject
            document.replaceItemValue("Subject", meetingInformation
                    .getSubject());
            document.replaceItemValue("Body", meetingInformation
                    .getDescription());

            // Creator of meeting
            document
                    .replaceItemValue("Chair", meetingInformation.getUsername());
            document.replaceItemValue("From", meetingInformation.getUsername());
            document.replaceItemValue("Principal", meetingInformation
                    .getUsername());

            // Icon
            switch (Integer.parseInt(meetingInformation.getAppointmentType())) {
            case 0:
                document.replaceItemValue("_ViewIcon", 160);
                document.replaceItemValue("$IconSwitcher", "Appointment");
                break;
            case 1:
                document.replaceItemValue("_ViewIcon", 63);
                document.replaceItemValue("$IconSwitcher", "Anniversary");
                break;
            case 2:
                document.replaceItemValue("_ViewIcon", 9);
                document.replaceItemValue("$IconSwitcher", "AllDayEvent");
                break;
            case 3:
                document.replaceItemValue("_ViewIcon", 158);
                document.replaceItemValue("$IconSwitcher", "Meeting");
                break;
            case 4:
                document.replaceItemValue("_ViewIcon", 10);
                document.replaceItemValue("$IconSwitcher", "Reminder");
                break;
            default:
                document.replaceItemValue("_ViewIcon", 158);
                document.replaceItemValue("$IconSwitcher", "Meeting");
            }

            /* date and time ----- */
            // date in format dd/mm/yyyy
            DateTime startDay = session.createDateTime(meetingInformation
                    .getStartDay());

            // time in format hh/mm/ss (AM|PM)
            DateTime startTime = session.createDateTime(meetingInformation
                    .getStartTime());
            DateTime endTime = session.createDateTime(meetingInformation
                    .getEndTime());

            document.replaceItemValue("CalendarDateTime", startDay);
            document.replaceItemValue("StartDateTime", startTime);
            document.replaceItemValue("EndDateTime", endTime);
            document.replaceItemValue("StartDate", startDay);
            document.replaceItemValue("StartTime", startTime);
            document.replaceItemValue("EndDate", startDay);
            document.replaceItemValue("EndTime", endTime);
            document.replaceItemValue("$NoPurge", endTime);
            document.replaceItemValue("tmpStartTime_Local", startTime);
            document.replaceItemValue("tmpEndTime_Local", endTime);

            document.replaceItemValue("$PublicAccess", "1");
            document.replaceItemValue("MailOptions", "");
            document.replaceItemValue("$CSFlags", "m");
            document.replaceItemValue("$CSVersion", "2");
            document.replaceItemValue("ExcludeFromView", "D");

            // save document and alarm
            document.save(false, true);

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

    }

    private MeetingInformation createDummyData(Session session) {

        MeetingInformation meetingInformation = new MeetingInformation();
        try {
            meetingInformation.setUsername(session.getUserName());
            meetingInformation
            .setSubject("Meeting title");
            meetingInformation.setStartTime("01:00:00 PM");
            meetingInformation.setEndTime("02:00:00 PM");
            meetingInformation.setStartDay("12/08/2013");
            meetingInformation.setEndDay("12/08/2013");
            meetingInformation.setLocation("Everywhere");
            meetingInformation.setDescription("Description");
            meetingInformation.setRecipient("[email protected]");
            meetingInformation.setAppointmentType("3");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return meetingInformation;
    }
}

Upvotes: 1

Frantisek Kossuth
Frantisek Kossuth

Reputation: 3524

"Object variable not set" is common Lotusscript error. I suppose, something fails when opening your entry. It might be missing field or wrong value in some field.

The best approach is to compare your document at field level (properties box) with exactly the same entry you make manually.

If it fails, start debugger and find problematic piece of code.

Upvotes: 1

Related Questions