code: def _get_formatted_query(self, fields, limit, order_by, offset):
          
  
          if not isinstance(order_by, list):
              raise InvalidUsage("Argument order_by should be a `list` of fields")
  
          if not isinstance(fields, list):
              raise InvalidUsage("Argument fields should be a `list` of fields")
  
          if isinstance(self.query, QueryBuilder):
              sysparm_query = str(self.query)
          elif isinstance(self.query, dict):  # Dict-type query
              sysparm_query = '^'.join(['%s=%s' % (k, v) for k, v in six.iteritems(self.query)])
          elif isinstance(self.query, six.string_types):  # String-type query
              sysparm_query = self.query
          else:
              raise InvalidUsage("Query must be instance of %s, %s or %s" % (QueryBuilder, str, dict))
  
          for field in order_by:
              if field[0] == '-':
                  sysparm_query += "^ORDERBYDESC%s" % field[1:]
              else:
                  sysparm_query += "^ORDERBY%s" % field
  
          params = {'sysparm_query': sysparm_query}
          params.update(self.request_params)
  
          if limit is not None:
              params.update({'sysparm_limit': limit, 'sysparm_suppress_pagination_header': True})
  
          if offset is not None:
              params.update({'sysparm_offset': offset})
  
          if len(fields) > 0:
              params.update({'sysparm_fields': ",".join(fields)})
  
          return params
docs: Converts the query to a ServiceNow-interpretable format
          :return:
              - ServiceNow query