Add GlideRecord UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:08 AM
Hi all,
I'm trying to add a record to a scoped application when someone clicks on a custom form button. I have used a UI action for this.
The UI action does not save the GlideRecord and when I debug I get following error: "Uncaught TypeError: GlideRecord is not a constructor".
Here's the code I'm using:
function test() {
alert("dfkdf");
var sur = new GlideRecord("x_mytable");
sur.initialize();
sur.state = 2;
var successful = sur.insert();
if (successful.isNewRecord()){
alert('inserted');
}
else {
alert('not_inserted');
}
action.setRedirectURL("www.blabla.be");
}
The aim is to save the record and subsequently redirect the user to the newly created record form to add some more detail.
Best regards,
Kris

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:14 AM
You seem to have a combination of client side (alert) and server side (action.setRedirectURL) code.
Do you happen to have the Client checkbox turned on in your UI action? It doesn't appear that you need it here. If you want some simple debug messages on the server side, use gs.addInfoMessage()
Recommended reading: UI Actions - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 06:47 AM
Thanks Chuck. I have the client indeed activated. Record is not being saved and i cannot redirect the user

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 07:01 AM
This this (caveat: untested) -
Name: Create New Record (adjust as necessary)
Show Insert: true
Show Update: true
Form Button: true
Client: false (unchecked)
Table: (your table name where you want this to appear)
Conditions: (blank for now)
Script:
var sur = new GlideRecord("x_mytable");
sur.newRecord();
sur.state = 2;
if (sur.insert())
gs.addInfoMessage('New record created');
else
gs.addErrorMessage('Error creating new record');
action.setRedirectURL(sur);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 07:02 AM
Updates made: Be sure to check my comments carefully - client is unchecked