Logout agent from Finesse gadget

Version 1
    This document was generated from CDN thread

    Created by: yogesh kumar on 08-11-2013 10:22:50 AM
    I want to logout agent when user click somewhere on the gadget. For that I have called finesse Logout api. I am passsing hard coded 0 value for reasonCode.

    logOut = function(reasonCode){
           user.logout(reasonCode, {
                         success: logoutSuccess,
                         error: logoutError
                  });
    },
     
    I get response on logoutsuccess with parameter something like:
    Object { status=202, object={...}, content=""}

    But agent didn’t log out from finesse agent desktop.  What can cause such behaviour?

    Subject: RE: New Message from yogesh kumar in Finesse - General Questions: Logout ag
    Replied by: David Lender on 08-11-2013 12:12:44 PM
    Is 0 a valid defined reason code id?  (not code but id)  You can use the following Rest API to view the reason codes that are defined for the agent.
    http://<server>/finesse/api/User/<id>/ReasonCodes?category=LOGOUT<http://%3cserver%3e/finesse/api/User/%3cid%3e/ReasonCodes?category=LOGOUT>


    Or  use user.getSignoutReasonCodes()

    Subject: RE: Logout agent from Finesse gadget
    Replied by: Joseph Horvath on 08-11-2013 05:34:05 PM
    Did you get an ApiError object back from the logout request or as an Event?

    Subject: RE: Logout agent from Finesse gadget
    Replied by: yogesh kumar on 10-11-2013 03:50:09 AM
    I tried running the same command through console(without and with call-backs)
    User.logout(0);
    Where 0 is not a valid logout code id. I get the response in console
     1<data>
     2    <apiErrors>
     3      <apiError>
     4        <errorData>281</errorData>
     5        <errorMessage>CF_REASON_CODE_REQUIRED</errorMessage>
     6        <errorType>Generic Error</errorType>
     7      </apiError>
     8    </apiErrors>
     9  </data>
    10  <event>put</event>
    11  <requestId>9f44862e-ff43-423f-80ad-b3c9d7e9e83b</requestId>
    12  <source>/finesse/api/User/1004</source>
    13</Update>

     
    Now I run the same command with valid reason code then I get the following error:
    1TypeError: v is undefined
    2xml += ind + toXml(v[i], name, ind + "\t") + "\n";[/i]

    from the function “in function json2xml: function(o, tab)”



    Subject: RE: Logout agent from Finesse gadget
    Replied by: Joseph Horvath on 11-11-2013 09:31:08 AM
    OK, so we can see that a VALID REASON CODE is required for a LOGOUT.

    You will need to fix your JavaScript code in order to test the logout with a VALID REASON CODE. You can place your JavaScript code here and I will be more than happy to look at it with you.

    Subject: RE: Logout agent from Finesse gadget
    Replied by: yogesh kumar on 13-11-2013 03:00:47 AM
    Here is my code for logout:
     1var finesse = finesse || {};
     2finesse.gadget = finesse.gadget || {};
     3finesse.container = finesse.container || {};
     4clientLogs = finesse.cslogger.ClientLogger || {};  // for logging
     5
     6/** @namespace */
     7//Configuration for the gadget
     8finesse.gadget.Config = (function () {
     9  var _prefs = new gadgets.Prefs();
    10  /** @scope finesse.gadget.Config */
    11  return {
    12         authorization: _prefs.getString("authorization"),
    13         host: _prefs.getString("host"),
    14         restHost: "localhost"
    15        };
    16}());
    17
    18/** @namespace */
    19finesse.modules = finesse.modules || {};
    20finesse.modules.logOutGadget = (function ($) {
    21  var user,
    22  handleNewDialog = function(dialog) {     },
    23  handleEndDialog = function(dialog) {    },
    24
    25  handleUserLoad = function (userevent) {
    26        dialogs = user.getDialogs( {
    27                                    onCollectionAdd : handleNewDialog,
    28                                    onCollectionDelete : handleEndDialog
    29                               });   
    30  },
    31  logOutUser = function(reasonCode){
    32        user.logout(reasonCode, {
    33        success: handleSuccess,
    34        error: handleError
    35  });
    36},
    37
    38handleUserChange = function(userevent) {    }, 
    39handleUserError = function(userevent) {    },
    40handleError = function(data){ alert('Error in Logout');};
    41handleSuccess = function (data) {alert('Logout Success');}
    42return {
    43    /**     * Performs all initialization for this gadget     */  
    44    init: function () {
    45        var prefs =  new gadgets.Prefs(),
    46        id = prefs.getString("id");        
    47        var clientLogs = finesse.cslogger.ClientLogger;  
    48        finesse.clientservices.ClientServices.init(finesse.gadget.Config);
    49        user = new finesse.restservices.User({id: id, 
    50                                              onLoad : handleUserLoad,
    51                                              onChange : handleUserChange,
    52                                              onLoadError: handleUserError
    53                                             });
    54        states = finesse.restservices.User.States;
    55    },
    56
    57    logOutGadgetReq : function(reasonCode){
    58        logOutUser(reasonCode);
    59    }};
    60}(jQuery));


    Subject: RE: Logout agent from Finesse gadget
    Replied by: Joseph Horvath on 13-11-2013 09:04:05 AM
    The code in the previous POST allows me to logout successfully. Note that I have a Gadget that calls the init() method, then the logOutGadgetReq() method.

    Subject: RE: Logout agent from Finesse gadget
    Replied by: yogesh kumar on 18-11-2013 12:27:15 PM
    I am still struggling with logout api. Giving some more information which might help us to resolve the issue.

    For
    http://<server>/finesse/api/User/<id>/ReasonCodes?category=LOGOUT
    This is the response I get
    <ReasonCodes category="LOGOUT"><ReasonCode><uri>/finesse/api/ReasonCode/11</uri><category>LOGOUT</category><code>4</code><label>Timed Out</label><forAll>true</forAll></ReasonCode></ReasonCodes>
     
    Then in logout gadget I first call the init method after that I called logoutreq like this
    finesse.modules.logOutGadget.logOutGadgetReq('11');

    ps:How can I upload the gadget here?