Dynamic report title for reports

Akhilkumar2
Mega Contributor

Hi all,

i have some reports which need dynamic title.

i have the code to do it. but it is very long and not that efficient.

 

ar a = new GlideRecord('sys_report');
a.get('9d2afa8affaec3');
a.title = 'Monthly Request KPI by OE - Summary for '+getMonth();
a.update();

var b = new GlideRecord('sys_report');
b.get('3D756e18aad1effaef1');
b.title = 'Monthly Request KPI by OE - Summary for '+getMonth();
b.update();

var c = new GlideRecord('sys_report');
c.get('466991ae71fedb6b52be');
c.title = 'Monthly Request SLA- Service Family for '+getMonth();
c.update();

var d = new GlideRecord('sys_report');
d.get('3Ddc3ef28e6d7edb8056e18aad1effaeae');
d.title = 'Monthly Request SLA - Summary'+getMonth();
d.update();

var e = new GlideRecord('sys_report');
e.get('3D0be6484cc85ebb5e8bc');
e.title= 'Monthly Request KPI by Provider-Summary for'+getMonth();
e.update();
var f = new GlideRecord('sys_report');
f.get('3D69ab37cba52ebb5e852');
f.title= 'Breached CTASKS by Assignment Group - Summary'+getMonth();
f.update();

var g = new GlideRecord('sys_report');
g.get('3Daa7936b3c8c75700547cba52ebb5e862');
g.title= 'All CTASK by Service Family for'+getMonth();
g.update();

function getMonth() {
var monthNames = ',December,January,February,March,April,May,June,July,August,September,October,November'.split(',');
var gdt = new GlideDateTime();
var month=(monthNames[new GlideDate().getMonthLocalTime()]+":"+gdt.getYear());
return month;


}

 

Any one know how to short this using loops or something..

please post answer if you know..

 

1 ACCEPTED SOLUTION

VigneshMC
Mega Sage

No problem, Mark the correct answer and close this thread.

Thanks

View solution in original post

5 REPLIES 5

Bhagyashree8
Kilo Guru

Hi,

Make array of object which contains sys_id and title then iterate over that array like below.

//add as many objects you want.
var Arr = [{
sys_id : 'gfagsagagetge', //update with your id
title : 'Monthly Request KPI by OE - Summary for '+ getMonth();
},{
sys_id : 'fsagdsahgdhgdsahsh', //update with your id
title : '2nd report title '+ getMonth();
}];

Arr.forEach(function(item){
var a = new GlideRecord('sys_report');
a.get(item.sys_id);
a.title = item.title;
a.update();
})

 

Mark my ANSWER as CORRECT / HELPFUL if it served your purpose.

Akhilkumar2
Mega Contributor

this code contains lots of error

 

find_real_file.png

Try below, month will be a numeric value, you will have to add an script to print as alphabetical one.

var gdt = new GlideDateTime(); 
var month = gdt.getMonth();

var Arr = [{
sys_id : 'gfagsagagetge', //update with your id
title : 'Monthly Request KPI by OE - Summary for '+ month
},{
sys_id : 'fsagdsahgdhgdsahsh', //update with your id
title : '2nd report title '+ month
}];

Arr.forEach(function(item){
var a = new GlideRecord('sys_report');
a.get(item.sys_id);
a.title = item.title;
a.update();
});

Thanks

Akhilkumar2
Mega Contributor

thanks vigneesh .. this works.

i changed the script a little to get month in aphabets

 


var monthNames = ',December,January,February,March,April,May,June,July,August,September,October,November'.split(',');
var gdt = new GlideDateTime();
var month=(monthNames[new GlideDate().getMonthLocalTime()]+":"+gdt.getYear());

var Arr = [{
sys_id : '1630026eb6512a2dc34d3', //update with your id
title : 'Monthly Request KPI by OE - Summary for '+ month
},{
sys_id : '46f1481cc7ccf9763d3', //update with your id
title : '2nd report title '+ month
}];
Arr.forEach(function(item){
var a = new GlideRecord('sys_report');
a.get(item.sys_id);
a.title = item.title;
a.update();
});