URGENT!! How can I create a multilevel tree view in service portal? At what format should I pass data from server script to html?

ashwanikumar
Tera Expert

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

 

3 REPLIES 3

nathanfirth
Tera Guru

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.

Community Alums
Not applicable

Varsha Jadhav1
Giga Expert

Hi ashwanikumar,

yes you can pass data from server script to html.

find below attachment