Searching the user table for user using custom field

leenathan24
Kilo Contributor

I am creating a form that takes customer information and creates a record from that information. I was originally using a field that was using the AJAXTableCompleter attribute, but for reasons I won't go into that option doesn't work for me. So I need to create a field that runs custom script through a UI policy to search the User table. My initial idea was that I would create a GlideRecord of the sys_user table:

var gr = new GlideRecord("sys_user");

And then use that object to look through the different columns in the user table to see if there is a match with what the user typed into the field. But I'm not sure how to dot-walk from the `gr` object to the appropriate sys_user columns and then iterate through their elements to search for a match. Can I get some guidance on how I should be doing this?

For some further context, I already setup the minimal script I have to run only when the text entered into the field matches a specific pattern, so that part is not a problem. It's just the searching that is the trouble.

Thank you!

6 REPLIES 6

venkatiyer1
Giga Guru

Hi Nathan,



getFields is a good option to loop through the glide Record. It is listed as a method in the following link



GlideRecord - ServiceNow Wiki


I tried to implement some of the code in the example from the link you posted (very helpful by the way), but now my script has a runtime error. Strangely, the error still happens when commenting out that code though; it didn't throw the error before when I just had something minimal, but now it's being thrown regardless.



Error:


onChange script error: TypeError: GlideRecord is not a constructor function (){var o=i(m,arguments);return l.apply(n,o)}


Please post the full code that you are running.  


venkatiyer1
Giga Guru

Hi Nathan,



Hope you are not accessing the GlideRecord directly from an onchange client script. You would need a script include to do that and access it via glideajax.