Invalid Timezone for Recurring event on Google Calendar API V3 - api

i'm trying to manipulate somme specific things with google events, i can add, delete, get all events and put colors on events, But i Have a problem , each time i ty to insert a recurring event , i get not valid timezone message and i don't know how to fix it :/
This my code :
public void AddRecurringEvents(Calendar service, Event createdEvent,
String rule, String Summary, String Location) {
Event event = new Event();
// Define Date Time for each start and end time.
DateTime start = DateTime.parseRfc3339("2014-09-30T10:00:00Z");
DateTime end = DateTime.parseRfc3339("2014-09-30T10:25:00Z");
event.setStart(new EventDateTime().setDateTime(start).setTimeZone(
"Europe/Paris"));
event.setEnd(new EventDateTime().setDateTime(end).setTimeZone(
"Europe/Paris"));
// Setting recurrence
event.setRecurrence(Arrays.asList(rule));
try {
Event recurringEvent = service.events().insert("primary", event)
.execute();
System.out.println(createdEvent.getId());
} catch (IOException e) {
e.printStackTrace();
}
}
Any ideas how to fix this problem ?? is there something wrong with my code ...
THanks

Try something like this:
Event event = new Event();
event.setSummary(en.name);
event.setDescription(en.desc);
event.setStatus("confirmed");
ArrayList<String> recurrence = new ArrayList<String>();
recurrence.add("RRULE:FREQ=YEARLY;WKST=MO;");
event.setRecurrence(recurrence);
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(en.year, en.month-1, en.day,0,0,0);
Date startDate = cal.getTime();
Date endDate = new Date(startDate.getTime()); // same Time
DateTime start = new DateTime(startDate, TimeZone.getTimeZone("Europe/Paris"));
event.setStart(new EventDateTime().setDateTime(start).setTimeZone("Europe/Paris"));
DateTime end = new DateTime(endDate, TimeZone.getTimeZone("Europe/Paris"));
event.setEnd(new EventDateTime().setDateTime(end).setTimeZone("Europe/Paris"));
Event createdEvent = client.events().insert( "primary", event).execute();

Related

VSTO Outlook How to get the previous AppointmentItem in a chain of AppointmentItems within recurring meetings

I am currently developing an Outlook Addin for AppointmentItem. In case the AppointmentItem is a member of a recurring meeting "chain" I want to retrieve/find the AppointmentItem which is the previous meeting. How can I do that?
I figured out the following part-solution:
Outlook.AppointmentItem item = (Outlook.AppointmentItem)inspector.CurrentItem;
if (item.IsRecurring) {
Outlook.RecurrencePattern pattern = item.GetRecurrencePattern();
Outlook.OlRecurrenceType occurenceType = pattern.RecurrenceType;
int dayFactor = 0;
switch (occurenceType) {
case Outlook.OlRecurrenceType.olRecursDaily:
dayFactor = 1;
break;
case Outlook.OlRecurrenceType.olRecursWeekly:
default:
dayFactor = 7;
break;
// TODO handly all other cases of RecurrenceType
}
Outlook.AppointmentItem lastItem = pattern.GetOccurrence(item.StartInStartTimeZone.AddDays(-1*pattern.Interval*dayFactor));
But this handles only very few "easy" cases.
Especially when it comes to calculate e.g. every first tuesday per month it gets too tricky for me. Any input? This code sample might be usefull, too: http://www.outlookcode.com/codedetail.aspx?id=1414
In fact I found an answer which is a little bit inefficient but very powerfull as you don't have to care about any recurring rules outlook may have. First any recurring rule does not change the time of the occurence meaning that recurring appointments take place at the very same point in time during the day. Second
GetOcurrences(DateTime)
throws an exception if there is no AppointmentItem at the given DateTime.
And finally the RecurrencePattern gives you the
PatternStartDate
So all what you need to do is check each and every day backwards, beginning at the given AppointmentItem and ending at PatternStartDate.
This is my implementation which of course can be written better, but it works well:
if (myAppointment.IsRecurring)
{
Outlook.RecurrencePattern pattern = myAppointment.GetRecurrencePattern();
bool doContinue = true;
Outlook.AppointmentItem lastAppointmentItem = null ;
int currentDay = -1;
while (doContinue) {
try
{
DateTime currentDate = myAppointment.StartInStartTimeZone.AddDays(currentDay);
if (currentDate < pattern.PatternStartDate)
{
doContinue = false;
lastAppointmentItem = null;
}
else
{
lastAppointmentItem = pattern.GetOccurrence(currentDate);
if (lastAppointmentItem != null)
{
doContinue = false;
}
else
{
currentDay -= 1;
}
}
}
catch (Exception ex)
{
currentDay -= 1;
}
}
....
The same approach can be used to create an Array of all Orccurences. It'll take some time to calculate all and I don't know how to handle open ended series. But that was not the question for this stackoverflow item.
Not easily. You'd need to expand the series explicitly in your code taking into account the recurrence pattern and the exceptions or you can try all suspect dates until GetOccurrence succeeds.
If using Redemption (I am its author) is an option, its version of RDORecurrencePattern.GetOccurrence method allow to pass an integer index (besides the date a-la OOM) as a parameter, so you can build an array of occurrences.

Asp.Net Entity Framework textbox to database

New to this.
I have a database, one table "Logins":
FirstName, LastName, Birthdate, Email
I am using VS2015 and I am using Entity Framework 6 and have my database loaded in through there. I have text boxes and I want the data entered in them to insert into the table "Logins" when submit is clicked.
I've been looking online and watching videos an I just seem to be getting more confused. How do I do this?
This is what I have on the back end code (the front just has the textboxes and submit button):
protected void btnSubmit_Click(object sender, EventArgs e)
{
using (LoginData2Entities lg = new LoginData2Entities())
{
DateTime birthdate = DateTime.Parse(tbBirth.Text);
Logins l = new Logins();
l.FirstName = tbFirstName.Text;
l.LastName = tbLastName.Text;
l.Birthdate = birthdate;
l.Email= tbEmail.Text;
lg.SaveChanges();
}
Nothing is saving to the database. How do I fix this?
You are not adding the Login object l with your LoginData2Entities object so there is nothing to save into the database.. add this in your code.
lg.Logins.Add(l);
it will look like this..
using (LoginData2Entities lg = new LoginData2Entities())
{
DateTime birthdate = DateTime.Parse(tbBirth.Text);
Logins l = new Logins();
l.FirstName = tbFirstName.Text;
l.LastName = tbLastName.Text;
l.Birthdate = birthdate;
l.Email= tbEmail.Text;
lg.Logins.Add(l);
lg.SaveChanges();
}
you are not adding the object to database before performing savechanges..
using (LoginData2Entities lg = new LoginData2Entities())
{
DateTime birthdate = DateTime.Parse(tbBirth.Text);
Logins l = new Logins();
l.FirstName = tbFirstName.Text;
l.LastName = tbLastName.Text;
l.Birthdate = birthdate;
l.Email= tbEmail.Text;
lg.Logins.Add(l); //add the object
lg.SaveChanges();
}

Custom Timer Job is not working in production

I have a document library called Documents in production. I wrote a timer job for sending emails based on the columns in the library.
Everything was fine in the dev environment but the timer job in prod is giving me exceptions. Any ideas?
Entering monitored scope (Timer Job Corporate Policies - Reminder Emails)
The Execute method of job definition CorporatePolicyReminders.DailySchedule (ID 3586f4d2-1bc1-4770-b5b8-4c2c578ee8d5) threw an exception. More information is included below. Object reference not set to an instance of an object.
Exception stack trace:
at CorporatePolicyReminders.CorporatePolicyReminders.SendCorporateReminder(SPWeb web)
at CorporatePolicyReminders.DailySchedule.Execute(Guid contentDbId)
at Microsoft.SharePoint.Administration.SPTimerJobInvokeInternal.Invoke(SPJobDefinition jd, Guid targetInstanceId, Boolean isTimerService, Int32& result)
Leaving Monitored Scope (Timer Job Corporate Policies - Reminder Emails). Execution Time=364.288198639771
SendCorporateReminers Method
public void SendCorporateReminder(SPWeb web)
{
SPList lstComplaint = Helper.GetList(web, "Documents", Helper.ListType.Library);
if (lstComplaint != null)
{
string query = "<Where><Eq><FieldRef Name='DocFormat' /><Value Type='Choice'>Policy</Value></Eq></Where>";
SPListItemCollection colRecords = Helper.ExecuteQueryRecursive(lstComplaint, query, null, 2000);
if (colRecords != null && colRecords.Count > 0)
{
foreach (SPListItem item in colRecords)
{
DateTime Expires = Helper.GetSPFieldDateTimeValue(item, "Expires");
String Title = Helper.GetSPFieldTextValue(item, "Title");
SPFieldUserValueCollection userResp = Helper.GetUsers(item, "Contact");
TimeSpan totaldays = DateTime.Now.Date - Expires.Date;
Int32 days = totaldays.Days;
String emailtemplatekeyA = "AEmail" + days.ToString();
String emailtemplatekeyB = "BEmail" + days.ToString();
String respToEmail = String.Empty;
if (userResp != null && userResp.Count > 0)
{
foreach (SPFieldUserValue user in userResp)
{
if (!string.IsNullOrEmpty(respToEmail))
respToEmail += ",";
respToEmail += user.User.Email;
}
}
HandleEmails handleEmail = new HandleEmails();
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.EmailRecipient, PlaceHolder.USERRESP.ToString(), respToEmail);
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.TITLE.ToString(), Title);
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.EXPDT.ToString(), Expires.ToShortDateString());
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.ID.ToString(), item.ID.ToString());
handleEmail.SendMail(web, emailtemplatekeyA);
handleEmail = new HandleEmails();
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.EmailRecipient, PlaceHolder.USERRESP.ToString(), respToEmail);
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.TITLE.ToString(), Title);
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.EXPDT.ToString(), Expires.ToShortDateString());
handleEmail.AddValueToPlaceholder(HandleEmails.EmailPlaceHolders.SendingTypeValue.OTHER, PlaceHolder.ID.ToString(), item.ID.ToString());
handleEmail.SendMail(web, emailtemplatekeyB);
}
}
}
}`
I found the issue and resolved it.Person whose userid is no longer valid is Contact the person of document (he is in contact column for the library i am creating timer job). So timer job is throwing exception (Object reference not set to an instance of an object.) whenever it is trying to read Contact column of the document. i figured it out by modifying my code as below and i removed that person from that column.
Helper.WriteUlsInformation("Item processing:" + i.ToString(), TraceSeverity.Verbose);
DateTime Expires = Helper.GetSPFieldDateTimeValue(item, "Expires");
Helper.WriteUlsInformation("Expires:" + Expires.ToString(), TraceSeverity.Verbose);
String Title = Helper.GetSPFieldTextValue(item, "Title");
Helper.WriteUlsInformation("Title:" + Title, TraceSeverity.Verbose);
SPFieldUserValueCollection userResp = Helper.GetUsers(item, "Contact");
Helper.WriteUlsInformation("UserResp read" , TraceSeverity.Verbose);
TimeSpan totaldays = DateTime.Now.Date - Expires.Date;
Int32 days = totaldays.Days;
Helper.WriteUlsInformation("Days:"+ days.ToString(), TraceSeverity.Verbose);
String emailtemplatekeyA = "AEmail" + days.ToString();
String emailtemplatekeyB = "BEmail" + days.ToString();
String respToEmail = String.Empty;

Example Program to insert a row using BAPI with JCO3

I am trying to "insert" (or) "add a row" to Purchase Requisition using standard BAPI (PurchaseRequisition.CreateFromData).
I am using JCo3. The example in JCo3 indicates that we should use table.appendRow() OR table.insertRow() methods. I am trying with table.appendRow() & table.appendRows(1). When i try to insert a row, i dont get any error and the row is not inserted.
Below is the program i am trying to execute.
/** Below are the inputs required for this program to run /
/ Step 1 **/
String BAPI_NAME = "BAPI_REQUISITION_CREATE";
/** Step 2 **/
String query_input_column1 = "DOCUMENTY_TYPE";
String query_input_column1_value = "NB";
String query_input_column2 = "PREQ_NAME";
String query_input_column2_value = "Name";
String query_input_column3 = "ACCTASSCAT";
String query_input_column3_value = "U";
String query_input_column4 = "DELIV_DATE";
String query_input_column4_value = "20131101";
String query_input_column5 = "MATERIAL";
String query_input_column5_value = "DELL-RQ2013";
String query_input_column6 = "QUANITY";
int query_input_column6_value = 10100;
/** Step 3 **/
String targetTableUnderBAPI = "REQUISITION_ITEMS";
/** Step 4 **/
/** For the confirmation read the value from export parameter after insertion execution **/
String result_column1 = "NUMBER";
JCoDestination destination = null;
try {
destination = JCoDestinationManager.getDestination(DestinationManager.DESTINATION_NAME1);
JCoRepository repository = destination.getRepository();
JCoContext.begin(destination);
JCoFunction function = repository.getFunction(BAPI_NAME);
if(function == null)
throw new RuntimeException(BAPI_NAME + " not found in SAP.");
System.out.println("BAPI Name from function object: " + function.getName());
//function.getImportParameterList().setValue(query_input_column1, query_input_column1_value);
JCoTable table = function.getTableParameterList().getTable(targetTableUnderBAPI); //it is taken from the response value of metadata
//System.out.println("No of Columns: "+ table.getNumColumns());
System.out.println("Trying to execute append row");
table.appendRow();
table.setValue(query_input_column1,query_input_column1_value);
table.setValue(query_input_column2,query_input_column2_value);
table.setValue(query_input_column3,query_input_column3_value);
//table.setValue(query_input_column4,new java.util.Date(query_input_column4_value));
//skipped Other columns related code
try{
function.execute(destination);
}
catch(AbapException e){
System.out.println(e.toString());
return;
}
System.out.println("Let us check the result from export parameter");
String exportParamStructure = (String)function.getExportParameterList().getValue(result_column1); //getStructure(result_column1); // getValue(result_column1);
System.out.println("Resulting PR#: "+exportParamStructure);
} catch (JCoException e) {
e.printStackTrace();
}
finally
{
try {
JCoContext.end(destination);
} catch (JCoException e) {
e.printStackTrace();
}
}
I did not understand how to read the response and am trying to fetch it from exportParameters!!
Can anybody share a piece of code to insert and
getting confirmation response (do we get the PREQ_NO in response?)
I am adding date field value as "20131101", but not sure if the format and approach is right?
when i try to add Quantity column value, i get an error message complaining this column is not part of BAPIEBANC. But the column is visible in BAPIEBANC type.
any configuration on SAP side to be checked?
should i activate any fields in JCo side? if so, how
Please note that my knowledge on SAP is very limited.
Waiting for an expert's response.
Thanks.
First, you should take a look at SAP JCo documentation, e.g.
http://help.sap.com/saphelp_nw04/helpdata/en/6f/1bd5c6a85b11d6b28500508b5d5211/content.htm
Regarding your code:
Adding (one) row to the table looks right on first sight.
Your code says QUANITY instead of QUANTITY.
You should add date values as java.util.Date; if creating a Date from a String format, you should use java.text.DateFormat.parse(). See http://docs.oracle.com/javase/6/docs/api/java/util/Date.html (this is however Java specific and has nothing to do with JCo).
If changing anything in SAP, never forget to call BAPI_TRANSACTION_COMMIT in the end to finish the logical unit of work (aka transaction) or nothing will actually be changed.
If you don't like to fiddle with the more or less complicated and verbose JCo API, try using Hibersap which gives you a much nicer programming model when calling functions in SAP ERP: http://hibersap.org.
However, you will still need a basic understanding on how SAP function modules work technically (such as parameter types or data types) as well as on the domain specific model which lies behind them (in your case, creating a requisition). I.e. you may need to communicate with your SAP experts.
Here I added 2 types of insertion :
insertval() function for user defined module resides in sap with the help of abap programmer
Its an standard module for insert a ticket using jco to SOLMAN system. First you have to analyse import, export, table & structure parameters, and according to that you have to pass values and retrieve response. In second function it will return ticket n° after successfull insertion of ticket in solman.
I hope this sample code will help you, it worked for me.
public class jco
{
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.1.1.1");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "01");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "500");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "uname");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "pwd");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDestinationDataFile(DESTINATION_NAME2, connectProperties);
System.err.println("hai");
}
static void createDestinationDataFile(String destinationName, Properties connectProperties)
{
File destCfg = new File(destinationName+".jcoDestination");
try
{
try (FileOutputStream fos = new FileOutputStream(destCfg, false)) {
connectProperties.store(fos, "for tests only !");
}
}
catch (IOException e)
{
throw new RuntimeException("Unable to create the destination files", e);
}
}
public void insertval() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1);
JCoFunction jf=destination.getRepository().getFunction("ZUSER_DET");
jf.getImportParameterList().setValue("FIRST_NAME","member");
jf.getImportParameterList().setValue("LAST_NAME","c");
jf.getImportParameterList().setValue("USER_NO","1000");
jf.execute(destination);
System.out.println(jf);
}
public void insertticket() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
System.out.println("test"+"\n");
JCoFunction jf=destination.getRepository().getFunction("BAPI_NOTIFICATION_CREATE");
JCoTable jt1=jf.getTableParameterList().getTable("APPX_HEADERS");
JCoTable jt2=jf.getTableParameterList().getTable("APPX_LINES");
JCoTable jt3=jf.getTableParameterList().getTable("APPX_LINES_BIN");
JCoTable jt4=jf.getTableParameterList().getTable("NOTIF_NOTES");
JCoTable jt5=jf.getTableParameterList().getTable("NOTIF_PARTNERS");
JCoTable jt6=jf.getTableParameterList().getTable("NOTIF_SAP_DATA");
JCoTable jt7=jf.getTableParameterList().getTable("NOTIF_TEXT_HEADERS");
JCoTable jt8=jf.getTableParameterList().getTable("NOTIF_TEXT_LINES");
JCoStructure jfn1=jf.getImportParameterList().getStructure("NOTIF_EXT");
JCoStructure jfn2=jf.getImportParameterList().getStructure("NOTIF_CRM");
JCoStructure jfn3=jf.getImportParameterList().getStructure("IBASE_DATA");
jfn1.setValue("NUMB","1234");
jfn1.setValue("REFNUM","123");
jfn1.setValue("TYPE_NOTIF","SLFN");
jfn1.setValue("SUBJECT","tl");
jfn1.setValue("PRIORITY","2");
jfn1.setValue("LANGUAGE","EN");
jfn1.setValue("CATEGORY","Z01");
jfn2.setValue("CODE","0011");
jfn2.setValue("CODEGROUP","0011");
jfn2.setValue("CATEGORY","Z01");
jfn3.setValue("INSTANCE","489");
jfn3.setValue("IBASE","500");
jt1.appendRow();
jt1.setValue("DESCR","practise");
jt2.appendRow();
jt2.setValue("LINE","CVXCVXCV");
jt3.appendRow();
jt3.setValue("LINE","second text line");
jt4.appendRow();
jt4.setValue("TYPE_NOTE","my");
jt4.setValue("IDENT","hoe twwrtgw");
jt4.setValue("DESCRIPTION","its description ");
jt5.appendRow();
jt5.setValue("PARNR","new ");
jt5.setValue("TYPE_PAR","FN");
jt5.setValue("FUNC_PAR","EN");
jt5.setValue("PAR_ACTIVE","1");
jt6.appendRow();
jt6.setValue("INSTN","0020214076");
jt6.setValue("COMP","FI-AA");
jt6.setValue("SYSTYPE","P");
jt6.setValue("SYSID","PRD");
jt6.setValue("MANDT","900");
jt8.appendRow();
jt8.setValue("TXT_NUM","1");
jt8.setValue("TDFORMAT",">X");
jt8.setValue("TDLINE","/(performing all test)");
jf.execute(destination);
String jfex=jf.getExportParameterList().getString("REFNUM");
System.out.println("hi "+jfex);
}

GWT-Ext DatePicker.setDisabledDatesRE

Does anyone have any experience using the GWT-Ext DatePicker.setDisabledDatesRE(String re) method? I have done the following, and the dates specified in the regular expressions are still selectable. I have been able to disable dates using setDisabledDays, but I need to exclude dates based on criteria other than day of week.
I'm using GWT 1.6.4 and GWT-Ext 2.0.5.
Thanks.
...
import com.gwtext.client.widgets.DatePicker;
...
public class MySimpleDatePicker implements EntryPoint {
public void onModuleLoad() {
final Panel panel = new Panel();
final Panel calendarPanel = new Panel();
DatePicker datePicker = new DatePicker();
Date initialDate = new Date();
datePicker.setFormat("yyyy-mm-dd");
datePicker.setValue(initialDate);
String ddRE = "2009-09-28|2009-09-29";
datePicker.setDisabledDatesRE(ddRE);
calendarPanel.add(datePicker);
panel.add(calendarPanel);
RootPanel.get().add(panel);
}
}
I figured this out. The argument to setFormat should be "Y-m-d", like this:
DatePicker datePicker = new DatePicker();
Date initialDate = new Date();
datePicker.setFormat("Y-m-d");
System.out.println("date format is: " + datePicker.getFormat());
datePicker.setMinDate(initialDate);
datePicker.setValue(initialDate);
String ddRE = "09-09-28|09-09-29";
datePicker.setDisabledDatesRE(ddRE);