Name

sn_uibtk_api.Experience

Description

No description available

Script

var Experience = Class.create();
Experience.prototype = Object.extendsObject(BuilderToolkitAPIBase, {
  TABLE: 'sys_ux_page_registry',
  FIELDS: ['root_macroponent', 'admin_panel'],

  /**
   * @param fields {string[]}
   */
  initialize: function(fields) {
      BuilderToolkitAPIBase.prototype.initialize.call(this, this.TABLE, fields || this.FIELDS);
  }, 

  /**
   * @param path {string} the path we are checking 
   */
  checkIfPathInUse: function(path) {
      const pathArray = String(path).split("/");
      const shortenedPathArray = pathArray.length > 1 ? pathArray.slice(0, pathArray.length - 1) : pathArray;
      const existingExperience = this.getRecordsByQuery('', 'path', true);
      while (existingExperience.next()) {
          var existingPath = existingExperience.getValue("path").split("/");
          var shortenedExistingPath = existingPath.length > 1 ? existingPath.slice(0, existingPath.length - 1) : existingPath;
          if (pathArray.join('/') === existingPath.join('/') ||
              (existingPath.length != pathArray.length && (pathArray.join('/') === shortenedExistingPath.join('/') ||
                  shortenedPathArray.join('/') === existingPath.join('/')))) {
              return true;
          }
      }
      return false;
  },

  /**
   * @param name {string} the name of the new experience
   * @param appShellUI {string} the sys_id of the app shell to use
   * @param path {string} the iniital path of the experience (e.g. my/experience)
   * @param homepage {string} the name of the screen that will be the homepage (defaults to home)
   * @param roles {string[]} an array of role sys_ids to be used for the ACL
   */
  create: function(name, appShellUI, path, homepage, roles = null) {
      const appConfigHandler = new AppConfig();
      const appConfigId = appConfigHandler.createRecord({
          name: name,
          landingPath: homepage
      });
      if (!appConfigId) {
          appConfigHandler.deleteRecord({
              sysId: appConfigId
          });
          return false;
      }

      const needsParentApp = appShellUI === BuilderToolkitConstants.WORKSPACE_APP_SHELL_ID || appShellUI === BuilderToolkitConstants.BREADCRUMB_APP_SHELL_ID || appShellUI === BuilderToolkitConstants.UXR_BASE_APP_SHELL_ID;
      const experience = this.createRecord({
          title: name,
          rootMacroponent: appShellUI,
          adminPanel: appConfigId,
          adminPanelTable: appConfigHandler.table,
          path: path,
          parentApp: needsParentApp ? BuilderToolkitConstants.POLARIS_PARENT_APP_ID : null
      });
      if (!experience) {
          appConfigHandler.deleteRecord({
              sysId: appConfigId
          });
          this.deleteRecord({
              sysId: experience
          });
          return false;
      }

      const appACLPath = path.replaceAll("/", ".");
      const companyCode = gs.getProperty("glide.appcreator.company.code");
      let companyCodePrefix = "now";
      if (!gs.getSession().getCurrentApplicationId().equals("global") && companyCode != "snc" && companyCode) {
          companyCodePrefix = "x." + companyCode;
      }
      const aclName = companyCodePrefix + "." + appACLPath + ".*";
      gs.eventQueue('sn_uibtk_api.create.experience.acl', this.getRecordById(experience, true), this.getUserUpdateSetId(), JSON.stringify({
          aclName: aclName,
          roles: roles ? String(roles)?.split(',') : []
      }));

      return experience;
  },

  /**
   * @param aclName {string} the name of the ACL to use based on experience URL
   * @param roles {string[]} list of role sys_ids to create ACL role records for
   * @param scope {string} the sys_id of the scope to create the records in
   */
  createACL: function(aclName, roles = [], scope) {
      const globalHandler = new global.BuilderToolkitAPIGlobal();
      const newACLId = globalHandler.createGlobalRecord('sys_security_acl', {
          operation: 'read',
          type: BuilderToolkitConstants.UX_ROUTE_ACL_TYPE_ID,
          name: aclName,
          sys_scope: scope
      });
      if (roles.length > 0) {
          roles.forEach(role => {
              globalHandler.createGlobalRecord('sys_security_acl_role', {
                  sys_security_acl: newACLId,
                  sys_user_role: role,
                  sys_scope: scope
              });
          });

          // If we have user provided roles we need to check for and delete the auto-generated role for snc_internal
          // This ensures that only the roles the user gave us are allowed
          const internalACL = new GlideRecordSecure('sys_security_acl_role');
          internalACL.addQuery('sys_security_acl', newACLId);
          internalACL.addQuery('sys_user_role', BuilderToolkitConstants.ACL_INTERNAL_ROLE_ID);
          internalACL.query();
          if (internalACL.next()) {
              globalHandler.deleteGlobalRecord('sys_security_acl_role', internalACL.getUniqueValue());
          }
      }
  },

  type: 'Experience'
});

Sys ID

2cf577f89d231110f8772de6b52d4d8b

Offical Documentation

Official Docs: