to compare variable field data present in user table

kaushalya1
Kilo Expert

I have created variable field type as Reference and mapped to Custom table.

Now   i want it to compare with user table (name field), whether the name is present or not.

please share if you have business script

Thanks in Advance

Kavya

6 REPLIES 6

Chuck Tomasi
Tera Patron

Hi,



I'm assuming this is in a catalog item somewhere. You can use a business rule to compare it quite easily. I'm going to assume your table is called u_table with a field called name, and your variable is 'user'. Adjust accordingly.



var gr = new GlideRecord('sys_user');


if (gr.get('name', current.variables.user))
        // You have a match


else


        // no person found in sys_user with that name




You will obviously want better logic than my comments.


Hi Chuck,



Thanks.


i want it to compare variable.authroiser field(from u_authoriser table)   with Name field in sys_user table.


if it matches only, it should go for approval.




Kavya


Hi Kavya,



The above solution will work for you then (with the proper name adjustments).



var gr = new GlideRecord('sys_user');


if (gr.get('name', current.variables.u_authoriser))
        // You have a match


else


        // no person found in sys_user with that name



However, I recommend you rethink your comparison. Names have uniqueness issues. I could have a name "Charles" in one table and "Chuck" in another. There could be two "Chuck Tomasi" records in sys_user. You may want to look at comparing something like an email address or employee ID. I'm not sure what you have on the u_authoriser table, but it is worth thinking about from an architectural perspective.


Hi Kaushalya,



I am with Chuck on this one. It is best to filter out records based on email_id field.


Also to add you can fetch variables on catalog item as


current.variables.VARIABLENAME; //Display the sys_id for reference fields.


current.variables.VARIABLENAME.getDisplayValue(); //Gives the display name for reference field types.



Here replace VARIABLENAME with the exact name of the variables. Please refer below link for more info on GlideRecord


Business Rules - ServiceNow Wiki