Moving to Employee Center and on Submit Catalog Client Scripts not working

hcoburn
Tera Contributor

We use onSubmit to

  • Move a variable to the "Requested For" on the shopping cart.
  • Set the special instructions on the cart (especially our automated processes to reminder users that it is an automated process and the field is not read)
  • Set a field that is utilized in the request workflow for specific approvals

These scripts are not working in Employee Center....

I have tried using the onchange catalog client scripts with GlideAjax calling a script include.  

Using the catalog item workflow will not work since we need the data to process the request workflow properly.

The old on Submit scripts have been set to UI Type Desktop (since they are working)

And the new scripts are UI Type Mobile/Service Portal

 

Any help you can offer would be appreciated.

7 REPLIES 7

hcoburn
Tera Contributor

Most of these scripts were created in 2014 so updating any that are an issue with Employee Center... 

Still cannot get the GlideAjax working, any assistance is greatly appreciated

 

the onchange script:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

     if (isLoading)
         return;


    if (newValue == '')
        return;

 

var ga = new GlideAjax('AjaxFunctions');
    ga.addParam('sysparm_name', 'updateCartOwner');
    ga.addParam('sysparm_user', g_user.userID);
    ga.addParam('sysparm_si', "test special instructions");
    ga.addParam('sysparm_requested_for', newValue);


ga.getXMLAnswer(function(answer) {
    if (answer == 'true')
        g_form.showFieldMsg('requested_for', 'Updated \'Requested for\'', 'info');

else
       g_form.showFieldMsg('requested_for', 'No cart found', 'error');

});

}

 

The Script Include (client callable is set):

 

var AjaxFunctions = Class.create();
AjaxFunctions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
 
   updateCartOwner: function() {
           var user_enter = this.getParameter('sysparm_user');
           var requested_for = this.getParameter('sysparm_requested_for');
           var si_data = this.getParameter('sysparm_si');
 
           var cart = new GlideRecord('sc_cart');
             cart.addQuery('user', user_enter);
             cart.query();
            if (cart.next()) {
                cart.requested_for = requested_for;
                cart.special_instructions = si_data;
                cart.update();    
                    
                   return true;
           }
 
           return false;
         },
 
 
   type: 'AjaxFunctions'
    });

 

 

 

 

Brad Bowman
Kilo Patron
Kilo Patron

As with troubleshooting any scripts, add an alert (before the getXMLAnswer in this case) to confirm the client script is running and the value of g_user.userID to be passed to the server, then some gs.info or addInfoMessage logs to the SI to confirm it is running, the value passed in from the client, and if the GR record is returned by the query...  I haven't used Employee Center, have you confirmed that there is a sc_cart record created for the user before an item is submitted?

hcoburn
Tera Contributor

Finally got this working.  Thank you to everyone.   The script include was not referenced correctly.