Copy existing records as new records via UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2016 12:17 PM
I am attempting to create a UI Action that will take the records off of a custom table I have created and if they meet criteria create new records as a copy of the ones that qualified.
I have a complicated switch statement to determine the date that I want to search against but I'm sure that is working properly from other client scripts that I have using that so will skip past determining that in my code. That date variable is called CopyFromDate
....
var userName = g_user.userName; //currently logged in user
var target = new GlideRecord('time_card'); //looking on the time card table
target.addQuery('week_starts_on',CopyFromDate); //only wanting to copy records whose week_starts_on (date) is the same as CopyFromDate (date)
target.addQuery('user',userName); //only wanting to copy records where the user is the currently logged in user
target.query();
while (target.next())
{
var copied= new GlideRecord('time_card');
copied.initialize();
copied.u_work_type = target.u_work_type;
copied.u_application = target.u_application;
copied.u_project = target.u_project;
copied.user = target.user;
copied.state = 'Pending';
copied.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2016 06:29 AM
current.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2016 06:48 AM
I added that to my script (and to the post above). Clearly that is necessary and a good catch (thank you!). However, even with that necessary addition I am still getting the message that no records are selected.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2016 07:03 AM
I'd be carefully using the variable name "current" as that is typically a system reserved name and may be causing issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2016 07:09 AM
That's actually a really good point. However, I updated my script (and to the post above) with 'copied' instead of 'current' and am still getting 'No records selected'.