locked
Passing the operation and additional parameters in a promise RRS feed

  • Question

  • In order to call my Generic File Handlers, I have several functions that look like this:

    function CreatedLogEntry(operation) {
        $.ajax({
            type: 'post',
            data: { pAction: "Created" },
            url: '../web/LogEntry.ashx',
            success: operation.code(function AjaxSuccess(AjaxResult) {
                operation.complete(AjaxResult);
            })
        });
    };


    And I call it like this:

    msls.promiseOperation(CreatedLogEntry).then(

    I'm not sure exactly how the operation parameter is getting passed. This seems to be a basic function of javascript that I have yet to get a handle on. I would like to pass additional parameters so that I can have a single function with variable data. I've tried this:

    function CreatedLogEntry(operation, action) {
        $.ajax({
            type: 'post',
            data: { pAction: "Created" },
            url: '../web/LogEntry.ashx',
            success: operation.code(function AjaxSuccess(AjaxResult) {
                operation.complete(AjaxResult);
            })
        });
    };


    Followed by this:

    msls.promiseOperation(CreatedLogEntry(operation, "Created")).then(

    But it said operation was undefined.

    Is there any way to do this? And if anybody can explain the (to me) mysterious method of passing operation without stating so in the call, that would be much appreciated.

    Thursday, January 14, 2016 11:22 PM

All replies

  • It seems your code is ok, any other explanation for your application?
    Wednesday, January 27, 2016 9:09 AM
  • I have had the same issue and would like to see an answer.  If you pass any parameter other than the operation it seems to fail.  I have had to abandon the msls.promiseOperation and write code like this instead to make the ajax call a promise.  I don't really like this syntax either.  If anyone knows a better way, please post.

    myapp.ViewEmployee.EmployeesBySupervisor_postRender = function (element, contentItem) {
        var renderDisplayText = function (value) {
            var promises = {};
            promises.id = contentItem.screen.getEmployeeId();
            promises.active = contentItem.screen.getActive();
            promises.employee = contentItem.screen.getEmployeeDetail();
    
            return WinJS.Promise.join(promises).then(function (values) {
                var getQueryCount = $.ajax({
                    type: 'GET',
                    url: '../api/QueryCount/EmployeesBySupervisorCount?id=' +
                        values.id + '&active=' + values.active
                });
    
                return getQueryCount.then(function success (count) {
    
                    // do stuff
    
                }, function error (jqXHR, textStatus, errorThrown) {
                    // do stuff
                });
            });
        };
        return contentItem.dataBind('screen.Active.value', renderDisplayText);
    };

    • Edited by Hessc Wednesday, January 27, 2016 6:36 PM
    Wednesday, January 27, 2016 6:25 PM