"addQuery" not working correctly with space

anirban300
Kilo Guru

Hi everyone,

 

I have written the following script include but it is not going inside the user table query. It is not able to query the space in the name. Can someone help me?

 

SCRIPT:
 
  var item = new GlideRecord('sc_req_item');
       item.addEncodedQuery('closed_atRELATIVEGT@dayofweek@ago@4^closed_atRELATIVELT@dayofweek@ago@3^state=3^stage=complete^cat_item=65db9bd9870f1110372587b6cebb356b'); //Catalog Item is "Creation of Login (AD) account for contractor", state is close complete, stage is completed and closed before 3 days ago & closed after 4 days ago
 
item.addEncodedQuery('cat_item.nameSTARTSWITHCreation of Login (AD) account for contractor^numberSTARTSWITHRITM2075329');
        item.query();
        while (item.next()) {
             var name = item.variables.userfirstname.getDisplayValue() + " " + item.variables.prefix.getDisplayValue() + " " + item.variables.userlastname.getDisplayValue();
 
            var userz = new GlideRecord('sys_user');
            userz.addQuery('name',name);
            userz.query();
            if (userz.next()) {
               gs.print('inside');
                //userz.company = company;
                //userz.update();
            }
    }
1 ACCEPTED SOLUTION

Manmohan K
Tera Sage

Hi @anirban300 

 

Please reverify below line's working- it may be providing name which does not match with name in User table. This can be due to incorrect formatting or wrong backend names of variables

 

var name = item.variables.userfirstname.getDisplayValue() + " " + item.variables.prefix.getDisplayValue() + " " + item.variables.userlastname.getDisplayValue();

 

View solution in original post

3 REPLIES 3

Manmohan K
Tera Sage

Hi @anirban300 

 

Please reverify below line's working- it may be providing name which does not match with name in User table. This can be due to incorrect formatting or wrong backend names of variables

 

var name = item.variables.userfirstname.getDisplayValue() + " " + item.variables.prefix.getDisplayValue() + " " + item.variables.userlastname.getDisplayValue();

 

Hi Manmohan,

 

Thank you for you reply. The name is exactly similar. e.g. Ricky Martin but the query is not able to query it.

 

var name = item.variables.userfirstname.getDisplayValue() + " " + item.variables.prefix.getDisplayValue() + " " + item.variables.userlastname.getDisplayValue();
 
            var userz = new GlideRecord('sys_user');
            userz.addQuery('name',name);
            userz.query();
            if (userz.next()) {
               gs.print('inside');
                //userz.company = company;
                //userz.update();
            }

Hi,

You say Ricky Martin as an example but we see Prefix as well being used.

Also, are you sure about the spaces as well in between?