简体   繁体   中英

Execute Stored Procedure from LightSwitch HTML Application

I am new to LightSwitch and as such am unfamiliar with my toolset of entities and methods .

I have an application which uses a dataSource called BrattlecubesData and contains two views: TBG_V_TimeLog_Details and TBG_V_TimeLog_Projects . These two datasets are joined by ProjectID and used to display two different browse screens.

My problem is, I want to implement a button on a ViewDetails screen, which deletes the currently selected record from a dimension table (a dimension table which is not included in my application). I want to achieve this via StoredProcedure.

I have found an MSDN article detailing how to do this, but they focused on C# and VB rather than the Javascript which I am using in my HTML application.

THIS LINK offers a translation of the MSDN C# code into Javascript, however I have been getting a recurring error in regards to my declaration of my dataset (error 0x800a138f - JavaScript runtime error: Unable to get property 'ApplicationData' of undefined or null reference )

I then decided to try the alternate technique of creating a table with which to execute my procedure, as outlined in the MSDN article above and also here . This technique however also eventually needed a button which led me to the Javascript, where I attempted to use the translated code resulting in the same error.

Following the instructions from the MSDN blog by Eric Erhardt link, I have error free C# code to call my procedure but am stuck again on the Button which passes the LineItemID to my table and then procedure to be deleted. My Button's Edit Execute Code code is below

myapp.ViewRecordDetails.DeleteRecord_execute = function (screen) {

    var dws = screen.TBG_V_TimeLog_Detail.dataWorkspace;
    var comment = screen.TBG_V_TimeLog_Detail.selectedItem;

    var operation =
        dws.ApplicationData.DeleteProjectComment_Operations.addNew();
    operation.LineItemID = comment.LineItemID;

    dws.ApplicationData.saveChanges();
};

When run this is giving me the same 0x800a138f error an balking at 'ApplicationData'. My solution does have a dataSource called ApplicationData which has a manually created table called DeleteProjectComment_Operations . Again, this button is located on a ViewDetails screen. The ViewDetails has a button which links to an EditDetails screen, and the Editing works as I want.

If I would be better off moving the Delete to my EditDetails screen, I am happy to do that. Or if the solution is to add the dimension table to my solution, please provide guidance on how to restructure my functions or screens

I am at a loss for how to troubleshoot which entity I need to access or how to edit my code in order to pass the LineItemID to my procedure.

It has also been suggested to me that I could use AJAX to achieve my goal, and if that is the suggested route please provide me with some clarification on how that would be done.

Thank you in advance, and I hope I have given enough detail, but am happy to provide more.

It should be possible to successfully implement the Eric Erhardt approach by using the following execute code:

myapp.ViewRecordDetails.DeleteRecord_execute = function (screen) {

    var dws = myapp.activeDataWorkspace;
    var comment = screen.TBG_V_TimeLog_Detail;

    var operation = dws.ApplicationData.DeleteProjectComment_Operations.addNew();
    operation.LineItemID = comment.LineItemID;

    dws.ApplicationData.saveChanges();
};

The only difference from your code is a change to the dws assignment from:

var dws = screen.TBG_V_TimeLog_Detail.dataWorkspace;

to:

var dws = myapp.activeDataWorkspace;

If you're still encountering problems after this modification, I would extend the saveChanges call to report any errors as follows:

dws.ApplicationData.saveChanges().then(null, function (errors) {
    errors.forEach(function (error) { 
        alert(error.message); 
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM