Marketcircle    Forums  Hop To Forum Categories  Extending Daylite  Hop To Forums  Scripting    New Appointment(timeblock)
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Apprentice
Posted
I'm new to Daylite and Fscript and am struggling to learn how to Fscript Daylite.

Can anybody help me create a new appointment(timeblock)? I need to add a new timeblock, then assign values/attributes to it.

Thanks for your help.
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
AJ
Marketcircle Team
Picture of AJ
Posted Hide Post
Here is how you do it with FScript:


creation_context := objectContext creationContext.
new_appointment := creation_context createObjectForEntityNamed:'Timeblock' addToObjectContext:true.

start_date := NSCalendarDate dateWithCurrentHour.
end_date := start_date dateByAddingHours:1.

new_appointment setStartDate:start_date.
new_appointment setEndDate:end_date.

new_appointment setSubject:'This is an appointment made with a script'.
new_appointment setDetails:'This is the details field'.

objectContext saveChanges.

document openObject:new_appointment.


This is how you do it from an AppleScript:
tell application "Daylite"
   eval"
   document := (NSApplication sharedApplication) firstDayliteDocument.
   objectContext := document objectContext.

	creation_context := objectContext creationContext.
	new_appointment := creation_context createObjectForEntityNamed:'Timeblock' addToObjectContext:true.

	start_date := NSCalendarDate dateWithCurrentHour.
	end_date := start_date dateByAddingHours:1.

	new_appointment setStartDate:start_date.
	new_appointment setEndDate:end_date.

	new_appointment setSubject:'This is an appointment made with a script'.
	new_appointment setDetails:'This is the details field'.

	objectContext saveChanges.

	document openObject:new_appointment.
   "
end tell



You'll notice that once you get to objectContext, the code is the same in the AppleScript version as in the pure FScript version.

For dates, you can use all the stuff available in NSCalendarDate. In our DevKit, we have a bunch of headers which describe the objectContext, creationContext, document (and superclasses).

I'm not sure exactly what you need to do, hopefully this gets you going in the right direction.
 
Posts: 893 | Location: Toronto | Registered: May 03, 2006Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
AJ,

Thanks, this is exactly what I was looking for. I also wanted to add Minutes to the appointment. I tried;

new_appointment setmeetingMinutes:'meeting stuff'.

and I received an error. Is there some trick to this too?

Thanks!
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
I believe message minutes should be set as a secondary object as outlined on page 17 and 18 of the Daylite Development book. But I'm having a hard time getting it to work.

I tried the following through AppleScript;

tell application "Daylite"
eval "
document := (NSApplication sharedApplication) firstDayliteDocument.
objectContext := document objectContext.

creation_context := objectContext creationContext.
new_appointment := creation_context createObjectForEntityNamed:'Timeblock' addToObjectContext:true.


new_appointment setSubject:'This is an appointment made with a script'.
new_appointment setDetails:'This is the details field'.
new_appointment setStatusCode:4.
new_appointment setTypeCode:6.



myminutes := creation_context createObjectForEntityNamed:'meetingMinutes' addToObjectContext:true.
myminutes setmeetingMinutes:'This are meeting minutes dude'.
myminutes setmetingMinutesLargeDataID:1.

new_appointment addObject:myminutes toRelationshipWithKey:'meetingMinutesLargeDataID'.

objectContext saveChanges.


document openObject:new_appointment.
"
end tell

and I get the following error;

FScript error: NSGenericException: Object for entity name: meetingMinutes not handled by GWCreationContext with command:
document := (NSApplication sharedApplication) firstDayliteDocument.
objectContext := document objectContext.

creation_context := objectContext creationContext.
new_appointment := creation_context createObjectForEntityNamed:'Timeblock' addToObjectContext:true.

Thanks for your help.
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
AJ
Marketcircle Team
Picture of AJ
Posted Hide Post
meeting minutes is a "to-one" relationship of kind LargeData.

Here is what you do once you have the appointment object.

meeting_minutes := new_appointment createAndSetMeetingMinutesIfNeeded.
meeting_minutes setPlainTextRepresentation:'This is the meeting minutes'.


That's all you need to do in this case.

Some points:
1) createObjectForEntityNamed: takes entity names only (Timeblock or Contact are examples of entity names)

2) You could have created the LargeData object yourself by doing the following:
my_meeting_minutes := creation_context createObjectForEntityNamed:'LargeData' addToObjectContext:false.

new_appointment addObject:my_meeting_minutes toRelationshipWithKey:'meetingMinutes'.

my_meeting_minutes setPlainTextRepresentation:'This is plain text'.

objectContext saveChanges.

In this case there is no need to LargeData to the objectContext because it is owned by the appointment. There is no harm if you add it however, we handle that case.

HTH.
 
Posts: 893 | Location: Toronto | Registered: May 03, 2006Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
AJ,

Thank you so much for your help. It works perfectly. I also understood what you said about creating the LargeData by myself.

Thanks for all of your help and support.
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
AJ,

I got stuck again. I am trying to have the meeting minutes use XML data. I don't need any fancy stuff, just the text of the xml file. What methods do you recommend me going about doing this?

Also, I tried to the entire code you provided above in Cocoa.

MCCreationContext *cc = [oc CreationContext];
MCPObject *new_appointment = [cc createObjectForEntityNamed:@"Timeblock" addToObjectContext:YES];

[new_appointment setValue:@"This is an appointment made with Cocoa." forKey:@"Subject"];
[new_appointment setValue:@"This is details field" forKey:@"Details"];
[new_appointment setValue:@"4" forKey:@"StatusCode"];
[new_appointment setValue:@"6" forKey:@"TypeCode"];


/* MCPObject *meeting_minutes = [cc createObjectForEntityNamed:@ createAndSetMeetingMinutesIfNeeded];
[meeting_minutes setPlainTextRepresentation:@"yo these are the minutes"];
*/

[oc saveChanges];


I commented out the meeting minutes because I wasn't sure about them.

But the MCCreationContext *cc = [oc CreationContext];
is giving me the error "Error:'oc' undeclared (first use in this function).

I tried to do id oc; but and it compiles with a warning message. When I put the plugin into Daylite and run it, it crashes Daylite.

Thanks for your help.
 
Posts: 20 | Location: San Diego | Registered: April 24, 2008Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

Marketcircle    Forums  Hop To Forum Categories  Extending Daylite  Hop To Forums  Scripting    New Appointment(timeblock)

© Copyright 2006 Marketcircle Inc. All rights reserved.