'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.
Similar Messages
-
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 NamespaceThis may help:
Creating Reports in LightSwitch HTML Client
// Show Loading message
var LoadingDiv = $("<div></div>");
var Loading = $("<h1> 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 -
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.
ThanksHello 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 -
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?
ThanksBut 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); -
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. -
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 SHi,
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 -
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. -
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 -
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.
davidHi 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. -
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
jlHi 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. -
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. -
HTML Client: How to get the content/value of a custom control?
I made two Custom Controls named, "CustomControl_1" and "CustomControl_2".
In the render function of "CustomControl_1", how to access the value of "CustomControl_2"?
For example,
myapp.BrowseOrders.CustomControl_2_render = function (element, contentItem) {
$(element).text("Some Value");
myapp.BrowseOrders.CustomControl_1_render = function (element, contentItem) {
$(element).text( Value of CustomControl_2 ? );I would recommend creating screen properties and binding the controls to those screen properties. Then you can easily get a reference to any value. See this article for an example of the process using custom controls:
Using The Clippy Agent in the Visual
Studio LightSwitch HTML Client
Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book
http://LightSwitchHelpWebsite.com -
Add line break in name of an interactive report computed field
I have a computed field in an IRR and need the name of this field to be broken into 2 lines. In regular columns I can add "br" right in the column attributes but if I use that in the computed field name, the HTML "br" actually shows up in the field name. How can I do this?
Here is a threa dealing with a nowrap issue for an IRR, try making the nowrap setting in the css a wrap and see what happens..
Re: Interactive Report - fields wrapping
Thank you,
Tony Miller
Webster, TX -
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 PatelHI 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. -
LightSwitch is not showing related data - HTML Client
The AddEdit screen doesn't display any related data, but if I press the Save button without making any changes, close the screen & reopen it, it then shows the data just for that particular record.
For example I have an Employee entity & it has a GenderID(foreign key) which is coming from Gender table. When I open the Employee’s Add/Edit screen the Gender appears blank. If I hit the Save button without doing any data changes, close the screen
& reopen it & it then shows the Gender correctly.
Fiddler shows it is querying correctly & also getting the response, but somehow it
doesn’t appear on the screen. I’ve checked the Add/Edit screen of other entities & it seems the problem is specific to this one only. I’ve also created a new Add/Edit screen for the same entity & it has the same problem.
Divyang VyasManage include data may help:
LightSwitch Tips & Tricks on Query Performance
Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book
http://LightSwitchHelpWebsite.com
Maybe you are looking for
-
Can't watch Netflix after upgrading to Yosemite
I have a MacBook Air, with 4gb, and 2.3 gHz. After I upgraded to Yosemite Netflix stopped working. It gives me an error saying that the "external monitor" is not HD compliant. Have anyone encountered this problem? Have you found a solution? Thanks.
-
Hi all, There is a property named error table for source and target operators in mapping editor. Can anyone tell me about its function? I mean where i can use this feature in mapping. and what is the structure of this error table? where i have to cre
-
Where can I find my filter menus
Hi, guys. I want to apply 'lens flare effect' to my photo. I've known that 'lens flare' is in 'Filter' > 'Render' > 'Lens Flare' But It's not in there. There was just 'Lighting Effects'. How could I find 'Lens Flare' and many other menus that I lost
-
JDeveloper Issue-Urgent.(Unable to find component with absolute reference)
Hello ppl, I been struck up with some JDev issue ,I copied the JDev and set my JDEV_USER_HOME and i create a simple page and try to run it...I get the following error Exception: oracle.adf.mds.MetadataDefException: Unable to find component with absol
-
Wmode=window decreases perfomance?
I recently wrote a Flash game using strictly ActionScript 3.0 in Flex Builder 3. The one thing I notice was even though I targeted 30 frames per second I would only get ~24 fps when running in the browser. I stumbled across an odd solution -- setting