To create a substitution, use the System.replacements.create method.
After specifying substitution details, you need to save the substitution by calling the ReplacementItem.save mehtod.

// Let's create  a substitution for an employee who is going on holiday 
const rpl = System. replacements.create(); 
rpl.data.type = rpl.fields.type.variants.reassign;  
rpl.data.absent = Context.data.__createdBy; 
rpl.data.replacement = Context. data.substitution; 
rpl.data.begin = Context.data.vacation_start;  
rpl.data.end = Context.data.vacation_end; 
await rpl.save(); 

Type parameters

Hierarchy

Properties

Readonly code

code: string

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

Readonly data

data: Based<Partial<ReplacementData>>

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).

Methods

delete

  • delete(): Promise<void>
  • The method allows you to delete a substitution that hasn’t become active.

    const rpl = await System.replacements.search().where(f => f. absent.eq(Context.data.user!)).first();
    if(rpl != undefined) { 
    await rpl. delete(); 
    } 
    

    Returns Promise<void>

fetch

interrupt

  • interrupt(): Promise<void>
  • The method allows you to interrupt a substitution of a user.

    const rpl = await System.replacements.search().where(f => f. absent.eq(Context.data.user!)).first();
    if(rpl != undefined) { 
    await rpl. interrupt(); 
    } 
    

    Returns Promise<void>

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

save

  • save(): Promise<void>
  • Save a substitution.

    Returns Promise<void>