The CreatorCon Call for Content is officially open! Get started here.

Can I use GlideRecord in a Service Portal client script

stryker129
Mega Guru

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?

1 ACCEPTED SOLUTION

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();


  }


 


})();


View solution in original post

8 REPLIES 8

Glad it worked. Also notice that the if (input) check makes sure the code doesn't run when the widget loads and creates a blank record.


for sure. understood. thanks.


Brad, quick question here:


It was an empty form for creating a new customer.


Now I need to open this form for existing customer by clicking "edit" button from another SP page (from another widget).


How can I open this page from another one? In other words, I need to pass "customer" object from another widget to the current widget.


Thanks.


You would link to it and pass a url parameter, then your client and server side code would grab the sysid from the url parameter and populate the data object onload in that way.


thanks.


will try.