- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 04:06 PM
Hello Everyone
I am retrieving records from a table using REST API feature in servicenow. I selected columns in the query parameter (sysparm_fields) in a particular order . But while the API is being formed at the backend , the columns get re-ordered . How do i retain the native ordering of columns ?
Thanks for the help in advance !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 06:51 PM
Please see this stack overflow response. ServiceNow has not adopted ES2015 yet so the relevant part is:
As a note, properties order in objects weren’t guaranteed at all before ES2015.
It is likely easier if you do not need to worry about the keys order, but if you must you can do something similar to what you need when iterating over the results though:
var keys = ["key_1", "key_2", "key_3"]
// run the query to retrieve the results. function not implemented here for simplicity.
// sysparm_fields would be set to keys.join();
var results = GetResults(keys);
results.forEach(function(record) {
keys.forEach(function(k) {
// K is now the first key you want
var value = record[k];
//... Do what you want here
});
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 06:51 PM
Please see this stack overflow response. ServiceNow has not adopted ES2015 yet so the relevant part is:
As a note, properties order in objects weren’t guaranteed at all before ES2015.
It is likely easier if you do not need to worry about the keys order, but if you must you can do something similar to what you need when iterating over the results though:
var keys = ["key_1", "key_2", "key_3"]
// run the query to retrieve the results. function not implemented here for simplicity.
// sysparm_fields would be set to keys.join();
var results = GetResults(keys);
results.forEach(function(record) {
keys.forEach(function(k) {
// K is now the first key you want
var value = record[k];
//... Do what you want here
});
});