How to trigger click event when app started in browser??
-
Wednesday, December 05, 2012 11:02 AMHi, i hope you can help me.
I have a LS Html Client Beta2 application. When I open the uri, which contains an entry id, I want to open the details screen for this entry.
I have a button on my browse data screen and when I click this button, my entry details screen opens.
But how can I click this button automatically when I open the uri?
I have an jquery trigger, and it should work, but in which method I have to place it? In my .created function (screen) it doesn't work, because the data is loaded after created.
I can't believe, that this isn't possible.
I'll be grateful for any help!
All Replies
-
Thursday, December 06, 2012 6:16 PM
@sstigi: If I understand correctly, you want to parameterize your application by passing a query parameter in the URI. So if you navigate in your browser to http://myserver/myapp/client/default.htm?entryId=123, you want it to automatically navigate from the home screen to a details screen for this entry.
There isn't an easy way to do this with the current preview, but you could try code like this:
myapp.MyBrowseScreen.created = function (screen) {
var entryId = <get entry ID from query parameter>;
if (entryId) {
myapp.dataWorkspace.MyService.Entries_SingleOrDefault(entryId)
.execute().then(function (value) {
var entry = value.results.length ? value.results[0] : null;
if (entry) {
return myapp.showAddEditEntry(msls.BoundaryOption.save, entry);
}
}
);
}
}This code doesn't depend on the browse screen being loaded; it first queries the entry entity given the entryId and once retrieving that result, tries to show the screen for it. It doesn't account for what should happen if it fails to find an entry for the given entry ID - it just stays on the browse screen.
Let me know if this gets you closer to what you want.
Visual Studio LightSwitch Team
-
Thursday, December 13, 2012 2:48 PM
Thank you four your help, I'll try it in a view days and let you know the result ;)
-
Monday, February 11, 2013 10:08 PM
@sstigi: If I understand correctly, you want to parameterize your application by passing a query parameter in the URI. So if you navigate in your browser to http://myserver/myapp/client/default.htm?entryId=123, you want it to automatically navigate from the home screen to a details screen for this entry.
There isn't an easy way to do this with the current preview, but you could try code like this:
myapp.MyBrowseScreen.created = function (screen) {
var entryId = <get entry ID from query parameter>;
if (entryId) {
myapp.dataWorkspace.MyService.Entries_SingleOrDefault(entryId)
.execute().then(function (value) {
var entry = value.results.length ? value.results[0] : null;
if (entry) {
return myapp.showAddEditEntry(msls.BoundaryOption.save, entry);
}
}
);
}
}This code doesn't depend on the browse screen being loaded; it first queries the entry entity given the entryId and once retrieving that result, tries to show the screen for it. It doesn't account for what should happen if it fails to find an entry for the given entry ID - it just stays on the browse screen.
Let me know if this gets you closer to what you want.
Visual Studio LightSwitch Team
Hey there.
The code as it is does not work at least in my case - i had to add some kind of waiting mess there - can you advise any trick to make the switching working without even showing the main screen?
function getURLParameter(name) { return decodeURI( (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]); } myapp.Welcome.created = function (screen) { // Write code here. var contractId = getURLParameter("contractId"); if ((screen.details._modelId == "Welcome") && (contractId != "")) { function check() { if (screen.details._propertyData.Contract._loading != false) { window.setTimeout(check, 10); } else { gofurther(); } } check(); function gofurther() { myapp.dataWorkspace.ApplicationData.Contract_SingleOrDefault(contractId) .execute().then(function (value) { var entry = value.results.length ? value.results[0] : null; if (entry) { return myapp.showContractDetail(msls.BoundaryOption.save, entry); } }); } } };
Sergey Vdovin
-
Monday, February 11, 2013 11:34 PM
Sergey,
The code I provided should work. Can you explain more the problem you are seeing? There shouldn't be a need to wait to execute the query once you have the contractId in hand.
Also be aware that using any members starting with an underscore is taking a dependency on internals of the LightSwitch runtime and you should avoid that. There are public APIs for all the information you are using here, such as the loading information would be available at screen.details.properties.Contract.loading. Internally it uses _propertyData, but that is subject to change over time.
Stephen
Visual Studio LightSwitch Team
-
Tuesday, February 12, 2013 10:04 PM
Hello, Stephen.
without
function check() { if (screen.details._propertyData.Contract._loading != false) { window.setTimeout(check, 10); } else { gofurther(); } } check();
the navigate method
myapp.showContractDetail(msls.BoundaryOption.save, entry);
just does not navigate (it does some codework in the ls internals but in the result the page remains the same) when launched in the created event.
_loadingi just use because it was the first difference i noticed between button launch of the code (it works within the button) and in the event launch - ok will keep in mind
Sergey Vdovin
-
Wednesday, February 13, 2013 5:23 PM
Sergey,
It sounds like you may be running into a timing issue. I'm trying to reproduce your scenario but I don't quite understand how your screens are configured. On the Welcome screen, you have a "Contract" property. Is this tied to a query? If so, what query is it and how does it determine what contract to return?
Thanks,
StephenVisual Studio LightSwitch Team
-
Wednesday, February 13, 2013 5:33 PM
Hello again, Stephen.
Yes, sounds like this.
Actually Contract is a table under the ApplicationData node - i guess
screen.details._propertyData.Contract
is tied to that table (i did not add something special with the name "Contract" what i can call "property").
Sergey Vdovin
-
Wednesday, February 13, 2013 5:51 PM
The code "screen.details._propertyData.Contract" tells me that there is a "Contract" property defined on the Welcome screen. How did you create the Welcome screen (which screen template)?
Thanks,
StephenVisual Studio LightSwitch Team
-
Wednesday, February 13, 2013 6:04 PMbrowse template + contracts table
Sergey Vdovin
-
Wednesday, February 13, 2013 6:06 PMActually i can send the project if it helps
Sergey Vdovin
-
Wednesday, February 13, 2013 7:05 PMThat would be great if you are willing to share.
Visual Studio LightSwitch Team
-
Wednesday, February 13, 2013 7:12 PM
sergey.a.vdovin@gmail.com
i will send the project back in the responce
Sergey Vdovin
-
Tuesday, February 19, 2013 7:05 PM
Sorry for the delay. I was able to reproduce the issue with the information you provided, and this is an issue with the current release. The specific problem is related to the fact that this logic is on the home screen and that the created code is called before the application has completed navigating to this first screen.
You should be able to workaround this issue using a single setTimeout call that wraps your goFurther() call. This pushes the query to run after the navigation has completed. Please let me know if this does not work.
Thanks for identifying the issue.
Visual Studio LightSwitch Team
- Marked As Answer by Beth MassiMicrosoft Employee, Owner Wednesday, February 20, 2013 8:44 AM
-
Tuesday, February 19, 2013 8:42 PM
ok will check it tomorow
actually we asked our PAM to check if we can take a part in lightswitch html TAP - like 2 weeks ago he had some kind of a connection with the TAP desk and the process stopped somewhere there (currently PAM at vacation, his substitutor do not send the emails back)
ok it is all like a fun, but we have a real project and i really want to implement a part of it on lightswitch html
Stephen, may be you can advice - how we as a partner can push the process?
Sergey Vdovin
-
Tuesday, February 19, 2013 10:10 PMOwner
Hi Sergey,
Who is your PAM contact? I will follow up with them.
Thanks,
-BethSenior Program Manager, Visual Studio Community http://www.bethmassi.com http://msdn.com/lightswitch http://dev.office.com
-
Wednesday, February 20, 2013 2:44 AM
Thanks, Stephen.
Hi, Beth.
Alexander Blinov (v-alblin@microsoft.com) - at vacation
Tatyana Leffka ('v-50tatl@microsoft.com) - Alexander 'away' contact
and additional contact (was in cc field of that emails - i could not reach Tatyana as for now):
Andrey Cherkasov (i-andc@microsoft.com)
Thanks in advance
Sergey Vdovin
-
Wednesday, February 20, 2013 9:54 AM
Sorry for the delay. I was able to reproduce the issue with the information you provided, and this is an issue with the current release. The specific problem is related to the fact that this logic is on the home screen and that the created code is called before the application has completed navigating to this first screen.
You should be able to workaround this issue using a single setTimeout call that wraps your goFurther() call. This pushes the query to run after the navigation has completed. Please let me know if this does not work.
Thanks for identifying the issue.
Visual Studio LightSwitch Team
Hello again, Stephen.
If got it right, the code should looks like this:
function getURLParameter(name) { return decodeURI( (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]); } var contractId; myapp.Welcome.created = function (screen) { // Write code here. contractId = getURLParameter("contractId"); if ((screen.details._modelId == "Welcome") && (contractId != "")) { if (screen.details._propertyData.Contract._loading != false) { window.setTimeout(gofurther(), 10); } else gofurther(); } }; function gofurther() { myapp.dataWorkspace.ApplicationData.Contract_SingleOrDefault(contractId) .execute().then(function (value) { var entry = value.results.length ? value.results[0] : null; if (entry) { return myapp.showContractDetail(msls.BoundaryOption.save, entry); } }); };it runs through
window.setTimeout(gofurther(), 10);
with the same problem result
IE10.0.9200.16466, KB2761465
Sergey Vdovin
-
Wednesday, February 20, 2013 6:59 PM
Interesting. This isn't what I was seeing in my repro project. Here is the code that I used in the created method:
var contractId = getURLParameter("contractId"); if (contractId) { setTimeout(function () { myapp.dataWorkspace.ApplicationData.Contracts_SingleOrDefault(contractId) .execute().then(function (value) { var entry = value.results.length ? value.results[0] : null; if (entry) { return myapp.showContractDetail(msls.BoundaryOption.save, entry); } }); }, 1); }You don't need the check for the screen model ID because it will always be the Welcome screen. You also don't need the check for the _loading status of the Contact entity as this is unrelated to the issue and it is just by coincidence that when _loading = true, calling myapp.showContractDetail works. I also simplified the code by inlining the goFurther() function.
Please give this code a try and let me know if it still doesn't work.
Visual Studio LightSwitch Team
-
Thursday, February 21, 2013 4:12 AM
It works.
There was en error in my last code: function name vs function call in settimeout.
Sergey Vdovin
-
Tuesday, February 26, 2013 8:56 AM
Hi Stephen, Beth.
The guys in Microsoft Russia told me that they have had a connection with Beth, but the process block is still here and is the same - they are waiting for some kind of an access - is anything possible to do with that?
Sergey Vdovin
-
Tuesday, February 26, 2013 5:08 PMOwner
Hi Sergey,
I connected them with a TAP representative here in the USA so things should get unblocked.
Cheers,
-BethSenior Program Manager, Visual Studio Community http://www.bethmassi.com http://msdn.com/lightswitch http://dev.office.com
-
Friday, March 01, 2013 8:07 PM
Beth, It is just not working - they are still waiting for the same stuff they were waiting this weeks.
Can you do anything else?
Sergey Vdovin
-
Saturday, March 09, 2013 6:08 PMUP: Beth, there are still no news and results about the theme - promises are good, of course - but sometimes it is nice to have them aligned with the results.
Sergey Vdovin
- Edited by Evolex Saturday, March 09, 2013 6:09 PM
-
Monday, March 11, 2013 6:20 PMOwner
Hi Sergey,
I emailed the contact you gave me and pointed them to a person that could help them. I would suggest contacting them directly about it again. If they are still having trouble, feel free to have them contact me directly with the exact problem they are having, I'm not sure what they are struggling with.
Thanks,
-BethSenior Program Manager, Visual Studio Community http://www.bethmassi.com http://msdn.com/lightswitch http://dev.office.com

