Name

sn_cd.cd_MobileUtils

Description

No description available

Script

var cd_MobileUtils = Class.create();
cd_MobileUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

  /*
   * Returns a list of sys ids for all the active mobile contents of type mobile banner for the current user
   */
  getMobileBannerContentSysIDs: function() {
      var contentType = 'ff192345b7633300264c2575de11a9b3';
      return this._getMobileContentSysIDs(contentType);
  },

  /*
   Function to retrive all content records
  */
  getContentSysIDs: function() {
      return this._getMobileContentSysIDs();
  },

  /*
   Function to retrive all content records or record content of specific type
  */
  _getMobileContentSysIDs: function(contentType) {
      var cd_Audience = new sn_cd.cd_Audience();
      var gdtNow = new GlideDateTime();
      var user = gs.getUserID();

      var grContentVisibility = new GlideRecord('sn_cd_content_visibility');
      grContentVisibility.addActiveQuery();
      grContentVisibility.addQuery('content.active', true);
      if (!gs.nil(contentType))
          grContentVisibility.addQuery('content.content_type', contentType);
      grContentVisibility.addQuery('content.sys_class_name', 'INSTANCEOF', 'sn_cd_content_mobile');
      grContentVisibility.addNullQuery('approvers').addOrCondition('state', 'published');
      grContentVisibility.addNullQuery('availability_start_date').addOrCondition('availability_start_date', '<=', gdtNow);
      grContentVisibility.addNullQuery('availability_end_date').addOrCondition('availability_end_date', '>=', gdtNow);
      grContentVisibility.query();

      var sysIds = [];
      while (grContentVisibility.next())
          if ((grContentVisibility.getValue('use_adhoc_users') == true && grContentVisibility.getValue('users').indexOf(user) != -1) || (grContentVisibility.getValue('use_adhoc_users') != true && cd_Audience.isUserInAudience(grContentVisibility.getValue("audience"), user)))
              sysIds.push(grContentVisibility.getValue("content"));
      return sysIds;
  },

  //checking that onboarding should only be visible if onboarding plugin is install
  getMobileApps: function() {
      var mobileApps = [];
      var ONBOARDING_APP_ID = "87f812cd73b033005788e1e54cf6a719";
      var REQUESTOR_APP_ID = "6fb6c08187403300e0ef0cf888cb0b19";

      var pluginManager = new GlidePluginManager();
      var appIds = [];
      //Requestor app should be always supported
      appIds.push(REQUESTOR_APP_ID);
      //checking whether the onboarding plugin is install or not
      if (pluginManager.isActive('com.sn_hr_onboarding'))
          appIds.push(ONBOARDING_APP_ID);

      return 'sys_idIN' + appIds.join(',');
  },




  /* @param current - current notification glideRecord object.
   @return - the list of sys ids for all the applet launcher in a particular native mobile app
  */
  getAppletLauncherSysIDs: function(current) {
      var appletLaunchers = [];
      if (!gs.nil(current.mobile_app) && !gs.nil(current.mobile_app.navigation)) {
          var navigation_id = current.mobile_app.navigation;
          var gr = new GlideRecord('sys_sg_navigation_tab_map');
          gr.addQuery('navigation', navigation_id);
          gr.addQuery('navigation_tab.sys_class_name', '=', 'sys_sg_applet_launcher_tab');
          gr.query();
          while (gr.next())
              appletLaunchers.push(gr.navigation_tab.applet_launcher.sys_id);
      }
      return 'sys_idIN' + appletLaunchers.join(',');
  },
  /*
   * Returns true if the url parameter is an absolute url otherwise it returns false for relative urls.
   */
  isAbsoluteUrl: function(url) {
      var pattern = new RegExp('^(?:[a-z]+:)?//', 'i');
      return pattern.test(url);
  },
  
  /* Get the delegated assignments for a user
  	@param config - Object - Object describing delegation records to retrieve
  		{
  			@param tables - Array - (optional) - The tables to get delegated records from
  			@param start_date - String - (optional) - Get delegate records at or after this date
  			@param encoded_query - String - (optional) - The condition to filter delegated records
  			@param limit - Number - (optional) - The maximum number of records to get
  		}
  	@param userId - String - (optional) - The user to get delegated records for
  	@param includeUsersRecords - boolean (optional) - Include the users assigned records as well as delegated records
  	@return Array - An array of delegated record sys_id's
  */
  getDelegatedTasks: function (config, userId, includeUserRecords) {
  	var delegatedRecords = [];

  	if (!GlidePluginManager().isActive('com.glide.granular_service_delegation'))
  		return delegatedRecords;

  	if (!userId)
  		userId = gs.getUserID();
  	
  	var grTasks = new sn_delegation.DelegationUtil().getDelegatedAssignmentsForUser(userId, !!includeUserRecords, config);
  	while (grTasks.next())
  		delegatedRecords.push(grTasks.getUniqueValue());
  	
  	return delegatedRecords;
  },

  /*
  * Returns the list of sys_ids of Mobile Content records of type "Mobile Banner" without images.
  */
  getBannersWithoutImage: function() {
  	var sysIds = [];
  	var sysId;
  	var gr = new GlideRecordSecure(cd_CommonConstants.CONTENT_TABLE_MOBILE);
  	gr.addQuery("content_type", cd_CommonConstants.CONTENT_TYPE_MOBILE_BANNER);
  	gr.query();
  	while(gr.next()) {
  		sysId = gr.getValue("sys_id");
  		if(!this._hasAttachment(sysId))
  			sysIds.push(gr.getValue("sys_id"));
  	}
  	return sysIds;
  },

  /*
  * Returns the list of sys_ids of Mobile Content records of type "Mobile Banner" with images.
  */
  getBannersWithImage: function() {
  	var sysIds = [];
  	var sysId;
  	var gr = new GlideRecordSecure(cd_CommonConstants.CONTENT_TABLE_MOBILE);
  	gr.addQuery("content_type", cd_CommonConstants.CONTENT_TYPE_MOBILE_BANNER);
  	gr.query();
  	while(gr.next()) {
  		sysId = gr.getValue("sys_id");
  		if(this._hasAttachment(sysId))
  			sysIds.push(sysId);
  	}
  	return sysIds;
  },

  _hasAttachment: function(sysId) {
  	var gr = new GlideRecordSecure("sys_attachment");
  	gr.addQuery("table_name", "ZZ_YYsn_cd_content_mobile");
  	gr.addQuery("table_sys_id", sysId);
  	gr.setLimit(1);
  	gr.query();
  	return gr.hasNext();
  },

  type: 'cd_MobileUtils'
});

Sys ID

317f3ac8c7100010264cc943c7c2605a

Offical Documentation

Official Docs: