- 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:23 AM
Hi,
Also just check if resource_plan has any other fields which are mandatory as your are not assigning any other values in your code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:21 AM
I would change the order a bit.
Can you try it like this:
var userName = "David Faroon"
var usergr = new GlideRecord('sys_user');
usergr.addQuery('name', userName);
usergr.query();
if (usergr.next()) {
var rp = new GlideRecord('resource_plan');
rp.initialize();
rp.user_resource = usergr.getUniqueValue();
rp.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:26 AM
sure, once RP created by script. Resource Manager will fill all these details.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 03:30 AM
There is a business rule: Check For Resource Based on Type that will abort the action/insert unless all mandat fields are filled.