Get user's sys id from the catalog variable

Manish Singh
Kilo Expert

Hi All,

I have a workflow where I need to capture the sysid of user from the configured variable "term_user" which is referencing to "sys_user" table. If requester specify the user name then

script should capture the user value & get it's sys id.

Condition: If user is active then it should return true else false.

find_real_file.png

I have created the below script but it's always returning "no" as value. Can someone have a look & let me know the reason.

----------------------------------------------------------------------

//Script to check whether user is active or not.

answer = ifScript();

function ifScript() {

var t_user = current.variables.term_user.sys_id;   //term_user is a variable where user is providing the user information

var user = new GlideRecord('sys_user');

user.addQuery(t_user);

user.query();

while (user.next())

        {

                  if (user.active == true)

                            {

                                      answer = 'yes';

                              }

        else

                              {

                                      answer = 'no';

                            }

          }

-----------------------------------------------------------------------------------

Thanks in advance!

Kind regards,

Manish

1 ACCEPTED SOLUTION

Manish Singh
Kilo Expert

Thanks every one, by the below query I am able to get the proper result in workflow.



var t_user = current.variables.term_user;


var gr = new GlideRecord('sys_user');


gr.addQuery('sys_id', t_user);


gr.query();




if (gr.next())


{


if (gr.active == true)


{


answer = true;


}


}


View solution in original post

20 REPLIES 20

Harsh Vardhan
Giga Patron

Hi Manish,



ok do one more thing put log in your script and check if you are able to access the variable or not?


by the way may i know why your workflow has configure in sc_cat_item table? instead of Sc_req_item


It was in sc_cat_item table, now I have to changed it to Sc_req_item.


if still it does not work can you put some log and check if you are able to get the variable value or not?


Also make sure in you catalog item, this workflow is mapped.



Please mark this response as correct or helpful if it assisted you with your question.

Can we try in this way,



var t_user = current.variables.term_user.toString();


gs.log('User' + t_user); //Let's check the log what it captures


var gr = new GlideRecord('sys_user');



if(gr.get('sys_id',t_user)){


                  if (gr.getValue(active) == 'true')                            


                                      return 'yes';


                else


                                      return 'no';                                    


}


return 'no';