Chalan B L
Giga Guru

scenarios: Need to glide a table, print the records and get into a Excel sheet using a Background script

We definitely come across such requirements often, following the below steps would help

 1) Create a Background script, print a column and rows using a seperator |

dpfracus();
function dpfracus(){
try{
gs.print('Assignment group'+'|'+'User'+'|'+'Has DP Fracas role (Yes/No)'+'|'+'Is DP Fracas revoked (Yes/No)'); //Table Header
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('group.typeLIKE6883ac7b4f385a006ce8bc718110c7b1');
gr.query();
while(gr.next()){

gs.print(gr.group.getDisplayValue() +'|'+gr.user.getDisplayValue()+'|'+userroles1(gr.user)+'|'+revokedroles(gr.user)); //Prints the row using a seperator |
}
}catch(e){
gs.log("Exception Occured :"+e,'>>>BackgroundScript<<<');
}
}
function userroles1(userrole){
var gr1 = new GlideRecord('sys_user_has_role');
gr1.addEncodedQuery('user='+userrole+'^role=31df7d154f41da006ce8bc718110c739');
gr1.query();
if(gr1.next()){
return 'Yes';
}else{
return 'No';
}
}
function revokedroles(userrevoked){

var gr2 = new GlideRecord('u_revoked_roles');
gr2.addEncodedQuery('u_user='+userrevoked+'^u_status=active^u_user_role=DP Fracas');
gr2.query();
if(gr2.next()){
return 'Yes';
}else{
return 'No';
}
}

2) Output

find_real_file.png

3) Copy all the script and paste it in Notepad ++ [remove ***script ] use ctrl+F andcopy the text, replace all

find_real_file.png

4) Now open the excel sheet --> Data - From text

find_real_file.png

 

find_real_file.png

 

find_real_file.png

 

Please mark the blog as helpful and Bookmark..!!!

 

 

Regards,

Chalan

 

 

 

 

 

 

 

Comments
Dianah
Tera Contributor

To use them in Excel:
Open a workbook in Excel.
Open the Automate tab.
Select New Script.
Replace the entire script with the sample of your choice.
Select Run in the Code Editor's task pane.

 

Regards,

Will

Version history
Last update:
‎02-18-2019 10:55 AM
Updated by: