- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2016 10:00 AM
Trying to make a UI Action in our custom application that will copy some fields from an existing record into a new record. We have similar UI Actions for Incident and Change that work properly but I can't get this working. I've tried changing the new GlideRecord parameter to various values but so far no luck. My script is included below. Can anyone tell me what I'm doing wrong here or if this has to be handled differently in a scoped application? Thanks.
new GlideRecord('x_kamr_sec_ex_security_exceptions');
new GlideRecord(current);
new GlideRecord('security_exception');
current.update();
var excnew = new GlideRecord('security exception');
excnew.description = current.description;
excnew.short_description = current.short_description;
excnew.update();
action.setRedirectURL(excnew);
Solved! Go to Solution.
- Labels:
-
Scoped App Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2016 11:04 AM
Hi Sharon,
You are close. current refers to the current record you are displaying, so you need to instantiate another record/object of that same type.
var newRec = new GlideRecord(current.getTableName());
the initialize it/set default values:
newRec.newRecord();
Copy the fields you wish
newRec.short_description = current.short_description;
newRec.description = current.description;
// Add additional fields as needed here
Save the new record
newRec.update();
and go to the new record form
action.setRedirectURL(newRec);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2016 11:04 AM
Hi Sharon,
You are close. current refers to the current record you are displaying, so you need to instantiate another record/object of that same type.
var newRec = new GlideRecord(current.getTableName());
the initialize it/set default values:
newRec.newRecord();
Copy the fields you wish
newRec.short_description = current.short_description;
newRec.description = current.description;
// Add additional fields as needed here
Save the new record
newRec.update();
and go to the new record form
action.setRedirectURL(newRec);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2016 12:10 PM
I still don't get a new record. I have an existing exception record open, click on the UI button and it just closes the record and returns to the list. This is the script as I have it now but I've also tried it with the var ecxnew like with the table name like this:
var excnew = new GlideRecord('x_kamr_sec_ex_security_exceptions');
This is the script as I have it now.
var excnew = new GlideRecord(current.getTableName());
excnew.newRecord();
excnew.description = current.description;
excnew.short_description = current.short_description;
excnew.url_or_exe = current.url_or_exe;
excnew.business_reason_for_exception = current.business_reason_for_exception;
excnew.assessment_of_risk = assessment_of_risk;
excnew.exception_type = current.exception_type;
excnew.exception_level = current.exception_level;
excnew.approval_level = current.approval_level;
excnew.update();
action.setRedirectURL(excnew);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2016 12:14 PM
If it is returning to the list, it means the script is hitting an error and not getting to the last action.setRedirectURL() option.
Go to System Logs> Errors or System Logs> Warnings and see if there is anything there. If you don't see anything, start putting gs.log() statements in your script to determine how far it is getting then find them in System Logs> Script Log Statements to investigate where your error may lie.
(FWIW, this will be made much easier when we get our script debugger in an upcoming release!)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2016 01:18 PM
I tried the gs.log suggestion but you get a message that it's not allowed within scoped applications. But it pointed me in the right direction. I found this wiki with a video (that might be yours?)
http://wiki.servicenow.com/index.php?title=Scoped_Script_Logging#gsc.tab=0
I used gs.info which writes to the application logs to pin down the line that was causing the issue.
Success at last. Thanks!