Check before change RRS feed

  • Question

  • Hi, I have a lightswitch 2015 application with a screen which displays a Department search dropdown list.  When the user selects the correct department, 2 related tables are shown. There is also a “InUse” dropdown displayed for the department with Yes\No choices.

    The user can set the “InUse” dropdown, however I need a check to ensure they cannot set the “InUse” to No if the related tables have data.

    How do I create a check or warning to prevent the “InUse” dropdown being set to No, if records exist in the related tables for that department.


    Thursday, August 27, 2015 8:36 AM

All replies

  • I would use a postrender method on your InUse control and have it bind to the value.  If the user selects "no", then you can check the two tables to see if they contain data and alert the user that "no" is not an option. 

    something like this code (NOT tested):

    contentItem.dataBind("value",function( inusevalue ){

    if(inusevalue == "no"){

    if(contentItem.screen.table1.length > 0 || contentItem.screen.table2.length > 0){

    msls.showMessageBox("You can't pick no");




     I don't know of a way to "remove" the "no" from the dropdown.

    Friday, August 28, 2015 6:00 AM
  • Hi jez123456,

    Could you please describe the detailed relationship between the Department table, the InUser and the related table with department?
    I assume I have a Employee table and a Department table. There has a Employee(Many)-to-Department(One) relationship. And the InUser is a choice list field in the Department table. Do you mean if there has employees under the department, I can't select "No" for the InUser field in Department table?
    Please write validation code in the InUser_Validate method as following code.

    partial void InUser_Validate(EntityValidationResultsBuilder results)
         // results.AddPropertyError("<Error-Message>");
         if (this.Employees.Count() != 0 && this.InUser == "No")
            results.AddPropertyError("There has employees under this department, please don't set it to NO!");

    If misunderstanding, please feel free to let me know.

    Best Regards,
    Friday, August 28, 2015 9:41 AM
  • Hi, thanks for the reply.

    The department table has a one to many relationship with the media table, thus one department can have zero or many media records.

    You are correct that the InUse is a Yes\No choice field within the departments table.

    The InUse flag is used to show if the department is live or closed. Yes = Live, No = Closed.

    By default when a new department record is created the InUse is set to Yes.

    Before a department can be closed (ie InUse set to No), there must be no related Media records.

    On the screen I need to ensure that the user cannot set InUse to No if there are any related media records.

    I hope this explains things a little better.
    Tuesday, September 1, 2015 8:35 AM
  • Hi jez123456,

    My assumptions is the same with your description. Please add your validation message in the InUser_Validate() method. When you click the save button, it will display the validation message that you added which will prompt customer can't set the InUser as "No".
    Best Regards,

    Tuesday, September 1, 2015 9:43 AM
  • What client are you using, HTML or SL? 
    Tuesday, September 1, 2015 12:21 PM