GlideQuery queryNoDomain

ColK
Tera Guru

Hi ServiceNow Community!

I am trying to created a GlideRecord query ignoring domain separation using queryNoDomain(), but I get the error, "Submit canceled due to a script error - please contact your System Administrator" when I test the script.

I know the error comes from when queryNoDomain() is called, but I'm stuck on what to do next troubleshooting. Is there a way I can find the code for queryNoDomain? Or is there a way for me to confirm that this method is enabled?

I also was not sure which forum to post this question to (here or DevOps), so if i should remove one of these posts please let me know.

1 ACCEPTED SOLUTION

As you have Client script so queryNoDomain doesn't work on client side. Also, GlideRecord in client script is not a good practice. You should use GlideAjax in client script and write script include to process server side code and in there you can use queryNoDomain(). 

Please Refer GlideAjax doc - https://docs.servicenow.com/bundle/orlando-application-development/page/script/ajax/topic/p_AJAX.htm...

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

View solution in original post

6 REPLIES 6

MrMuhammad
Giga Sage

queryNoDomain() only works in Domain separated environments. Its code is not available publicly but you can read its documentation here queryNoDomain.

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

I am in a domain separated environment and it does not work.

Can you show me the sample of code you are using, if possible? 

Regards,
Muhammad

I am trying to get a specific user in a different domain, by using a given email in a variable called email_manager.

function onSubmit() {
   g_form.clearMessages();

   var domain = new GlideRecord('sys_user');
   console.log("TESTING: 1");       // gets logged
   domain.queryNoDomain();
   console.log("TESTING: 2");       // does not get logged
   
   if (domain.next()) {
      var manager = new GlideRecord('sys_user');
      manager.addQuery('email', g_form.getValue('email_manager'));
      manager.addQuery('active',true);
      manager.addDomainQuery(domain);
      manager.query();

      if (manager.hasNext()) {
         return true;
      }
      else {
         alert("Email error. Please check the previous manager's email.");
         return false;
      }
   }
}