var DSCSQueryBRUtil = Class.create(); DSCSQueryBRUtil.prototype = { TABLE_CONTACT: 'customer_contact', TABLE_ACCOUNT: 'customer_account', TABLE_CS_CASE: 'sn_customerservice_case', TABLE_INTERACTION: 'interaction', TABLE_CSM_CONSUMER: 'csm_consumer', initialize: function () { }, /** * Add an encoded query to the current record to restric the visibility * @param current GlideRecord * @param table string name of the table - optional * @return GlideRecord with added encoded query */ addQueryforAgent: function (current, table) { var tableName = gs.nil(table) ? current.getTableName() : table; var query = this.getQBRConditionQueries(current, tableName); if (!gs.nil(query)) current.addEncodedQuery(query); return current; }, /** * Add an encoded query to the current record to restric the visibility * @param current GlideRecord * @return GlideRecord with added encoded query */ addCaseQueryforAgent: function (current) { return this.addQueryforAgent(current, this.TABLE_CS_CASE); }, /** * Add an encoded query to the current record to restric the visibility * @param current GlideRecord * @return GlideRecord with added encoded query */ addInteractionQueryforAgent: function (current) { return this.addQueryforAgent(current, this.TABLE_INTERACTION); }, /* * QBR queries can be used in each entity's QBR functions based on Conditions */ getQBRConditionQueries: function (current, tableName) { var query = null; var myOpcos = this.getMyOpcos(); if (myOpcos && myOpcos.length > 0) { // Important decision here, if there are NO assignment types on the record, should it be visible to everyone? // query = current.addEncodedQuery('u_assignment_typeIN' + myOpcos.join() + '^ORu_assignment_typeISEMPTY'); query = current.addEncodedQuery('u_assignment_typeIN' + myOpcos.join()); } else { // Important decision here, if an agent is not a member of any Opco, should they see any records? // query = current.addEncodedQuery('u_assignment_typeISEMPTY'); query = current.addEncodedQuery('u_assignment_typeISEMPTY^u_assignment_type!=NULL'); } /* This is a place for more complex logic and exception query variable can be manipulated it is possible to reuse CSQueryBRUtil.getRoleAccessDetails() approach with conditions */ return query; }, /** * Get array of my Opcos * similar to CSQueryBRUtil.getMyCSMRoles * loop through my groups, get all assignment types * list of assignment types that count as "Opco" should be stored as a coma-separated string in a system property * @return array of sys_ids of the assignment types */ getMyOpcos: function () { var key = 'my_csm_opcos_' + gs.getUserID(); var results = gs.getSession().getClientData(key); var dataSeparatedOpcos = gs.getProperty('hohr.csm.data_separated_opcos', '').split(','); gs.log('data separated opcos: ' + dataSeparatedOpcos); if (gs.nil(results) || results == 'NIL') { var myOpcos = []; var allMyGroups = new GlideRecordSecure('sys_user_grmember'); allMyGroups.addQuery('user', gs.getUserID()); allMyGroups.query(); while (allMyGroups.next()) { //var myGroupTypes = allMyGroups.group.type; //coma-separated list of types var myGroupTypes = allMyGroups.group.u_business_group.u_assignment_types; //coma-separated list of types var groupTypeArr = myGroupTypes.split(','); for (var i = 0; i < groupTypeArr.length; i++) { var groupType = groupTypeArr[i]; if (dataSeparatedOpcos.indexOf(groupType) > -1) { // group type we found is data-separated if (myOpcos.indexOf(groupType) == -1) myOpcos.push(groupType); } } } gs.log('opcos: ' + myOpcos); results = (myOpcos.length > 0) ? myOpcos.join(',') : 'NIL'; gs.getSession().putClientData(key, results); } results = (gs.nil(results) || results == 'NIL') ? null : results.split(','); return results; }, type: 'DSCSQueryBRUtil' };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter