I have a tile list in a HTML Lightswitch Client (current version) and want to enable functionality for users to be able to click an element and display the addEdit screen for that element.
The addEdit screen uses a query Complaints
and the tile list uses a query vw_Upcoming_Complaints
. Both queries have a common unique attribute Complant_ID
.
I currently have the following code:
myapp.Main.vw_Upcoming_Complaints_Selected_execute = function (screen) {
myapp.showAddEditComplaints(null, {
beforeShown: function (addEditComplaintScreen) {
addEditComplaintScreen.Complaint = screen.Upcoming_Complaints.selectedItem;
},
afterClosed: function (addEditScreen, navigationAction) {
screen.selected_Complaint.details.refresh();
}
});
};
Lightswitch currently shows the correct Complaint_ID
on the addEdit screen but does not fetch the remainder of the attributes.
How can I tell lightswitch that the common identifier is complaint_Id
and it should find the rest of the attributes in the Complaints
data set?
There is no way for me to edit the original Complaints
query to contain all the attributes of the vw_Upcoming_Work
dataset.
One option would be to update your vw_Upcoming_Complaints_Selected_execute function along the following lines:
myapp.Main.vw_Upcoming_Complaints_Selected_execute = function (screen) {
myapp.showAddEditComplaint(null, {
beforeShown: function (addEditComplaintScreen) {
var id = screen.Upcoming_Complaints.selectedItem.Id;
myapp.activeDataWorkspace.ApplicationData.Complaints_SingleOrDefault(id).execute().then(function onComplete(result) {
if (result && result.results && result.results.length !== 0) {
addEditComplaintScreen.Complaint = result.results[0];
}
});
},
afterClosed: function (addEditScreen, navigationAction) {
screen.selected_Complaint.details.refresh();
}
});
};
This update assumes that your DataSource is called ApplicationData, and the complaint id is the key of your Complaints query.
Based upon these assumptions, the revised version simply locates the matching Complaint entity, by using the _SingleOrDefault method against your Complaints query, and assigns it to the add edit screen.