Object.extendsObject
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 01:29 PM
I want to extend the sn_ws.RESTMessageV2 object to create a subclass but am having trouble getting the syntax correct.
This object sn_ws.RESTMessageV2 instantiates either as empty object or populates via a table if passed two parameters.
Do I need to recreate the initialize function as part of the prototype definition or can i just extend the functionality with new calls?
How does one call the parent function from within the child prototype?
super() is not supported...
Nothing I have tried so far seems to work...everything involving calling the parent function methods just comes up undefined.
var ib_message = Class.create();
ib_message.prototype = Object.extendsObject(sn_ws.RESTMessageV2, {
foo: function() {
gs.print('foo b');
},
type: 'ib_message'
});
var end = "https://xxx.xxx.xx.xx";
var record_type="record:a";
var max_records_per_query = 50;
var max_queries = 2;
var fields="extattrs";
var r = new ib_message('Network_Sync', 'get_ib_records');
r.setStringParameter("rest_endpoint",end);
r.setStringParameter("record_type", record_type);
r.setQueryParameter("_paging", 1);
r.setQueryParameter("_return_as_object", 1);
r.setQueryParameter("_max_results", max_records_per_query);
r.setQueryParameter("_return_fields%2B",fields);
r.setEndpoint(end);
gs.print(r.getEndpoint());
var resp = r.execute();
var httpResponseStatus = resp.getStatusCode();
gs.print("http response status_code: " + httpResponseStatus);
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2019 08:10 PM
I'd suggest editing your post by updating the title to get more people to look at it.
Make a good to-the-point title for the question or as stackoverflow says, "Write a title that summarizes the specific problem". This helps because it lets those who can help, know they can without going into the post. You might be thinking, I can't sum it up it's too complex. No problem, try to think how you'd ask a busy colleague, and put that into the subject. If you're still having trouble, write the title last after all the details are fresh.
- Good: Set Value form variable in the request form to Table field
- Good: How to disable attachment confirmations?
- Good: How can I set an override reference qualifier to a group
- Bad: NetApp
- Bad: Photo Masking
- Bad: Not Available for Module script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2019 08:25 PM
I may be wrong about this, but I believe you cannot extend a Java object to a javascript class as you are trying to do, and I am fairly certain that sn_ws.RestMessageV2 is a java object.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2019 08:34 PM
I may be wrong, but I don't think you can extend a java object to a javascript class using extendsObject. and since sn_ws.RestMessageV2 appears to be a java object (like GlideRecord), I don't think you can extend it in that way. But I do think you can add functions to it using prototype. See this blog from Steve Bell for how he extended the GlideRecord object to add a couple new functions to it.
https://community.servicenow.com/community?id=community_blog&sys_id=b96c2ea1dbd0dbc01dcaf3231f9619b9&view_source=searchResult
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 04:00 AM
Hi @Tim71 ,
I have created this easy to follow example where you can inherit from a class using Object.extendsObject() function. just replace the code with a REST-Message function.
You can find more details here: Master Good Software Architecture with Object.extendsObject() | A Guide for ServiceNow Developers