This is a migrated thread and some comments may be shown as answers.

Obtaining the Appointment ID after appointment creation

7 Answers 194 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
JK
Top achievements
Rank 1
JK asked on 25 Oct 2007, 03:42 PM
Hi,

very sorry that I am hammering the forum again.  But I have hit a brick wall with regard how to obtain the appointment ID after creation.

I have got an appointment which is programatically created within the "FormCreating" event (user double clicks the rest of the process is performed by code), this works well. 

However I need to obtain the appointment ID to pass this value to another datasource.  I have had no sucess with obaining the value,  my thoughts were that to obtain the appointment ID this would be in the "formCreated" event.  But when I debug the page, the event never gets fired even though the "formcreating" event does.

Am I missing something? How do I obtain the AppointmentID imeditaly after creation?

Thanks,

JK

P.S. Is there any detailed docs on Scheduler (only got help system, not much to go on) so I can review that before posting?

7 Answers, 1 is accepted

Sort by
0
Tim Barton
Top achievements
Rank 2
answered on 26 Oct 2007, 09:43 PM

Hi JK,

When I create an event, I create the ID to put in the database.  To get the ID after created you can try e.Appointment.ID or e.ModifiedAppointment.ID if you changed the ID for some reason.

Tim 

0
JK
Top achievements
Rank 1
answered on 28 Oct 2007, 03:09 PM
Thanks for your input Tim.
Unfortunatley, the e.appointmentID does not exist during the formcreating stage as at that point the appointment does not exist ( my code performs an insert appointment command).

The e.modifedappointmentID workes if your editing a appointment which in this case I am not doing.

Unless there is another application to e.modifedappointment I am missing?

Thanks,

JK
0
Tim Barton
Top achievements
Rank 2
answered on 28 Oct 2007, 05:14 PM
Hi JK,

Doing the creating phase you have to create the ID.  Telerik uses the Guid.NewGuid().ToString() to create the ID in there examples and I use the same method.   How do you created the ID that is put in your datasource when the event is created?

Thanks,
Tim
0
EmpowerIT
Top achievements
Rank 2
answered on 28 Oct 2007, 11:16 PM
Are you sure you are not setting e.Cancel to true in the formCreating event?
If you set this to true, i believe the formCreated event will not fire (because it thinks you are cancelling out of creating a form).

You will need to keep track of the last appointment you created so that you can retrieve it and check its ID property.

0
JK
Top achievements
Rank 1
answered on 29 Oct 2007, 09:46 AM
Thanks for the response guys.

I think i may have worked it out.  But to answer both your questions.

Tim - I have set the SQL datasource to a identity seed datatype so no intervention is performed on the schedulers part it just gets assigned the next number and since this is on the SQL side (i.e number assignment occurs after/during record creation, I wanted to know how/if the scheduler retrieves this information.  I suspect this is done on the formcreated part which is where I was placing the code (which would not fire)

Link64 - Feel very embarrassed now.  Your bang on the money,  The last line in the formcreating event is to cancel the creation of the appointment as the rest of my code creates the appointment (it just needs the user to double click to get the appointment underway).  Becuase of this the formcreated event never fires!

Now I have an understanding of what is going on I suspect I would be able to obtain the ID by performing a rebind (dirty read) to the scheduler as no new call to the DB would be done the last appointment would be the ID number I would require.  So putting the code in the "appointmentcreating" event would recurse through each appointment until the last one (newly created appointment) and then I can assign that number to the other datasource.

Thanks for both your help.  Must say this is probably the best forum I have ever used everyone is very helpful!

JK
0
T. Tsonev
Telerik team
answered on 29 Oct 2007, 09:53 AM
Hello Jon,

This is the same answer as in your support ticket, I am duplicating it here for the forum users to see.

You can use the Inserted event of the SqlDataSource to determine the ID of the newly created record.
First, you need to modify the insert query:

InsertCommand="INSERT INTO ServiceHistory(...) VALUES (...); SELECT @NewID = @@IDENTITY" 

You can change "@@IDENTITY" to "SCOPE_IDENTITY()", if you are using SQL Server.

Then, add the following parameter to the InsertParameters:

<asp:Parameter Direction=Output Name="NewID" Type="Int64" /> 

We can now handle the Inserted event to get the ID of the inserted appointment:

protected void AppointmentsDataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)  
{  
    Int64 newId = (Int64) e.Command.Parameters["@NewID"].Value;  
}  


Greetings,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JK
Top achievements
Rank 1
answered on 29 Oct 2007, 09:59 AM
it is amazing how I always overcomplicate things!

Thank you so much guys for all your help, at the very least it is expanding my knowledge very quickly :o)

JK
Tags
Scheduler
Asked by
JK
Top achievements
Rank 1
Answers by
Tim Barton
Top achievements
Rank 2
JK
Top achievements
Rank 1
EmpowerIT
Top achievements
Rank 2
T. Tsonev
Telerik team
Share this question
or