Tim Edelmann Posted February 13, 2018 Report Share Posted February 13, 2018 Hey there, as part of our integrations, we want to be able to setup entries in the 'overview calendar' for 'projects and users'. for example 'Add Leave' should be available. Ideally this should be done via external api-calls in javascript. by executing this: console.info(Object.keys(session.schemas)); for (schema in session.schemas) { console.info(session.schemas[schema]); } We found out, that there is something called: 'CalendarEvent'. Are we on the right track, playing with this? Since we don't know, how to deal with this, we shoot in every direction.. Is it possible to 'Add Leave' for a user via the javascript api? If yes, how is it done? We tried this: var query = 'select id from CalendarEvent'; But the result is: '(node:7332) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: request is not defined' Any help/assistance/ideas are greatly appreciated! thanks in advance Tim Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 13, 2018 Author Report Share Posted February 13, 2018 Update* having this.. date_begin = Date(2018, 1, 13); date_end = Date(2018, 1, 15); var obj = { id: 'CalendarEvent', name: 'TEdelmann', start: date_begin, end: date_end }; var result = session.create("CalendarEvent", obj); console.info(result); we get a "Promise { <pending> }" result. But it seems, we do not provide the correct parameters, or something else isn't correct. Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 13, 2018 Author Report Share Posted February 13, 2018 Update2* if we handle the result (from last post), it seems to get added. We are able to list calendarevents for user 'TEdelmann' with this: var query = session.query('select id from CalendarEvent'); query.then(function (response) { console.info('response:\n' + response.data.length + ' entries'); if ('data' in response) { for (entry in response.data) { console.info(response.data[entry]); } } }); But the listed calendarEvents aren't shown on the webinterface (i.e. in the 'Projects and Users' calendar). Is there something else, we have todo? Or is this still the wrong way to do it? thanks again. Link to comment Share on other sites More sharing options...
Mattias Lagergren Posted February 14, 2018 Report Share Posted February 14, 2018 Hi Tim, for it to appear properly in the web interface you will want to do one of the following: Attach it to a project with project_id. Allocate it to a user by creating CalendarEventResource with resource_id and calendar_event_id. Making it a Leave event assigned to someone (see above) or everyone. Attributes are booleans: leave and everyone I hope this helps Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 14, 2018 Author Report Share Posted February 14, 2018 Hey Mattias, thank you very much, took me a few minutes to get it done Very helpful and precise answer! Tim Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 14, 2018 Author Report Share Posted February 14, 2018 ...one last follow-up on this: After having successfully created a 'leave'-entry. How am I supposed to delete it via the api? What I am trying so far.. session.initializing.then(function() { // get user return session.query('select id from User where username = "' + user_name + '"'); }).then(function (user) { user_id = user.data[0].id; // with the user, get the CalendarEventResource with the corresponding resource_id return session.query('select id from CalendarEventResource where resource_id is "' + user_id + '"'); }).then(function (calendar_event_resource) { return [calendar_event_resource, session.query('select id from CalendarEvent where id is "' + calendar_event_resource.data[0].calendar_event_id + '" and name is "' + type + '" and start <= "' + starting_date + '" and end >= "' + ending_date + '"')]; }).then(function(data) { data[1].then(function(result) { // this shows, that the result is 'empty' (i.e. "data: [], metadata: { next: { offset: null } } }" ) console.info(result); }); }); So Its possible to select the calendarEventResource by providing the resource_id. But from there I cannot access the "CalendarEventResource.calendar_event_id" property (as set on creation) to get the correct CalendarEvent linked to it. I want to delete both objects when a vacation gets canceled (CalendarEvent AND CalenderEventResource). Otherwise for each canceled Leave / Vacation there would still be a lonely CalendarEvent lying around, if I just delete the CalendarEventResource!?! and thanks again Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 15, 2018 Author Report Share Posted February 15, 2018 on my follow-up: I solved this myself by getting the CalendarEvent for a given time frame (starting and ending dates) first. This should always be only one result. From there I select the corresponding CalendarEventResource and can delete both objects. But is it somehow possible to retrieve CalendarEvents and read the starting and ending dates? The CalendarEvent I get, only have these properties: { __entity_type__: 'CalendarEvent', id: '5b677504-1245-11e8-a8ac-7ab7a47c9dda' } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.