- 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 04:02 AM
user name fetching from another table. that table field is string field. sales team will enter the user name. but some times there is a change to add double space in name while entering name by mistakenly .
so while coming to script to compare that name with user table. first need to remove that double space, add single space only and compare name, create Resource Plan.

- 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 04:22 AM
could you please help me what is different between
.replace(/\s\s/g,' ');
.replace(/\s+/g,' ');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 04:24 AM
\s\s we are checking for double space and replacing with single space.
your 2nd one replacing single space again with single space 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 04:26 AM
Correct is:
.replace(/\s\s/g,' '); Replaces exactly 2 spaces with 1.
.replace(/\s+/g,' '); Replaces 1 or more spaces with 1 space. So could be triple space or quadruple or any number of spaces and will replace it with 1.