Get field values from related option list

davidwilhelm-in
Giga Contributor

Hello all,

I have a related list view. I have created a list choice UI Action for this list view.

The related list is the attachments table which includes the table name and the sys_id the attachments are on.

This server side code works fine:

var url = '/' + current.table_name + '.do?sys_id=' + current.table_sys_id + '&sysparm_stack=home.do';

action.setRedirectURL(url);

However, I   need to do a window.open such as this:

window.open(url,"_blank");

In this way, if the user selects more than one attachment record, more than one browser tab open should be created and load the correct form.

Going client I have not been able to come up with a way to capture the field values in the list view. Below are screen shots of my list view, which has the table_name and table_sys_id fields, which are the two fields I need to capture in my client or server side ui action script.

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi David,



If the UI action is list choice then g_list.getChecked() should give you the sys_ids of the record being selected you can then form the URL and do whatever is needed.



for all the sys ids


query the sys_attachment table with table_sys_id for


get the attachment record sys_id and form the URL and use window.open()



var listSysIds = g_list.getChecked().split(",");



for(var i=0; i<listSysIds.length; i++){


var gr = new GlideRecord('sys_attachment');


gr.addQuery('table_sys_id', listSysIds[i]);


gr.query();


if(gr.next()){


window.open('/sys_attachment.do?sys_id=' + gr.sys_id);


}


}



get g_list.getChecked() in server side part of UI action


http://www.snc-blog.com/2012/01/30/verifying-list-view-selection/



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi David,



If the UI action is list choice then g_list.getChecked() should give you the sys_ids of the record being selected you can then form the URL and do whatever is needed.



for all the sys ids


query the sys_attachment table with table_sys_id for


get the attachment record sys_id and form the URL and use window.open()



var listSysIds = g_list.getChecked().split(",");



for(var i=0; i<listSysIds.length; i++){


var gr = new GlideRecord('sys_attachment');


gr.addQuery('table_sys_id', listSysIds[i]);


gr.query();


if(gr.next()){


window.open('/sys_attachment.do?sys_id=' + gr.sys_id);


}


}



get g_list.getChecked() in server side part of UI action


http://www.snc-blog.com/2012/01/30/verifying-list-view-selection/



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I actually did not want to pull values from the attachments table but your example helped me.



I didn't want to have to query the attachments table since the attachments data fields are in the list view. I wanted to pull the values directly from the list like you can a form with g_form. The below works, but do you know if it's possible to pull the table_name and table_sys_id values directly from the list view?



function redirect(){


    var listSysIds = g_list.getChecked().split(",");


    for(var i=0; i<listSysIds.length; i++){


          var gr = new GlideRecord("sys_attachment");


          gr.addQuery('sys_id', listSysIds[i]);


          gr.query();


          if(gr.next()){


                var url = '/' + gr.table_name + '.do?sys_id=' + gr.table_sys_id + '&sysparm_stack=home.do';


                window.open(url);


          }


    }


}