URGENT!! How can I create a multilevel tree view in service portal? At what format should I pass data from server script to html?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 12:40 AM
Hi All,
As per the requirement i need to create a tree view from table/tables which have parent > child1 > child2>.. relationships. (Similar to Assignment group reference field in incident with child extending further)
Is it possible in ServiceNow? I did not see any reference out of the box widget which i can use?
At what format should I pass data from server script to html?
Thanks,
KUMAR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 05:13 PM
There are many ways of doing this. One way to do this is using a recursive function to build the array and then kick off the function for each record to find any children record. This works great for traversing the KB and Catalog categories. There are plenty of other ways of doing this that doesn't initiate a separate GlideRecord for each "level", but this is a pretty simple concept to get you started.
Remember the first function call starts where there is no parent, and then will continue building out the array for any record that has children based on the "parent" field.
data.array = getRecords(null);
function getRecords(parent_id) {
var gr = new GlideRecord('table');
gr.addQuery("parent", parent_id);
gr.query();
var records = [];
while(gr.next()) {
var rec = {}
rec.title = gr.getDisplayValue();
rec.sys_id = gr.getUniqueValue();
rec.children = getRecords(gr.sys_id);
records.push(rec);
}
return records;
}
Hope that helps.
-----------------
Nathan Firth
Founder and ServiceNow Architect
NewRocket, Inc.
nathan.firth@newrocket.com
http://serviceportal.io
http://newrocket.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2019 01:26 AM
Check larstange's answer on the below article.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2019 01:55 AM