Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to query user name

Sironi
Kilo Sage

Hi,

Some one help me in GlideQuery.

var gr= "David Faroon"

var rp = new GlideRecord('resource_plan');
rp.initialize();
var usergr = new GlideRecord('sys_user');
usergr.addQuery('name', gr);
usergr.query();
if (usergr.next()) {
rp.user_resource = usergr.sys_id;
}
rp.insert();

 

is it right way to compare name with User table, if yes then ResourcePlan not created . any suggestions ?

1 ACCEPTED SOLUTION

okay.

So try it like this.

 

var gr = "David   Faroon";
gr = gr.trim().replace(/\s+/g,' ');
var rp = new GlideRecord('resource_plan');
rp.initialize();
var usergr = new GlideRecord('sys_user');
usergr.addQuery('name',gr);
usergr.query();
  if (usergr.next()) {
    gs.info("Entered into your if condition");
    rp.user_resource = usergr.getValue("sys_id");
  }
rp.setWorkflow(false);
rp.insert();

View solution in original post

32 REPLIES 32

' ' is one space. So this script replaces any number of spaces '    ' with one space ' '.

Hi,

 

Could see many suggestions & comments but I would still recommend you to instead of applying permutations & different combinations try looking for a unique identifier for comparison.

Willem
Giga Sage
Giga Sage

@Sironi Is my script not working for you?