- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 06:40 AM
This is a part of this question:
So I have a custom form in a widget (Service Portal page).
By submitting I'd like to store all the data to my table.
Firebug says that gr.insert() is not defined:
$('#submit').click(function(){
var gr1 = new GlideRecord('x_11234_notes_customers');
gr1.initialize();
gr1.name = 'first to do item';
gr1.list_of_services = 'learn about GlideRecord';
gr1.insert();
});
Where am I wrong here?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 08:54 AM
Hi Ivan,
What it's doing now is running your insert when the page loads. When you run the update the data object gets passed back to the server as the input object, so try this in your server side script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if (input) {
var gr = new GlideRecord('x_1111_customers');
gr.initialize();
gr.name = input.name;
gr.list_of_services = input.list_of_services;
gr.insert();
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 06:51 AM
You'll need to put the GlideRecord update in the server script part of the widget, and then call that from the client side. This article describes how you can use this.server.get() or this.server.update().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 08:46 AM
HTML:
<button type="button" id="submit" ng-click="c.submitCustomerForm();" name="submit" class="btn btn-primary pull-left">Submit Form</button>
Client Script:
function() {
/* widget controller */
var c = this;
$('ul.panel-tabs a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
c.submitCustomerForm = function(){
c.data.name = 'first to do item';
c.data.list_of_services = 'learn about GlideRecord';
c.server.update().then(function(){
console.log("response from Server");
c.data.name = "";
c.data.list_of_services = "";
})
};
}
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var gr = new GlideRecord('x_1111_customers');
gr.initialize();
gr.name = data.name;
gr.list_of_services = data.list_of_services;
gr.insert();
})();
It creates a new record in 'x_1111_customers' table, but 'name' and 'list_of_services' fields are empty.
Why?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 08:54 AM
Hi Ivan,
What it's doing now is running your insert when the page loads. When you run the update the data object gets passed back to the server as the input object, so try this in your server side script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if (input) {
var gr = new GlideRecord('x_1111_customers');
gr.initialize();
gr.name = input.name;
gr.list_of_services = input.list_of_services;
gr.insert();
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 09:04 AM
Thanks a lot!
I've tried it before but with
gr.name = data.name;
instead of using
gr.name = input.name;
Thanks again.