4 Replies · Latest reply on Nov 14, 2017 7:18 PM by Aakash Shah

    onSubmit Script not working in Service Portal

      I have the following script that works perfectly in the Service Catalog, but not on the Portal.  The UI Type is set to BOTH.

       

      function onSubmit() {
      
      var t = new GlideRecord('sys_user');
      t.addQuery('user_name',g_user.userName);
      t.query();
      while(t.next()){
      var ti = t.title;
      var s = t.u_site;
      if((ti.indexOf('Executive')>=0 || ti.indexOf('Secretary')>=0 || ti.indexOf('Mgr')>=0) && s == '852f90bc0f14b100d39de478b1050ec9'){
      var gr_at = new GlideRecord("sys_attachment");
      gr_at.addQuery("sys_created_by", g_user.userName);
      gr_at.addQuery("sys_created_on", '>=', 'javascript:gs.minutesAgo(10)');
      gr_at.query();
      if(!gr_at.next()){
      
      g_form.addErrorMessage("You must have an attachment to submit.");
      return false;
      
      }
      }
      
      
      }
      }
      

       

      I also attempted to create a business rule that would not allow a requested item to be created without an attachment.  That works great, except for the fact that it still creates an empty REQ.  I tried changing the business rule to run on the sc_request table, but then it doesn't do anything at all.