- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:15 AM
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 ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 04:14 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:39 AM
Yes.
Have you checked manually searching for the user using the User Interface? So go to the table and enter =David Faroon in the filter.
Do you get the user that way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:44 AM
yes , there is "David Faroon" .
some times variable value may contains double space like "David Faroon" , so how to query this time?
any suggestions please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:47 AM
You can remove the duplicate spaces using:
var gr = "David Faroon";
gr = gr.trim().replace(/\s+/g,' ')
- Trim removes spaces from start and end.
- replace(/\s+/g,' ') replaces any number of spaces with a single space.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:50 AM
If there are spaces stored in your name field in the database, then you need to find right name and compare.
If you are using a static name "David Faroon" then check in user table find the right name and do the comparison.
If this is going to be dynamic, then from where are you fetching this name? Try to fetch it from the user table only from there as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:50 AM
gr = gr.trim().replace(/\s+/g,' ')
' ' - directing double space?