4 Replies · Latest reply on Dec 22, 2017 5:08 AM by billu balaji

    Ui Action for both server and client side code is not working properly?

      Hello All,

       

      I have written a Ui Action code  for both serve and client side code is not working properly?

       

      Below is the code and screen shot, please tell me the issue in the below code.

       

      function mandatory()

      {

        g_form.setMandatory('u_technology_group',true);

        gsftSubmit(null, g_form.getFormElement(), "isnew");

      }

       

       

       

       

      if(typeof window == 'undefined')

         runBusRuleCode();

       

       

      //Server-side function

      function runBusRuleCode(){

      var name = gs.getUser().getFullName();

      current.assigned_to = name;

      current.state =6;

      current.update();

      action.setRedirectURL(current);

      }

       

       

      Thanks

        • Re: Ui Action for both server and client side code is not working properly?
          brendanwilson84

          you have client checked, but noting in the onclick, put in onclick Mandatory()

           

          Also under link 9 you need to call your action name, server side

          if(typeof window == 'undefined') 

             runBusRuleCode(); // you missed having the function definition

          //Call the UI Action and skip the 'onclick' function 

             gsftSubmit(null, g_form.getFormElement(), 'action name'); //MUST call the 'Action name' set in this UI Action

          1 of 1 people found this helpful
          • Re: Ui Action for both server and client side code is not working properly?
            Dave Smith

            As Brendan mentioned, there's a few issues here:

            1. mandatory() needs to be in "onclick", not in "hint".
            2. you are using GlideSystem which is server-side in client-side code - that ought to go into a Script Include to be called it from your client action?
            3. You're not really explaining what outcome you're after - other than your code working. If you were to explain why you're trying to do something, perhaps alternative approaches could be explored
            4. "code is not working properly?" isn't really a particularly verbose problem definition.

             

            Have you attended our script course at all?  http://www.servicenow.com/services/training-and-certification/scripting-in-servicenow-training.html - we often look at this kind of coding and also some troubleshooting/debugging tools that could help.

            1 of 1 people found this helpful
            • Re: Ui Action for both server and client side code is not working properly?
              Jim Coyne

              As Brendan and Dave mentioned, you are not very specific as to what "is not working properly", which makes it a bit difficult to help you out.

               

              However, that being said, there are some obvious questions and issues:

              1. what is in the "Action name" field of the UI Action?  I'm assuming it is "isnew" because of line 4 in your code.  These 2 must match.

              2. I like to prefix custom JavaScript function names with "u_" just in case ServiceNow adds functions with the same name.  This limits the problem.

              3. "u_mandatory();" should be in the "Onclick" field and not in the "Hint" field

              4. when setting the "assigned_to" field, you need to use a sys_id and not the user's name

              5. the following code should work for you now:

               

              function u_mandatory() {
                g_form.setMandatory('u_technology_group',true);
                gsftSubmit(null, g_form.getFormElement(), "isnew");
              }
              
              if(typeof window == 'undefined')
                u_runBusRuleCode();
              
              //Server-side function
              function u_runBusRuleCode(){
                current.assigned_to = gs.getUserID();
                current.state = 6;
                current.update();
                action.setRedirectURL(current);
              }
              
              2 of 2 people found this helpful

              *** Please Like and/or tag responses as being Correct.
              And don't be shy about tagging reponses as Helpful if they were, even if it was not a response to one of your own questions ***