cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1430
Views
10
Helpful
1
Replies

Finesse gadget making a direct transfer button

HI all,

 

I am very new to Finesse coding and wondering if someone wold be able to shed some light on what I am doing wrong.

 

This is the code I am using:

 

var finesse = finesse || {};
finesse.gadget = finesse.gadget || {};
finesse.container = finesse.container || {};
clientLogs = finesse.cslogger.ClientLogger || {};  // for logging
/*global logFinesse */

/** @namespace */
finesse.modules = finesse.modules || {};

finesse.modules.Transfer = (function ($) {
    var clientLogs, user, dialog,

    populateGadget = function () { 
        var currentState = user.getState();

        $("#userId").text(user.getId());
        $("#firstName").text(user.getFirstName());
        $("#lastName").text(user.getLastName());

        if (user.hasSupervisorRole()) {
            $("#userRole").text('Supervisor');
        } else {
            $("#userRole").text('Agent');
        }

        $("#extension").text(user.getExtension());
        $("#userState").text(currentState);
        $("#teamId").text(user.getTeamId());
        $("#teamName").text(user.getTeamName());

        gadgets.window.adjustHeight();
    },

        /**
     * Handler for makeCall when successful.
     */
    makeCallSuccess = function(rsp) { },
    
    /**
     * Handler for makeCall when error occurs.
     */
    makeCallError = function(rsp) {
        $('#errorMsg').html(_util.getErrData(rsp));
    },

    handleUserChange = function(userevent) { populateGadget(); },

    handleUserLoad = function (userevent) { populateGadget(); };

    handleTransferSuccess = function(userevent) {  },

    handleTransferError = function (userevent) { };

    /** @scope finesse.modules.SampleGadget */
    return {
         /**
          * Performs all initialization for this gadget
          */
        initiateDirectTransfer: function ( tooExt ) {
            userExt = user.getExtension();
            dialog.initiateDirectTransfer( userExt, tooExt, {
                success: makeCallSuccess,
                error: makeCallError
            });
        },


        init : function () {
            var cfg = finesse.gadget.Config;

            clientLogs = finesse.cslogger.ClientLogger;   // declare clientLogs
             
            gadgets.window.adjustHeight();
            
            // Initiate the ClientServices and load the user object.  ClientServices are
            // initialized with a reference to the current configuration.
            finesse.clientservices.ClientServices.init(cfg, false);

             // Initiate the ClientLogs. The gadget id will be logged as a part of the message
            clientLogs.init(gadgets.Hub, "Transfer", finesse.gadget.Config); //this gadget id will be logged as a part of the message

            dialog = new finesse.restservices.Dialog({
                id: id,
                onLoad : handleTransferSuccess,
                onChange : handleTransferError
            });

            user = new finesse.restservices.User({
                id: cfg.id, 
                onLoad : handleUserLoad,
                onChange : handleUserChange
            });


        }
    };
}(jQuery));

Currently the issue is that user is not defined on the line containing "userExt = user.getExtension();" inside the "initiateDirectTransfer" function, I can not for the life of me work out how to get this to work.  Could someone either explain the errors or point me in the right direction of some decent docs/tutorials that will help.

 

Thanks in advance,

 

Damian

1 Reply 1

dekwan
Cisco Employee
Cisco Employee

Hi,

 

The user variable is not defined until the init function is called. But even if you fix that issue, the dialog object is not within the scope of that function. So I would suggest that you take a look at the UpdateCallVariableDataSampleGadget to see how to store the dialog object to use the dialog's methods. The only thing for your gadget is that you do not need to call the raw REST API request that you see in the 

updateCallVariable function. Instead the updateCallVariable function should be as simple as:
updateCallVariable = function(name, value) {
if (currentDialog) { clientLogs.log("updateCallVariable(): ..."); currentDialog.initiateDirectTransfer( userExt, tooExt, { success: makeCallSuccess, error: makeCallError }); } else {
clientLogs.log("updateCallVariable(): There are currently no active dialogs");
}
}
 I hope that helps.
 
Thanx,
Denise