cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1665
Views
16
Helpful
11
Replies

Unable to set reason code to NOT_READY

Patrick Curley
Level 1
Level 1

I have a gadget where I need to set the agent to NOT_READY.

Here is a code snippet:

var currentState = user.getState();

     if ( currentState == "READY" ) {

          console.log("Setting state to NOT_READY");

          user.setState(states.NOT_READY,'10',{

               success: success,

               error: makeStateError

          });

     }

};

I always get the same error:

Object { status: 400, content: "<ApiErrors>

  <ApiError>

    <ErrorType>Parameter Missing</ErrorType>

    <ErrorData>finesse.api.reasoncode.require_reasoncode</ErrorData>

    <ErrorMessage>The state change requires a valid reason code.</ErrorMessage>

  </ApiError>

</ApiErrors>", object: Object }

I know I need to send the reason code id.  But it still gives me this error. 

I used this to get the valid reason code ids.

http://10.89.194.14/finesse/api/User/50005/ReasonCodes?category=NOT_READY

Here is part of the return:

<ReasonCodes category="NOT_READY"><ReasonCode><uri>/finesse/api/ReasonCode/5</uri><category>NOT_READY</category><code>10</code><label>End of Shift</label><forAll>true</forAll></ReasonCode>

As you can see I get a reason code id of 10 back.  So I use 10 for the reason code id when I try to change the agent state but I always get the error.  Any help would be appreciated.

11 Replies 11

ewindgat
Level 5
Level 5

The reasoncode ID should be used, not the reasoncode. Let me know if this works for you.

Thanks for the answer Edwin.  But I was saying I have been using the reasoncode ID and it is not working.  Please see the details in my original post.  I am using 10 but I still get the error. 

This does not resolve my issue.

Please advise.

Let me look into this further. You should have a reply by tomorrow.

This is a bit confusing. The ReasonCodeID should be used. The returned URL of <code>10</code> is the ReasonCode, and not what you are looking for.

You need is the value of 5 (in your example), that is the real ReasonCodeID...

<ReasonCode><uri>/finesse/api/ReasonCode/5"><ReasonCode><uri>/finesse/api/ReasonCode/5

OK, that makes sense.  Now I know the correct value to use, but it still gives me the same error.  However, I am able to use the Finesse web service using Ajax, I can do a PUT and then it works. That is a work around though, and I have to pass in the user name and password.  I would rather get it to work using the user object. 

Hi

Try this:

var currentState = user.getState();

     if ( currentState == "READY" ) {

          console.log("Setting state to NOT_READY");

          rc = { id: '10' };

          user.setState(states.NOT_READY,rc,{

               success: success,

               error: makeStateError

          });

     }

};

Reason code must be sent as a dictionary (i believe that's what this is called) where the reason code is set as a key named id.

This has been a major headace for me for a few months now, finally figured this out yesterday

Finnur

Hi,

I have scenario where system shouldn't allow user/agent to change state to READY.If user tries to change READY system should automatically put them to NOT_READY so when i am trying with below code system is giving alert but its allowing agent to go to READY:(.  Do you know why?Any help is really appreciated.

  if ( currentState == "READY" )

         {

alert("Inside currentState Condition!!" + currentState);

          console.log("Setting state to NOT_READY");

          rc = { id: '10' };

          user.setState(states.NOT_READY,rc,{

               success: success,

               error: makeStateError

          });

};

Hi,

Where do you have this code?

If the agent is making the change to READY using the actual agent state change from the desktop, you cannot stop that request in a custom gadget. You need to allow it to go READY and then switch it back to NOT_READY via the custom gadget.

So, when you say "its allowing agent to go READY", do you mean that it is not setting the agent back to NOT_READY? Take a look at the webservices logs to see if there is an error being sent.

Thanx,

Denise

Thanks.Following is my JavaScript file. Yes we are allowing agent to change status to READY, but after am checking the currentstatus and if its READY then am trying to change it back to NOT_READY.

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

/**
* The following comment prevents JSLint errors concerning the logFinesse function being undefined.
* logFinesse is defined in Log.js, which should also be included by gadget the includes this file.
*/
/*global logFinesse */

/** @namespace */
finesse.modules = finesse.modules || {};
finesse.modules.SampleGadget = (function ($) {
    var user, states, dialogs, clientlogs, malength,

    /**
     * Populates the fields in the gadget with data
     */
    render = function () {
        var currentState = user.getState();
var malength = user.getMobileAgentDialNumber();
var dnLenght = malength.length;
        // Examples of getting data from the User object (GET)

        if (user.isMobileAgent() && user.getMobileAgentDialNumber().length != 11) {
           alert("Hello! You have entered Invalid Dial Number.\n Please check and enter correct 11 digit number!!" + dnLenght);
   
    if (user.isMobileAgent() && user.getMobileAgentDialNumber().length != 11 && user.getState() != "NOT_READY") {
       alert("Inside Condition!!" + user.getState());
    } 

  
        }

      if ( currentState == "READY" )
         {
  alert("Inside currentState Condition!!" + currentState);
          console.log("Setting state to NOT_READY");
          rc = { id: '10' };
          user.setState(states.NOT_READY,rc,{
               success: success,
               error: makeStateError
          });
};

        //$("#userState").text(currentState);

        gadgets.window.adjustHeight();
    },

    /**
     * Handler for the onLoad of a User object. This occurs when the User object is initially read
     * from the Finesse server. Any once only initialization should be done within this function.
     */
    handleUserLoad = function (userevent) {
        render();
    },
     
    /**
     *  Handler for all User updates
     */
    handleUserChange = function(userevent) {

        render();
    };

    /** @scope finesse.modules.SampleGadget */
    return {
        /**

         * Performs all initialization for this gadget
         */
        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, "LearningSampleGadget");

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

            states = finesse.restservices.User.States;
  
           
            // Initiate the ContainerServices and add a handler for when the tab is visible
            // to adjust the height of this gadget in case the tab was not visible
            // when the html was rendered (adjustHeight only works when tab is visible)
            containerServices = finesse.containerservices.ContainerServices.init();
            containerServices.addHandler(finesse.containerservices.ContainerServices.Topics.ACTIVE_TAB, function() {
                clientLogs.log("Gadget is now visible");  // log to Finesse logger
                // automatically adjust the height of the gadget to show the html
                gadgets.window.adjustHeight();
            });
            containerServices.makeActiveTabReq();
        }
    };
}(jQuery));

Glancing at the code, the code snippet looks correct. I did notice that you have a success and onError handler, but I don't see it defined. Two suggestions, breakpoint it in the browser's developer's tool and make sure that the setState method is actually being executed successfully. If so, take a look at the webservices logs to see if you are getting an error back.

Thanx,

Denise

Thanks Denise, After defining success and onError handler its working fine now.AgentState is changing from READY to NOT_READY without any issues.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: