Lightswitch HTML Client - beforeApplyChanges only fires once

Hi,
I have a standard Add/Edit screen created by Visual Studio with the standard save button in the top right-hand corner. In my beforeApplyChanges function I have the following code:
if (!screen.OrderAllocation.OfflineAdType) {
screen.findContentItem("OfflineAdType").validationResults = [
new msls.ValidationResult(
screen.OrderAllocation.details.properties.OfflineAdTypes,
"This is a required field")];
return false;
This fires correctly if someone tries to save the object without an OfflineAdType. However, if they then correct the error by editing it within the screen, and then click on the standard save button - a message box pops up saying there's validation errors
on the page. BeforeApplyChanges isn't called.
How do I clear these validation errors beforehand?

You need to clear the validation results.  You can also add a change listener to update any time the value changes.  See the answer to this post. 
https://social.msdn.microsoft.com/Forums/en-US/08af462d-a094-44b2-bf3c-a3cd5f7a40a9/hmtl-client-screen-validation?forum=lightswitch

Similar Messages

  • Extending Screens for Multi-Select in the LightSwitch HTML Client

    Hi i
    read Mike Droney's article of 
    Extending Screens for Multi-Select in the LightSwitch HTML Client
    But i just want to understand the code, so what is the ‘__isSelected’ property? from where does it come?
    why does the contentItem.value.details have an ‘__isSelected’ property?
    is the value of the contentItem not the screen?
    and also how can i implement the ‘Can Execute Code’ only if one or more check boxes are checked?
    Thanks  

    But i just want to understand the code, so what is the ‘__isSelected’ property? from where does it come?
    why does the contentItem.value.details have an ‘__isSelected’ property?
    is the value of the contentItem not the screen?
    and also how can i implement the ‘Can Execute Code’ only if one or more check boxes are checked?
    The '__isSelected' property is a private member of the class msls.ContentItem related to the backing data for the selected item.  That is to say, it would be a private member if JavaScript actually had encapsulation and information hiding like a typical
    object-oriented language. I like to reference David Herman's description from his book
    Effective JavaScript:
    Often, JavaScript programmers resort to coding conventions rather than any absolute enforcement mechanism for private properties. For example, some programmers use naming conventions such as prefixing or suffixing private property names with an underscore
    character (_). This does nothing to enforce information hiding, but it suggests to well-behaved users of an object that they should not inspect or modify the property so that the object can remain free to change its implementation.
    ...which means that it's generally not recommended to directly get or set backing data properties like __isSelected, instead working with the public property 'selectedItem', although it may work fine in certain cases like this one.
    To make _canExecute fire only when an item in the list is selected to enable a button method, try:
    return (screen.Contacts.selectedItem !== null);

  • Lightswitch HTML Client - Detail picker for each related List Item

    I have a doubt in Lightswitch Html Client application.
    Scenario:
    Suppose i have two tables  "Property" and "PropertyVaues".
    A Property can have many PropertyValues is the relationship between them.
    I want to show the data on screen like below:
    Property List:
    XYZ            [___10____(+)]
    MNO          [___abc____(+)]
    PQR           [___30.5___(+)]
    Xyz  is the list item
    assume [___10____(+)]  is the detail picker of
    PropertyValues which allow to select one value related to
    XYZ Property item, and same for other list items.
    Only Related "PropertyValues" for each list item must be available in the detail picker.
    Please help me out if any one has the solution to solve it.
    Or you can give me any other way to accomplish the above scenario.
    Thanks

    Hello Josh,
    I am implementing it on AddEdit screen.
                      (1)                                              
    (2)                           
    Screen description:
    [Note: Some Images are in my next post]
    1. Image(1) shows the list of properties (GSM, Mill Name, CMS). These Properties have its respective property values in drop down.
    2. When i select any value from the dropdown list (eg. 10 from GSM). the value is assigned to all other drop down.
    [shown in image(3) next post]
    (4) Again when suppose i select value for "Mill Name" Property as "Abc", it is assigned to all other drop down.
    [shown in image(4) next post]
    I want that a property value must be assigned to its respective Property only.
    Please help me on this. Or suggest me another way out to accomplish such scenario.
    Thanks
    Ravi Patel

  • SSRS reports from Lightswitch Html Client

    I have created a Lightswitch desktop application that list the available reports that are stored in a table and also provides a button that when clicked launches the web browser to the URL for the report on the SQL server. My problem is now I'm trying to
    create the HTML client for the application and have no experience with Java Script. Does anyone know how to accomplish the something that I did on the desktop application on the HTML client?
    Below is the code that I used to open the URL in the browser in the desktop application.
    Imports Microsoft.LightSwitch.Threading
    Imports System.Runtime.InteropServices.Automation
    Namespace LightSwitchApplication
    Public Class ListReports
    Private Sub RunReport_Execute()
    ' Write your code here.
    Dim uri As New Uri(ReportsSet.SelectedItem.ReportAddress) 'website stored in the ReportsSet.ReportAddress field
    If (AutomationFactory.IsAvailable) Then
    Dim shell = AutomationFactory.CreateObject("Shell.Application")
    shell.ShellExecute(uri.ToString)
    ElseIf (Not System.Windows.Application.Current.IsRunningOutOfBrowser) Then
    System.Windows.Browser.HtmlPage.Window.Navigate(uri, "_blank")
    End If
    End Sub
    End Class
    End Namespace

    This may help:
    Creating Reports in LightSwitch HTML Client
    // Show Loading message
    var LoadingDiv = $("<div></div>");
    var Loading = $("<h1>&nbsp;&nbsp;&nbsp;&nbsp;Loading Report...</h1>");
    Loading.appendTo(LoadingDiv);
    LoadingDiv.appendTo($(element));
    // Get Report
    var HTMLContent = $("<div></div>").html(
    "<object width='650px' height='650px' data='../reports/ReportViewer.aspx?SurveyId="
    + contentItem.screen.SurveyId + "'/>"
    // Make report appear on top of the Loading message
    HTMLContent.css({
    "margin-top": "-50px"
    HTMLContent.appendTo($(element));
    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book
    http://LightSwitchHelpWebsite.com

  • Making the ChangeListener only fire once on a JTabbedPane

    Hi guys, I'm having a problem with the amount of times that a ChangeListener for a JTabbedPane is called. If the user clicks on a certain tab, a JOptionPane is displayed with a message. However, I can't figure out a easy work around to make it so the listener only executes the code within it only once - I don't want the JOptionPane to come up twice. I tried doing a not-so-great boolean method:
    private void setPass(){
         if (pass)
              pass = false;
         else
              pass = true;
    }and calling it from within the listener, but I'm having trouble with it. Anyone know how to make it so the lister only fires once, or at least only displays the dialog once? I tried searching the forums using keywords such as "JTabbedPane ChangeListener pass once twice... etc" but it didn't bring anything relevant up. Thanks!

    are you sure you're using a changeListener?
    works OK in this
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    class Testing
      public void buildGUI()
        final JTabbedPane tp = new JTabbedPane();
        for(int x = 0; x < 5; x++) tp.addTab(""+(char)(x+65),new JPanel());
        JFrame f = new JFrame();
        f.getContentPane().add(tp);
        f.setSize(300,200);
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        tp.addChangeListener(new ChangeListener(){
          public void stateChanged(ChangeEvent ce){
            JOptionPane.showMessageDialog(null,tp.getTitleAt(tp.getSelectedIndex()));
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }post a sample program so we can see what you're doing
    (by compiling/running the sample program)

  • Runtime Error in VS2012 (Update4) LightSwitch HTML Client

    I have a desktop (Silverlight) application, I upgraded the project to add the HTML Client. Now when I run the HTML Client, it shows this message box on the browser:
    "The application could not be loaded. Please try refreshing the page. Failed to load model: failed to parse the model JSON string. Failure reason: syntax error."
    I started my desktop application in VS2012 Update 2, and now it is in the Update 4. The interesting thing is that when I make new Project and then add HTML Client, I will not receive this error and it works fine.
    It shows this error only on that specific project (Which I started on VS2012 Update2, later Update3 and now Update4) and that project is very big (more than 100 tables and screens), therefore I can not make that from scratch again.
    I have to add HTML Client to my project. I really appreciate if someone can help me.

    "The application could not be loaded. Please try refreshing the page. Failed to load model: failed to parse the model JSON string. Failure reason: syntax error."
    Hi Keysen,
    First you need install Microsoft.LightSwitch.Client.JavaScript.Runtime 2.5.2. This update can be downloaded from the NuGet Gallery, see:
    http://www.nuget.org/packages/Microsoft.LightSwitch.Client.JavaScript.Runtime/
    Because this issue is project specific, you can also turn the build output, in the
    Options window, find Projects and Solutions >> 
    Build and Run. Find Diagnostic in the drop-down for MSBuild project build output verbosity. It will give detailed information why this happens.
    Please let me know if there is anything that I can do to help.
    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.

  • Terminatio​nStateChan​ged Callback Only Fires Once

    Hi,
    I have a TestStand OI that has a callback VI registered for TerminationStateChanged event.  Essentially, I'd like to show an image anytime the user hits the terminate button to shutdown the sequence.  It seems that the first time I run the sequence, everything works fine.  I click terminate during a sequence, TS fires my callback VI -- I trap newTermState 2 (Terminating) and am able to display the image without a problem.  However, it seems that when the user runs the sequence again, the callback VI never fires on a termination.  If I click terminate this time, TS must have received the command because the sequence does in fact terminate... but the callback VI is never called.
    Am I missing something?   Does this callback only work once? 
    Thanks!

    Hi jplotzke,
    I just wanted to clarify from my earlier post that although using the Execution.GetTerminationMonitorStatus function will detect a termination state change in your sequence, you may simply be able to use the Execution.GetStates method instead as it does not require any initialization. Note however that we can use this function without any penalty in this case since the sequence runs inside of the TestStand engine and so there is no performance hit when calling this method. On the other hand, if you were to call this method from a UI, you will be crossing a client/server boundary, which in turn will result in some performance penalty. So if you wanted to make changes to the UI instead of adding extra steps in your sequence, I recommend using the ExecutionViewMgr methods to track the Termination State as it will have the smallest impact on performance.
    I hope this clarifies some questions.
    S_Hong
    National Instruments
    Applications Engineer

  • How to access the C# file in server from Lightswitch HTML Client

    Hi,
    In that LightSwitch HTML Application i have some c# file in the server project.How can i access those C# file in the screens (HTML Client project )
    thanks,
    goblalakrishnan s
    gobalakrishnan S

    Hi,
    with implementing Generic File Handlers (.ashx)
    See follow link:
    http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/174/Full-Control-LightSwitch-ServerApplicationContext-And-Generic-File-Handlers-And-Ajax-Calls.aspx
    regards
    j.nord

  • 'Days Elapsed' computed field in lightswitch HTML client

    I am developing a simple lightswitch HTML application to keep track of research experiments. I have a table called 'Experiments' and one of the fields is 'ExperimentDate'. I want to display the number of days that have passed since the date of experiment.
    Is there any way to do this?

    Use a custom control to display 'ExperimentDate' and display the calculation. Use in-built JavaScript datetime functions or add a JavaScript library such as moment.js. Similar to this MSDN article sections:
    Format a Date
    Moment.js
    You can see the use in this
    stackoverflow post.
    var date1 = new Date("02/Feb/2015 00:00:00"),
    date2 = new Date("25/Feb/2015 10:09:00"),
    diff = date2.getTime() - date1.getTime(),
    days = Math.floor(diff / (1000 * 60 * 60 * 24));
    Cheers
    Dave
    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

  • LightSwitch HTML Client pubished on azure get an 400.0 bad request error

    Well, I have this problem: "Request failed with status code '400' and the status text 'Bad Request'." when I run my LightSwitch HTMLClient application that are published in Azure Web Applications.
    I already look everywhere for 3 days and still could not find the answer to this problem.
    I hope someone in this forum can help me.
    Thanks.

    Hi, thank you for respond.
    let's see, the fiddler throws these:
    NOTICE: Don't follow the links, they are dummies
    GET http://myapp.azurewebsites.net/ApplicationData.svc/$metadata
    400 Bad Request (text/html)
    The Request
    GET /ApplicationData.svc/$metadata HTTP/1.1
    MaxDataServiceVersion: 3.0
    Accept: application/xml
    Referer: http://myapp.azurewebsites.net/HTMLClient/default.htm
    Accept-Language: es-MX,es;q=0.8,en-US;q=0.5,en;q=0.3
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
    Connection: Keep-Alive
    Host: myapp.azurewebsites.net
    Cookie: ARRAffinity=354b4b5b87b2f1e4e8b6c19a5566c6e055bf3e4047b54b4d2ea846ba1b33d561; msls-client-parameters=preferredLanguage=es-MX; ASP.NET_SessionId=bkf52whz0rkufhcxmqrfuirm
    The Response
    HTTP/1.1 400 Bad Request
    Cache-Control: private
    Content-Type: text/html
    Server: Microsoft-IIS/8.0
    X-AspNet-Version: 4.0.30319
    X-Content-Type-Options: nosniff
    X-Powered-By: ASP.NET
    Date: Wed, 01 Apr 2015 04:23:39 GMT
    Content-Length: 1647
    Connection: Keep-Alive
    The azure logs, the lightswitch diagnostic and the debugger not show any difference from these.

  • CEV-Rules only fire once

    Our Change Events Rules fire only once effectively. If we save one record per transaction everything works fine. The CEV-rules are fired, and executed. If, however, we enter 2 records (or more...) per transaction, the CEV-rule is fired twice, but thice for the same record.
    I can see in the trace-files, it does pass the NEED-BR procedure, but when it fires the second time, the same record-data is used as from the first record, resulting in the fact, that one record was not processed.
    We're running forms 6i(6.0.8.24.1) and Headstart patchlevel= PATCH6523

    are you sure you're using a changeListener?
    works OK in this
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    class Testing
      public void buildGUI()
        final JTabbedPane tp = new JTabbedPane();
        for(int x = 0; x < 5; x++) tp.addTab(""+(char)(x+65),new JPanel());
        JFrame f = new JFrame();
        f.getContentPane().add(tp);
        f.setSize(300,200);
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        tp.addChangeListener(new ChangeListener(){
          public void stateChanged(ChangeEvent ce){
            JOptionPane.showMessageDialog(null,tp.getTitleAt(tp.getSelectedIndex()));
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }post a sample program so we can see what you're doing
    (by compiling/running the sample program)

  • How to show/hide build in search box in javascript for LightSwitch html clients?

    Hi
    For each collection on content item, there is built-in showSearch button we can add, once the user clicks on the search, a pre-built-in-search-box shows up above the collection so user can search items in the list. How can I show/hide the pre-built-in-search-box
    in javascript?
    Any help will be appreciated
    The built-in showSearch on content item
    The user clicks the search button, and the pre-built-in-search-box shows up to allow user to enter search terms
    jl

    Hi Joe,
    Welcome to Lightswitch forum.
    If you want to show/hide showSearch button, you can execute this line to show the button,
    this.FindControl("showSearch").IsVisible = true;
    Or execute the line below:
    this.FindControl("showSearch").IsVisible = false;
    Please let me know if there is anything that I can do to help.
    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.

  • Lightswitch HTML Client 2013 - Navigation property load works Intermittently on phone, but works all the time in desktop browsers

    Hi,
      I have this code which is adding a record and re-loading a navigation property "ldDailyLogDetails_FK".
    afterClosed:
    function   (viewScreen, navigationAction) {
                    if
      (navigationAction === msls.NavigateBackAction.commit) {
                          screen.ldDailyLogDetails_FK.load();
         It successfully adds a record and then redisplays this new record on all browsers, but on my phone it adds the record ok, but sometimes, it dosnt seem to refresh (or load) the page with the new record.  
          I also wonder if there is any place I might go to get some "phone vs desktop browser" information and advice?
          I have tried screen.ldDailyLogDetails_FK.refresh(); as well.
    david

    Hi David,
    From your description above, it seems that this issue happens occasionally. At the same time you can also use some tool to test your lightswitch application, such as:
    Fiddler, it will be helpful to troubleshoot.
    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.

  • Updating Multiple entities Programmatically in LightSwitch Html Client 2013

    hi,
    How to Update Multiple entities When Updating One entity in Server Side ?
    Thanks in Advance...

    You'll probably need to give a little more information about your particular scenario but if you're doing this update server side using the updating method of your entity then you have access to do what you like with any record/entity.
    If the entities are related then it may just be a case of a statement like:
    YourEntity.YourRelatedEntity.SomeProperty = "Hello world.";
    Or you could call a entity specifically from another table and update it accordingly:
    AnotherTable ent = DataWorkspace.ApplicationData.AnotherTable.Where(r => r.id == 5).FirstOrDefault();
    if (ent != null)
    ent.Description = "Hello World.";
    Hope that helps you.
    Paul.

  • LIGHTSWITCH HTML ENTITY SOFT DELETION

    Hello all,
    I am working on LightSwitch HTML client application. I have an issue regarding entity soft deletion.
    For your kind information, I have also referred Beth Messi's link:
    http://blogs.msdn.com/b/bethmassi/archive/2011/11/18/using-the-save-and-query-pipeline-to-archive-deleted-records.aspx
    My Scenario:  
    I have an Accounts table which is related to other tables.
    In Accounts edit screen, I have a delete button. On deleting account from edit screen Account should be marked as deleted in database(i.e. soft delete) if it has no reference in any other table, otherwise show client side an error message
    myapp.EditAccount.DeleteAccount_Tap_execute = function (screen) {
    // Write code here.
    screen.Account.deleteEntity();
    myapp.applyChanges().then(function success() {
    // Delete successful message.
    }, function error(e) {
    // Delete failure message.
    According to Beth Messi's example: On deletion, the entity will discard changes and mark the entity as soft deleted. 
    So, If data is discarded then I do not get the server side exception " Could not delete. entity is in use." and my code inside function error() could not execute.
    Any different way to accomplish this is also appreciated.  
    Thanks,
    Ravi Patel

    HI Ravi,
    As Beth’s blog said, it marks records for deletion without actually deleting them from the database. It discards the changes, this reverts the deletion.
    As I know, myapp.applyChanges(), calling apply will save all the changes of the current changeset. If only one changeset exists, it will save them to the database. If the current changeset is a nested scope, it will commit the changes to
    the parent changeset. I don’t think you can use myapp.applyChanges()
    method in this scenario.
    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.

Maybe you are looking for

  • How to delete Content Source in Sharepoint 2013 Search Service

    I want to delete Default Content Source in Search Service in SharePoint 2013 but delete button is disable?Please see the below image. Content Source Type=SharePoint Sites How to do it? If In Content Source type=Files than delete button enables but no

  • Display the W-2 form in PDF in portal

    Hi, Has anyone ever had a request to display the W2 and 1099 forms online in the portal? I know there is an SAP standard service to request a W-2 reprint, but the client wants the end users to be able to select a year and then the W2 for that year is

  • Missing text in itemrenderer button.

    I've upgraded from Flex2 to Flex3, and while it's working much better for me overall I still have one problem that I can't figure out. In some of my datagrids, I have a column that displays a button (the button is used for removing it's row from the

  • Does class/static context make an object?

    Howdy all! I know that for every class there exists a 'static context' in which all static members of a class operate - methods, variables or classes. I also know that there is a method getClass() which retrieves a Class object. My question is: does

  • SDM upgrade

    folks i'm trying to upgrade the sdm on my 1841 via the update tool in the sdm but when trying to load onto the router the upload failed after it had removed the old sdm so now i can't get onto the router anyone any suggestions how i can recover this?