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

Brad Bowman
Kilo Patron
Kilo Patron

Post an example of the script(s) that are not working.

hcoburn
Tera Contributor

The onSubmit that has been working on desktop:  I sometimes set another field that is in the sc_cart record that indicates the type of transaction (new hire, transfer, patch, etc) which is utilized in the request workflow....

 

     function onSubmit() {
            var for_userid = g_form.getValue('usrname' ); 
            var userid = g_user.userName;  

            var cart = new GlideRecord('sc_cart');
            cart.addQuery('user.user_name', userid);
             cart.query();
            if (cart.next()) {
                cart.requested_for = for_userid;
                cart.special_instructions = 'This is an automated process. Any data entered into the Special Instructions field is not read or taken into consideration in this automated process.';
                cart.update();
           }
   }

 

 

Using a GlideRecord in a client script has never been best practice nor supported, even moreso when using the Service Portal/CMS/Employee Center architecture.  The recommended approach is to use GlideAjax.  The trick is to make sure the cart is updated prior to the form submitting.  This is easiest onChange of a mandatory variable, which fits your use case as you do not need to wait until the form is submitted,so it would be worth going back to that approach to see why it's not working.

@hcoburn GlideRecord queries in the client script on Service portal are not supported. Instead you should use GlideAjax and put your GlideRecord calls in a client callable script include.