locked
Is the table created function never executed in HTML Client? RRS feed

  • Question

  • The following debug output never appears and other code I tried has no effect, so please let me know, if there is no create-hook for HTML clients.

    1. I have a DB table called Measure

    2. In the entity designer I click on "Server"

    3. On top of the window I click on <> Write Code -> Measure_Created

    (Additonal question: should this not be called Measures_created? because all other functions end on an 's', like Measures_inserted)

    4. I put this code inside the generated function:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.LightSwitch;
    namespace LightSwitchApplication
    {
        public partial class Measure
        {
            partial void Measure_Created()
            {
                Console.WriteLine(
                  "Measure_Created() called??"
                );
            }
        }
    }

    Thank you for your help.

    Thursday, November 27, 2014 3:13 PM

Answers

  • I know about that javascript entry point. But I am not allowed to use it, because I need to create an artificial ID. This should not happen on client side, so it cannot be tampered with.

    You're correct entity_created is client side code for desktop client only and doesn't fire for HTML client.

    It would be nicer if the tooling didn't show any of those methods in a solution having no Desktop Client.

    You should use entity_Inserting of the server-side DataService code to set values on new entities.

    HTH,

    Josh

    • Marked as answer by Sp1key Monday, December 1, 2014 2:26 PM
    Monday, December 1, 2014 1:55 PM

All replies

  • the created event SERVER side, is not really aware which client (desktop or html) is creating the record.

    If you create the method stub via the designer, the naming will be always ok.


    paul van bladel ==independent enterprise application architect== http://blog.pragmaswitch.com

    Thursday, November 27, 2014 5:20 PM
  • (Additonal question: should this not be called Measures_created? because all other functions end on an 's', like Measures_inserted)


    The pluralization (usually adding an 's') to an entity is done to indicate the action is on the collection of the entity rather than just a single entity. In this case the action is on the single entity.

    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book

    http://LightSwitchHelpWebsite.com

    Thursday, November 27, 2014 8:50 PM
  • Thank you for answering. This clarified already a lot. This means my assumption must be wrong, that this hook function is always triggered, as soon a new entry is created in the DB for the measure table?

    Thursday, November 27, 2014 8:56 PM
  • There is a client side  _created entry point in javascript as well:

    http://msdn.microsoft.com/en-us/library/dn720458.aspx#entry

    In the entity designer, select the HTML perspective then Write Code.

    HTH,

    Josh

    Saturday, November 29, 2014 1:44 PM
  • Hello, Josh, thank you for your answer. I know about that javascript entry point. But I am not allowed to use it, because I need to create an artificial ID. This should not happen on client side, so it cannot be tampered with.
    Monday, December 1, 2014 8:28 AM
  • The following debug output never appears and other code I tried has no effect, so please let me know, if there is no create-hook for HTML clients.

    1. I have a DB table called Measure

    2. In the entity designer I click on "Server"

    3. On top of the window I click on <> Write Code -> Measure_Created

    (Additonal question: should this not be called Measures_created? because all other functions end on an 's', like Measures_inserted)

    4. I put this code inside the generated function:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.LightSwitch;
    namespace LightSwitchApplication
    {
        public partial class Measure
        {
            partial void Measure_Created()
            {
                Console.WriteLine(
                  "Measure_Created() called??"
                );
            }
        }
    }

    Thank you for your help.

    I wonder, did anyone already succesfully use that server side hook during DB entry creation? in a HTML client? I still think I am using it for the wrong purpose or it does not work at all.
    Monday, December 1, 2014 8:32 AM
  • You may want to use ServerApplicationContext to create an entity triggered from the HTML Client and still return an ID or other value created on the server.

    // Save the record so we get a Id to use in the PayPal request
    serverContext.DataWorkspace.ApplicationData.SaveChanges();
    // set PayPalPurchaseTransactionId
    PayPalPurchaseTransactionId = objPayPalTransaction.Id;
    

    See:

    Integrating PayPal With Visual Studio LightSwitch


    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book

    http://LightSwitchHelpWebsite.com

    Monday, December 1, 2014 1:24 PM
  • I know about that javascript entry point. But I am not allowed to use it, because I need to create an artificial ID. This should not happen on client side, so it cannot be tampered with.

    You're correct entity_created is client side code for desktop client only and doesn't fire for HTML client.

    It would be nicer if the tooling didn't show any of those methods in a solution having no Desktop Client.

    You should use entity_Inserting of the server-side DataService code to set values on new entities.

    HTH,

    Josh

    • Marked as answer by Sp1key Monday, December 1, 2014 2:26 PM
    Monday, December 1, 2014 1:55 PM
  • Thank you, for your answer. Yes, this is a similar situation to mine. But the major question is where do you place this code, so it is executed when the user is done with his input?
    Monday, December 1, 2014 2:26 PM
  • In the Entity Designer - Server perspective choose Write Code | Measures_Inserting

    HTH,

    Josh

    Monday, December 1, 2014 2:28 PM
  • Thank you for that confirmation. I use the _Insterted(entity) hook now, for saving a modified ID. Inside the _ApplicationDataService.lsml.cs file.

    It is triggered on a table insert.

    Thank you all, for your help.

    Monday, December 1, 2014 2:30 PM