none
Please Help: Screen for One to One Relationship in HTML Client

    Question

  • Hi,

    May be I sound silly but how can I create a single screen for One to Zero or One relationship. I am getting an error of Primary Key is required for the child table if I try to create a new child. I tried by creating a property of Child type & then assigning it, but that doesn't work either.

    Kind Regards,

    Divyang Vyas


    Divyang Vyas


    • Edited by divyang_dv Friday, February 14, 2014 11:08 AM
    Friday, January 24, 2014 3:58 PM

Answers

  • Finally I figured out a work around, it works if the child table is created within "onsavechanges". Here is the code:
    myapp.AddEditWorker.AddBankDetails_execute = function (screen) {
        // Write code here.
        myapp.onsavechanges = function (e) {
            // Create Bank Details
            var bankDetails = new myapp.tblWorkerBankDetail();
            bankDetails.AccountNumber = "xxx";
            bankDetails.BankName = "xxxx"
            bankDetails.setTblWorker(screen.tblWorker);
        }
    };


    Divyang Vyas

    • Marked as answer by divyang_dv Friday, April 04, 2014 2:57 PM
    Friday, April 04, 2014 2:57 PM

All replies

  • Any one?

    Divyang Vyas

    Tuesday, January 28, 2014 11:02 AM
  • Hi Divyang

    Thanks for your feedback.

    According to your description above, you want to create a single screen for One to Zero or One relationship in LightSwitch HTML client, and you got the error message.

    For this issue, we could add data to tables that have a one-to-zero-or-one relationship in Visual Studio LightSwitch. Depending on whether the related record is mandatory (required) or not you have a couple different options when inserting data.

    Beth Massi show a couple different options for doing that in both the desktop and mobile clients.

    Here is the reference for you - Saving Data Across One-to-One Relationships

    Best regards

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 29, 2014 6:13 AM
    Moderator
  • Thank Angie for the response, yes that is exactly what I want & for that I've already followed the same article that you have posted but it is not working.

    I have two tables:

    tblWorkers (WorkerID, Surname, Forename)

    tblWorkerBankDetails(WorkerID, BankName, BankAccountNumber)

    I’ve created a screen “AddWorker”, Placed a new button to add Bank details & trying to create new bank details, here is the code:

    myapp.AddWorkerWithBankDetails.NewBankDetail_execute = function (screen) {
        // Create new bank details
        screen.tblWorker.tblWorkerBankDetail = new myapp.tblWorkerBankDetail();
    };

    As soon as I click the button, I get this error:


    Divyang Vyas

    Wednesday, January 29, 2014 8:23 AM
  • Can someone please let me know if I am setting the relationship incorrectly or there is an issue with code or there is a work around to get this done.

    Divyang Vyas


    • Edited by divyang_dv Friday, January 31, 2014 8:27 AM
    Friday, January 31, 2014 8:02 AM
  • Hi Divyang,

    The syntax for what you want to do is, I believe, as follows:

    myapp.AddWorkerWithBankDetails.NewBankDetail_execute=function(screen){

    // Create new bank details

    var wbDetail = new myapp.tblWorkerBankDetail();

    // to link an entity, use the set(entityName)(instanceOfEntity) syntax

    // this literally 'sets' the 'tblWorkerBankDetail' navigation property of screen.tblWorker'

    // to the instance of 'tblWorkerBankDetail' you just created in code

    screen.tblWorker.settblWorkerBankDetail(wbDetail);

    };

    Ah, it's the JavaScript way! (trying to get used to it myself!)

    Hope this helps you!


    Ian Mac

    Friday, January 31, 2014 3:18 PM
  • Thinking about it a bit, you could most likely just write:

    myapp.AddWorkerWithBankDetails.NewBankDetail_execute=function(screen){

    screen.tblWorker.settblWorkerBankDetail(new myapp.tblWorkerBankDetail());

    };


    Ian Mac

    Friday, January 31, 2014 3:20 PM
  • Thanks Ian,

    I've tried both ways but getting the same error. I know it is very simple but unable to understand why it is not working. I can upload the program & data both if you want. Please let me know.


    Divyang Vyas

    Saturday, February 01, 2014 8:08 AM
  • Hi Divyang,

    Just a thought; your primary key (or whatever field you are linking to which must have a unique index) in the child table must not be of the auto-increment type in the actual database.


    Ian Mac

    Sunday, February 02, 2014 11:45 AM
  • Hi Ian,

    No that's not the case. I've shared the program & the data backup both, here is the link, https://skydrive.live.com/redir?resid=FB0A0BB2D8AB713C%21122


    Divyang Vyas

    Monday, February 03, 2014 9:56 AM
  • Hi guys,

    Please help, I really need to get this sorted to move on.



    Divyang Vyas

    Wednesday, February 05, 2014 8:20 AM
  • Can I confirm there is an issue with One to One relationship using External Database?

    Divyang Vyas


    • Edited by divyang_dv Friday, February 14, 2014 10:48 AM
    Monday, February 10, 2014 9:35 AM
  • Any one???

    Divyang Vyas

    Monday, February 17, 2014 1:55 PM
  • Finally I figured out a work around, it works if the child table is created within "onsavechanges". Here is the code:
    myapp.AddEditWorker.AddBankDetails_execute = function (screen) {
        // Write code here.
        myapp.onsavechanges = function (e) {
            // Create Bank Details
            var bankDetails = new myapp.tblWorkerBankDetail();
            bankDetails.AccountNumber = "xxx";
            bankDetails.BankName = "xxxx"
            bankDetails.setTblWorker(screen.tblWorker);
        }
    };


    Divyang Vyas

    • Marked as answer by divyang_dv Friday, April 04, 2014 2:57 PM
    Friday, April 04, 2014 2:57 PM