locked
HTML Client - Set Value for Property linked to a child table RRS feed

  • General discussion

  • Hi All,

    I have two tables of interest: Jobs and JobStatusSet. There is a one to many relationship between the tables - one job status, many jobs. When a job is created I want to set the status to a value defined in the JobStatusSet table (StatusName). I'm not sure how to set this via JS. I have a Job Add/Edit screen with the following code which doesn't work:

    myapp.AddEditJob.beforeApplyChanges = function (screen) {
    
        if (screen.Job.Id == undefined)
        {
            screen.Job.JobStatus = screen.JobStatusSet
        }
        
    };

    But I'm not sure how to finish the line off to correctly identify the value in the JobStatusSet table.

    Thanks in advance for pointing me in the right direction :)

    Cheers,

    Adam

    Tuesday, January 12, 2016 11:59 AM

All replies

  • This may help:

    Dynamically Creating Records In The LightSwitch HTML Client

    myapp.AddEditOrder.DynamicAddOrderDetail_execute = function (screen) {
        // Make a new OrderDetail
        var newOrderDetail = new myapp.OrderDetail();
        // Set the Order property
        // Whenever you have associated Entities, there will 
        // be a .set[Entity Name] method available
        newOrderDetail.setOrder(screen.Order);
        // Set the Quantity
        newOrderDetail.OrderQuantity = 0;
        // Try to find a Product
        var Products = screen.details.dataWorkspace.ApplicationData.Products
            .load().then(function (results) {
                // Try to get the first Product
                var FirstProduct = results.results[0];
                // Did we find a first Product?
                if (FirstProduct != undefined && FirstProduct != null) {
                    // Set the first Product as the Product for the OrderDetail
                    newOrderDetail.setProduct(FirstProduct);
                }
            });
    }


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

    http://LightSwitchHelpWebsite.com

    Tuesday, January 12, 2016 1:43 PM
  • There are many ways, another way is you can set JobStatus in Job screen's created event:

    myapp.AddEditJobs.created = function (screen) {
        //Set job status for new Jobs
        if (screen.Jobs.Id == undefined) {
            myapp.activeDataWorkspace.ApplicationData.JobStatusSets_SingleOrDefault(1).execute()
            .then(function (result) {
                var status = result.results[0];
                if (status != undefined) {                
                    screen.Jobs.setJobStatusSet(status);
                }
            });
        }
    };

    Here I've used ID to get the job status (myapp.activeDataWorkspace.ApplicationData.JobStatusSets_SingleOrDefault(1).execute()) but you can use StatusName by creating a server-side query and passing SatusName.


    Divyang Vyas


    • Edited by divyang_dv Tuesday, January 12, 2016 3:20 PM
    Tuesday, January 12, 2016 3:19 PM
  • Thanks Michael this worked a treat. :)
    Friday, January 15, 2016 9:52 AM
  • Thanks Divyang. This approach also worked for me :)
    Friday, January 15, 2016 9:53 AM