Type parameters

Hierarchy

Properties

Readonly code

code: string

App code of the URL’s target (the app’s code).

Readonly data

data: Based<Partial<UserData>>

Values of object’s fields.

Readonly fields

fields: Readonly<object>

Description of the object’s fields.

Readonly id

id: string

ID of the URL’s target.

Readonly namespace

namespace: string

Namespace of the URL target (the code of the workspace that the app belongs to).

Readonly timezone

timezone: TTimezone

Time zone with time offset in hours.

If the user’s time zone is not defined, the system uses the company’s time zone. Example:

const currentUser = await System.users. getCurrentUser();
const userTimezone = currentUser.timezone; 

Methods

assignToPosition

  • The method allows you to assign a position to a user.

    After you use this method, you need to save the user object.

    Parameters

    Returns void

block

  • block(): Promise<void>
  • The method locks a user’s account.

    await Context.data.user.block();
    

    Returns Promise<void>

fetch

getChiefs

  • The method retrieves all superiors of a user.

    This method defines all the superiors of a user based on the organizational chart. The first position above the user’s position in the organizational chart tree will be considered the user’s superior. If the user does not have a position in the org chart, the method will return an empty list. If the user is in the root of the org chart tree, the method will return this user.

    const chiefs = await Context.data.__createdBy.getChiefs();
    Context.data.approver = chiefs[0]; 
    

    Returns Promise<UserItemRef[]>

getLocale

  • getLocale(): Promise<string>
  • The method returns a user’s locale.

    A locale code has two parts divided by a hyphen: *Two- or three-charater IETF code of the language. *Region code (ISO 3166-1), which is usually the two-charater code of the country. Examples:

    • de-DE: German (Germany).
    • en-US: English (United States).
      const currentUser = await  System.users.getCurrentUser();
      const userLocale = await currentUser. getLocale(); 
      if (userLocale.startsWith('de-')) { 
      Context.data.message =  'Hallo Welt!'; 
      } else if (userLocale.startsWith('es-')) { 
       Context.data.message = 'Hola mundo!'; 
      } else { 
      Context.data.message =  'Hello world!'; 
      } 
      

    Returns Promise<string>

    A locale as a string.

normalize

  • normalize(): void
  • Delete duplicate data in arrays.

    The method deletes duplicates in fields that store arrays of links to system objects (users, files, app items, or documents). For example, you can call this method after bulk editing data within an object.

    const  app1 = await Context.data.app1.fetch();
    const app2 = await Context.data.app2 .fetch(); 
    app1.data.executors.push(app2.data.executors); 
    app1.normalize();  
    // Now we need to go over the elements in the new array 
    app1.data.executors .forEach( ... ); 
    

    Returns void

positions

  • The method allows you to retrieve the list of positions that a user is assigned to.

    const currentUser = await System.users.getCurrentUser();
    const  positions = await currentUser.positions(); 
    

    Returns Promise<OrganisationStructureItem[]>

removeFromPosition

  • The method allows you to remove a user from a position.

    After you use this method, you need to save the user object.

    Parameters

    Returns void

save

  • save(): Promise<void>
  • The method saves the user object.

    This method allows you to update the current user and invite new users
    Editable fields: fullname, mobilePhone, workPhone, birthDate, hireDate, avatar, timezone, accounts, displayedPosition, and additionalData. If you’re inviting a new user, you have to fill out the email field. Updating:

        const user = await Context.data .user.fetch();
        const timezones = System.timezones.all().filter(  timezone => timezone.name === 'Africa/Bujumbura' ) 
        user.data.timezone =  timezones[0].name; 
        user.data.mobilePhone!.tel = '9655555555'; 
         user.data.fullname!.firstname = 'Peter'; 
        await user.save(); 
    

    To send an invitation, you need to initialize the new user:

         const user = System.users.create();
        user.data.email = 'example@example. com'; 
        user.data.fullname = { 
            lastname: 'Robertson', 
             firstname: 'Jack', 
            middlename: 'Thomas' 
        } 
        await user. save(); 
    

    Returns Promise<void>

setLocale

  • setLocale(locale: string): Promise<void>
  • The method allows changing a user’s locale (language).

    As the locale argument, the locale code is passed, which consists of two parts separated by a hyphen:

    • The two- or three-character IETF language code.
    • The region code (ISO 3166-1), typically a two-character country code. Examples:
    • en-US is the locale for the English language in the USA.
    • es-ES is the locale for the Spanish language in Spain. If the locale passed to the method is not among those available in the company, the operation will terminate with an error.
      // Get the new user  locale from the context 
      const locale = Context.data.new_locale; 
      if  (!locale) { 
        throw new Error('New user locale is not specified'); 
      } 
      //  Get the current user 
      const user = await System.users.getCurrentUser(); 
      //  Change the user's locale 
      await user.setLocale(locale); 
      

    Parameters

    • locale: string

    Returns Promise<void>

setPositions

  • The method sets a list of positions the user is assigned.

    The positions previously configured for this user will be lost. After you use this method, you need to save the user object.

    Parameters

    Returns void

unblock

  • unblock(): Promise<void>
  • The method unlocks a user’s account.

    await Context.data.user.unblock();
    

    Returns Promise<void>