Strategy ONE

Creating a New E-mail Address for Scheduling

This example demonstrates creating a new e-mail address. This address is used for scheduling delivery of reports to this e-mail address. All schedules for e-mail delivery in MicroStrategy Web are displayed under the "Scheduled e-mails" heading on the My Subscriptions page. To access the list of printer locations, go to the Preferences page and click on E-mail Addresses.

Code sample

1.     //create and initialize the bean with the right session

2.     SubscriptionBean sb = WebBeanFactory.getInstance().newSubscriptionBean();

3.     sb.setSessionInfo(factory.getIServerSession());

4.     

5.     //set the delivery mode to be e-mail

6.     sb.setDeliveryMode(EnumWebSubscriptionDeliveryMode.SUBSCRIPTION_DELIVERY_MODE_EMAIL);

7.     //set the content for this subscription

8.     sb.setContent("some report id", EnumWebSubscriptionContentTypes.CONTENT_TYPE_REPORT);

9.     

10.   //set the custom message property

11.   sb.setCustomMessage("This is a test subscription");

12.   

13.   //set the properties specific to e-mail delivery

14.   WebSubscriptionDeliveryModeEmailProperties wdp = (WebSubscriptionDeliveryModeEmailProperties)sb.getDeliveryMode();

15.   wdp.setEmailSubject("TestSubscription");

16.

17.   //set an appropriate trigger -- in this case we just pick the first one

18.   SimpleList triggers = sb.getAvailableTriggers();

19.   sb.setTriggerID(((WebSubscriptionTrigger)triggers.item(0)).getID());

20.

21.   //set an appropriate address -- again we pick the first available address

22.   //if one is not available, we create a new one

23.   SimpleList addresses = sb.getAvailableAddresses();

24.   WebSubscriptionAddress address = null;

25.   if(addresses==null || addresses.size()==0){

26.   SimpleList devices = sb.getAvailableDevices();

27.   address = (WebSubscriptionAddress)factory.getSubscriptionsSource().getNewObject(EnumWebSubscriptionObjectTypes.WEB_SUBSCRIPTION_ADDRESS);

28.   address.setValue("someone@company.com");

29.   address.setDevice((WebSubscriptionDevice)devices.item(0));

30.   address.save();

31.   }else{

32.   address = (WebSubscriptionAddress)addresses.item(0);

33.   }

34.   sb.getAvailableAddresses().add(address.getID());

35.

36.   //handle prompts if required

37.   if(sb.isPersonalized()){

38.   PromptsBean pb = sb.getPromptsBean();

39.   //answer prompts here

40.   }

41.

42.   //save the subscription

43.   sb.save();

Explanation

Line 2 creates and initializes a SubscriptionBean while line 3 sets the session on the bean. Line 6 sets the appropriate delivery mode (e-mail). Line 8 defines the content to be subscribed (report) and line 11 sets a message. Line 14 accesses the delivery properties of this subscription in order to set the e-mail subject. Each type of delivery mode, has a specific set of properties that can be defined. Line 18 retrieves the set of available triggers for this subscription and line 19 picks the first one from this list. Lines 23-34 define how a valid address would be defined for this subscription: Retrieve all available e-mail addresses. If this list is not empty, then use the first address. If this list is empty, then create a new e-mail address. Lines 27-30 retrieve available devices, create a new address for the first device, set an appropriate value for the address and save the address. Line 34 sets the address ID on the subscription. Line 37 handles prompts (if they are present) and line 43 saves the subscription.