How to print array element in vertical patter
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 04:44 AM
Hello All,
we want to print array element in vertical patter.
I am stories CI names in the CIList array, but It gives me list of names in horizontal patter.
I want list of names in the following patter:
1] Name 1 - Sys_id of CI.
2] Name 2 - Sys_id of CI.
3] Name 3 - Sys_id of CI.
4] Name 4 - Sys_id of CI.
var CIList = [];
var gr = new GlideRecord("cmdb_ci");
gr.addQuery('sys_id', '4dff3b34dbe874102f5be8891396195d');
gr.query();
while (gr.next()) {
var grManufacturerName = gr.manufacturer.name;
var grCompany = new GlideRecord("core_company");
grCompany.addQuery('name', grManufacturerName);
grCompany.query();
var grCompanycount = grCompany.getRowCount();
if (grCompany.next()) {
CIList.push(gr.name);
}
}
Thank you
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 04:48 AM
Hello @Sonu Parab
Use below code :-
var CIList = [];
var gr = new GlideRecord("cmdb_ci");
gr.addQuery('sys_id', '4dff3b34dbe874102f5be8891396195d');
gr.query();
while (gr.next()) {
var grManufacturerName = gr.manufacturer.name;
var grCompany = new GlideRecord("core_company");
grCompany.addQuery('name', grManufacturerName);
grCompany.query();
var grCompanycount = grCompany.getRowCount();
if (grCompany.next()) {
CIList.push(gr.name);
}
}
for(var i=0; i<CIList.length; i++){
gs.info(CIList[i]);
}
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Regards,
Samaksh