Prepare appointment and let user save of cancel it

I use

      soApnt := objSo.Database.CreateAppointment;
      soApnt.SetDefaults;

      set some more properties
      soApnt.Save;
      objSo.SetSoProtocol('superoffice:appointment.main.?contact_id=3$appointment_id='+IntToStr(soApnt.Identity)';

This works but the appointment is always made, the user should be able to cancel it.

Can anyone help me on this?

Thanks in advance

RE: Prepare appointment and let user save of cancel it

Hi Hans,

Assuming you are running from an external process, the following script example works for me in version 8 SR4.

SetSoProtocol is an immediate call.
PostSoProtocol is a call defered to idle time.

Use SetSoProtocol first, with 0 identity.
This will invoke the current appointment dialog and set defaults.
Then add your changes and exit - do not save!

Conrad.

-----------------------------------------------------------------------------------

Set app = CreateObject( "SuperOffice.Application" )
If Not app Is Nothing Then
    On Error Resume Next
    Err.Clear

    app.SetSoProtocol( "superoffice:appointment.main?appointment_id=0" )
    If Err.Number = 0 Then
        Set appnt = app.CurrentAppointment

        Err.Clear
        appnt.Description = "­Hello world...."
        appnt.Location = "The cabin"
        appnt.DoBy = "26.02.2017 10:30"
        appnt.EndDate = "26.02.2017 15:00"
        ' .........
         
    Else
        app.SOMessageBox "Unable to set soprotocol!", "Script encountered an error", 2
    End If
    On Error Goto 0
Else
    WScr­ipt.Echo "Error getting application object"
End If

Af: Conrad Weyns 4. feb 2017

RE: Prepare appointment and let user save of cancel it

Gewelding Conrad,

Werkt fantastisch!

Hartelijk dank

Af: Hans van Mackelenbergh 5. feb 2017

RE: Prepare appointment and let user save of cancel it

Hello,

New problem, how to switch between appointment and todo.

I use

SetDefaults with type_ = enAppointAppoint

or

SetDeaultsTodo with type_ = enAppointTodo

I thought this worked but it does not.

Anu suggestions here

thanks in advance

Af: Hans van Mackelenbergh 10. feb 2017

RE: Prepare appointment and let user save of cancel it

Good evening - Goeie avond..

First a disclamer. To me this is a gray zone that I have never quite understood. Also, I reckon it is implemented as somewhat of a hack... Often the case when adding features without being able to change the database schema. Presumably this will all change now with CDD.

appnt.SetDefaults
appnt.SetDefaultsCall
appnt.SetDefaultsToDo

These 3 should help you get going. Observe, none of these take any parameters.
A Task is first and foremost identified by the fact that it has no start time.
SetDefaultsToDo will help you with this, corrected for TimeZone.
The appnt Type will be 2 for kAppointmentType_HasNoStartTime.
The appnt Status will be 1 for kNotStarted
The appnt Task will be some default Follow-up type, a list item whose Type=Task. But this is where it starts breaking down because it might as well have been set to a any follow-up type by a default peference. The latter will cause the large icon to change adding to the confusion.

Bottom line, my advice is:
Use SetDefaultsToDo early in your sequence, then change the Task to whatever list item you want. If this item, a Follow-up type, is defined with Type=Task, then you'll get a Task icon, else not.

Hope this helped somewhat :-)
/conrad



Af: Conrad Weyns 10. feb 2017

RE: Prepare appointment and let user save of cancel it

Hello Conrad,

Thanks again, I've tested a lot and it seems that the the appointment / Todo (I only need these 2) is always saved correct.

The only problem is that the user sees the ToDo text onscreen which is confusing. Other things like time, description are shown correctly.

I was looking for a way to refresh but database.refresh takes a very long time (and probably doesn't solve the issue)

My code looks like this

      objSo.SetSoProtocol('superoffice:appointment.main?appointment_id=0');
      soApnt = objSo.CurrentAppointment;
      if AAction = _actAppointment then
      begin
        soApnt.SetDefaults;
        soApnt.type_ = enAppointAppoint;
      end
      else
      begin
        soApnt.SetDefaultsToDo;
        soApnt.type_ = enAppointTodo;  
      end;
      soApnt.Contact = objSo.CurrentContact;
      soApnt.DoBy = (Trunc(Now * (24*4)) + 1) / (24*4);
      soApnt.Duration = 60;
      soApnt.Description := 'do something';

Af: Hans van Mackelenbergh 14. feb 2017

RE: Prepare appointment and let user save of cancel it

Not sure what you mean by "sees the ToDo text onscreen.."


A few comments:
1. Do not set theType to enAppointmentToDo. SetDefaultsToDo will have set the correct Type and Status for you, 2 and 1 respectively.
In actual fact, the pubished EnAppointmentType enumerator is in reality  EAppointmentRecordType used in a completely different universe.
For some reasons, unknown to me, we have never corrected this in the COM API.
The relevant enumerator, never published is (copied form the c++ code):

    kAppointmentType_Undefined = 0
    , kAppointmentType_HasStartTime = 1            // appointment that has a starttime, meaning it has a timespan and not only a deadline
    , kAppointmentType_HasNoStartTime            // appointment has only a deadline
    , kAppointmentType_Note
    , kAppointmentType_DocumentIn
    , kAppointmentType_DocumentReport
    , kAppointmentType_BookingHasStartTime
    , kAppointmentType_BookingHasNoStartTime
    , kAppointmentType_DocumentMergeDraft
    , kAppointmentType_DocumentMergeFinal

We get these two confused many times over...

2. I don't have access to Trunc, so I couldn't test this line, but make sure that doBy has a 00:00:00hrs time. If not, the Type will automatically change to 1, kAppointmentType_HasStartTime, and then it stops being a "Todo".
Also, if TimeZones is enabled, DoBy takes a base time, not a display time!

3. As long as you are using the SOAppication object, you need never force a refresh. Live-update takes care of this.

/Conrad

 

Now, a completely different thing. While looking into this case, I discovered a nasty issue. I use VBSEdit and/or PrimalScript from Sapien. When I debug the script and try to look into the appnt instance, everything was cleared! It turned out we have a age old bug in our Models...
When opening an object in a script debugger, it will normally use reflection to update all or some of its its properties. One of these methods is IsAvailable(). I am sorry to say that this results in fetching the record. But when the identity = 0, this involves a clear all varialbes!
Bottom line, either do not use a debugger or look into model objects as early as possible, before the call to SetDefaultsTo.
We are looking into fixing this for the next 8.1 release.

 

Af: Conrad Weyns 14. feb 2017

RE: Prepare appointment and let user save of cancel it

Thanks again Conrad,

1st af all, I removed the lines saApnt.type_ =...

The didn't change the result.

You also mentioned that setting saApnt.DoBy would change a Todo into an appointment (or something like it) but I get an Todo, no matter which SetDefault(ToDo) I use.

The third thing you mentioned was about the debug environment, we use Delphi / Pascal to I reccon this is not a problem for us.

Any suggestions?

Af: Hans van Mackelenbergh 26. feb 2017

RE: Prepare appointment and let user save of cancel it

Hi Hans,

I amgoing to need more info I think.
I am not entirely sure what the problem is.

You mentioned:

The only problem is that the user sees the ToDo text onscreen which is confusing. Other things like time, description are shown correctly.

I was looking for a way to refresh but database.refresh takes a very long time (and probably doesn't solve the issue)

Can you elaborate?

Conrad

Af: Conrad Weyns 27. feb 2017

RE: Prepare appointment and let user save of cancel it

Hi Conrad,

Today al systems reset and testing again, it looks like it works properly

We wil try this in production see if it stays ok.

Thanks so far, I'm sorry not to have a clear answer to why this is...

Regards

Herman









Af: Hans van Mackelenbergh 5. mar 2017