Skip to main content

Get user footprint (about to deactivate the user, list their tickets, CIs, approvals...etc)

this will embed the list of items including clickable urls into the activity trail of for example a RITM to deactivate users

call the script include - e.g. from business rule:

var si=new UserFootprint(usersArr[ic]); var sUserFootprint=si.writeLogUserDeactivate(); sMsg+=sUserFootprint;




script include code:

var MOJUserFootprint = Class.create(); MOJUserFootprint.prototype = { initialize: function(userID) { this.usersysid=userID; this.instance_url=gs.getProperty("glide.servlet.uri"); this.usertickets_assigned_url=""; this.usertickets_createdby_url=""; this.userCIs_url=""; this.userapprovals_url=""; this.usergroupmanager_url=""; this.userRITMS_url=""; this.userserviceowner_url=""; this.userreports_url=""; this.userdashboards_url=""; }, moj_writeLogUserDeactivate: function(){ //--this function will return all results, however each function in the sections below may be called separately if desired var sMsg=''; var grUser=new GlideRecord('sys_user'); if (grUser.get('sys_id', this.usersysid)){ sMsg='****RESULTS FOR USER: ' + grUser.name + '; ' + grUser.email + '\n'; //--active tickets-assigned to user: var sURL=''; var sRet=this.moj_getusertickets_assigned(); sMsg+="**TOTAL ACTIVE TICKETS ASSIGNED TO USER: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getusertickets_assigned_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--active tickets-created by user: sRet=this.moj_getusertickets_createdby(); sMsg+="**TOTAL ACTIVE TICKETS CREATED BY USER: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getusertickets_createdby_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--RITM tickets-user is requested for: sRet=this.moj_getuserRITMs_requestedfor(); sMsg+="**TOTAL ACTIVE RITM TICKETS WHERE USER=REQUESTED FOR: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getuserRITMs_requestedfor_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--active CIs assigned to user: sRet=this.moj_getuserCIs_assigned(); sMsg+="**TOTAL CONFIGURATION ITEMS ASSIGNED TO USER: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getuserCIs_assigned_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--active approvals assigned to user: sRet=this.moj_getuserapprovals(); sMsg+="**TOTAL ACTIVE APPROVALS ASSIGNED TO USER: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getuserapprovals_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--active groups where user is manager: sRet=this.moj_getusergroups_usermanager(); sMsg+="**TOTAL ACTIVE GROUPS WHERE USER=MANAGER: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getusergroups_usermanager_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--service offerings where user is owner: sRet=this.moj_getserviceofferings_userowner(); sMsg+="**TOTAL SERVICE OFFERINGS WHERE USER=SERVICE OWNER: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getserviceofferings_userowner_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--reports created by user: sRet=this.moj_getuserreports(); sMsg+="**TOTAL REPORTS CREATED BY USER: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getuserreports_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--dashboards created by user: sRet=this.moj_getuserdashboards(); sMsg+="**TOTAL DASHBOARDS CREATED BY USER: "; sMsg+=sRet; sMsg+='\n'; if (sRet>0){ sURL=this.moj_getuserdashboards_URL(); sMsg+='URL: [code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; } //--user group memberships and any standalone roles: sRet=this.moj_getusergroups(); sMsg+="**SERVICENOW GROUPS THE USER BELONGS TO: "; sMsg+=sRet; sMsg+='\n'; sRet=this.moj_getuserstandaloneroles(); sMsg+="**SERVICENOW STANDALONE ROLES THE USER HAS: "; sMsg+=sRet; sMsg+='\n'; sMsg+='**Link to user record:\n'; sURL=this.instance_url+ "nav_to.do?uri=%2Fsys_user.do%3Fsys_id%3D" + this.usersysid; sMsg+='[code]<a target="_blank" href="' + sURL + '">'; sMsg+=sURL; sMsg+='</a>[/code]'; sMsg+='\n'; //--// sMsg+='***********************************************\n'; sMsg+='***********************************************\n'; } return sMsg; }, //**********START -- TICKETS ASSIGNED TO USER********************* moj_getusertickets_assigned: function() { //--list all tickets assigned to the user var grTask=new GlideRecord('task'); grTask.addActiveQuery(); grTask.addQuery('assigned_to', this.usersysid); grTask.query(); var sTotal=grTask.getRowCount(); var sTotal_refined=0; while (grTask.next()){ if (grTask.getTableName()=='incident'){ if (grTask.state!=6){ sTotal_refined++; } }else{ //--filter out resolved incidents which technically are still active sTotal_refined++; } } this.usertickets_assigned_url=this.instance_url+ "nav_to.do?uri=task_list.do?sysparm_query=active%3Dtrue%5Eassigned_to%3D" + this.usersysid; return sTotal_refined; }, moj_getusertickets_assigned_URL: function() { return (this.usertickets_assigned_url); }, //**********END -- TICKETS ASSIGNED TO USER********************* //**********START -- TICKETS OPENED BY USER********************* moj_getusertickets_createdby: function() { //--list all active tickets raised by the user var grTask=new GlideRecord('task'); grTask.addActiveQuery(); grTask.addQuery('opened_by', this.usersysid); grTask.query(); var sTotal=grTask.getRowCount(); var sTotal_refined=0; while (grTask.next()){ if (grTask.getTableName()=='incident'){ if (grTask.state!=6){ sTotal_refined++; } }else{ //--filter out resolved incidents which technically are still active sTotal_refined++; } } this.usertickets_createdby_url=this.instance_url+ "nav_to.do?uri=task_list.do?sysparm_query=active%3Dtrue%5Eopened_by%3D" + this.usersysid; return sTotal_refined; }, moj_getusertickets_createdby_URL: function() { return (this.usertickets_createdby_url); }, //**********END -- TICKETS OPENED BY USER********************* //**********START -- RITMS REQUESTED FOR USER***************** moj_getuserRITMs_requestedfor: function() { var grRITMs=new GlideRecord('sc_req_item'); grRITMs.addActiveQuery(); grRITMs.addQuery('u_requested_for', this.usersysid); grRITMs.query(); var sTotal=grRITMs.getRowCount(); this.userRITMS_url=this.instance_url+ "nav_to.do?uri=sc_req_item_list.do?sysparm_query=u_requested_for%3D" + this.usersysid; return sTotal; }, moj_getuserRITMs_requestedfor_URL: function() { return (this.userRITMS_url); }, //**********END -- RITMS REQUESTED FOR USER******************* //**********START -- CIs ASSIGNED TO USER********************* moj_getuserCIs_assigned: function() { //--status not in (retired,stolen,absent) var sCIQuery="install_statusNOT IN100,7,8"; var grCI=new GlideRecord('cmdb_ci'); grCI.addQuery(sCIQuery); grCI.addQuery('assigned_to', this.usersysid); grCI.query(); var sTotal=grCI.getRowCount(); /*while (grCI.next()){ }*/ this.userCIs_url=this.instance_url+ "nav_to.do?uri=cmdb_ci_list.do?sysparm_query=install_statusNOT%20IN100%2C7%2C8%5Eassigned_to%3D" + this.usersysid; return sTotal; }, moj_getuserCIs_assigned_URL: function() { return (this.userCIs_url); }, //**********END -- CIs ASSIGNED TO USER********************* //**********START -- APPROVALS ASSIGNED TO USER************* moj_getuserapprovals: function() { var grAppr=new GlideRecord('sysapproval_approver'); grAppr.addQuery('state', 'requested'); grAppr.addQuery('approver',this.usersysid); grAppr.query(); var sTotal=grAppr.getRowCount(); this.userapprovals_url=this.instance_url+ "nav_to.do?uri=sysapproval_approver_list.do?sysparm_query=state%3Drequested%5Eapprover%3D"+this.usersysid; return sTotal; }, moj_getuserapprovals_URL: function() { return (this.userapprovals_url); }, //**********END -- APPROVALS ASSIGNED TO USER************* //**********START -- GROUPS WITH USER AS MANAGER*********** moj_getusergroups_usermanager: function() { var grGrps=new GlideRecord('sys_user_group'); grGrps.addQuery('active', true); grGrps.addQuery('manager', this.usersysid); grGrps.query(); var sTotal=grGrps.getRowCount(); this.usergroupmanager_url=this.instance_url+ "nav_to.do?uri=sys_user_group_list.do?sysparm_query=manager%3D"+ this.usersysid; return sTotal; }, moj_getusergroups_usermanager_URL: function() { return (this.usergroupmanager_url); }, //**********END -- GROUPS WITH USER AS MANAGER************* //**********START -- SERVICE OFFERINGS WITH USER AS OWNER** moj_getserviceofferings_userowner: function() { var grSO=new GlideRecord('service_offering'); grSO.addQuery('install_status', '!=', '7'); //--not retired grSO.addQuery('managed_by', this.usersysid); grSO.query(); var sTotal=grSO.getRowCount(); this.userserviceowner_url=this.instance_url+ "nav_to.do?uri=service_offering_list.do?sysparm_query=install_status!%3D7%5Emanaged_by%3D"+ this.usersysid; return sTotal; }, moj_getserviceofferings_userowner_URL: function() { return (this.userserviceowner_url); }, //**********END -- SERVICE OFFERINGS WITH USER AS OWNER**** //**********START -- REPORTS******************************* moj_getuserreports: function() { var grReports=new GlideRecord('sys_report'); grReports.addQuery('created_by_user', this.usersysid); grReports.query(); var sTotal=grReports.getRowCount(); this.userreports_url=this.instance_url+ "nav_to.do?uri=sys_report_list.do?sysparm_query=created_by_user%3D" + this.usersysid; return sTotal; }, moj_getuserreports_URL: function() { return (this.userreports_url); }, //**********END -- REPORTS********************************* //**********START -- DASHBOARDS**************************** moj_getuserdashboards: function() { var grDashBoards=new GlideRecord('pa_dashboards'); grDashBoards.addQuery('owner', this.usersysid); grDashBoards.query(); var sTotal=grDashBoards.getRowCount(); this.userdashboards_url=this.instance_url+ "nav_to.do?uri=pa_dashboards_list.do?sysparm_query=owner%3D" + this.usersysid; return sTotal; }, moj_getuserdashboards_URL: function() { return (this.userdashboards_url); }, //**********END -- DASHBOARDS******************************* //**********START -- GROUPS USER BELONGS TO***************** moj_getusergroups: function() { var grGroupMem=new GlideRecord('sys_user_grmember'); grGroupMem.addQuery('user', this.usersysid); grGroupMem.query(); var sGroups='0'; if (grGroupMem.getRowCount()>0){ sGroups='\n'; while (grGroupMem.next()){ sGroups+=grGroupMem.group.name; sGroups+='; '; } } return sGroups; }, //**********END -- GROUPS USER BELONGS TO******************* //**********START -- STAND ALONE USER ROLES***************** moj_getuserstandaloneroles: function() { var grUserRoles=new GlideRecord('sys_user_has_role'); grUserRoles.addQuery('inherited', 'false'); grUserRoles.addQuery('user', this.usersysid); grUserRoles.query(); var sStandAloneRoles='0'; if (grUserRoles.getRowCount()>0){ sStandAloneRoles='\n'; while (grUserRoles.next()){ sStandAloneRoles+=grUserRoles.role.name; sStandAloneRoles+='; '; } } return sStandAloneRoles; }, //**********END -- STAND ALONE USER ROLES******************* type: 'MOJUserFootprint' };
};

Comments

  1. Умножайте качественные беклинки на ваш интернет портал и увеличьте трафик, Индекс качества сайта. Разбавьте текущую ссылочную массу, углубляйте беклинки с бирж, пирамида ссылок, tier 1, tier 2, tier 3. Бессмертные ссылки с мега трастовых сайтов на ваш интернет ресурс, дешевле чем на биржах и аналогов на интернет рынке беклинков. https://seobomba.ru/

    ReplyDelete

Post a Comment

Popular posts from this blog

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){...

Code a pause/wait - gs.sleep or gs.wait alternative, pause script for specified seconds (timer)

Code a pause/wait - gs.sleep / gs.wait alternative, pause script for specified seconds (timer)  e.g. 10 seconds: do_sleep ( 10000 ); function do_sleep ( milliseconds ) { var start = new Date (). getTime (); for ( var i = 0 ; i < 1e7 ; i ++) { if (( new Date (). getTime () - start ) > milliseconds ){ gs . print ( 'waking up!' ); break ; } } }