deleteFile()

The deleteFile() function (server-side) deletes a file from the File Cabinet.

Syntax

The deleteFile() function can be called using the file name with its path, the file ID as a string or number, or using an object containing the file information. Use these syntax formats:

  • To delete a file using the file name with the path, use:

                    deleteFile('path/filename.extension')
        .done(callback)
        .fail(callback); 
    
                  
  • To delete a file using the ID as a number or a string, use:

                    deleteFile(internalId)
        .done(callback)
        .fail(callback); 
    
                  
                    deleteFile('internalId')
        .done(callback)
        .fail(callback); 
    
                  
  • To delete a file using an object with the file information, use:

                    deleteFile({
        name: 'path/filename.extension', // name OR id
        id: number, // name OR id
        async: true | false,
        nocheck: true | false
    }).done(callback)
      .fail(callback); 
    
                  

Return Value

When using the deleteFile() function in synchronous mode (async: false), the result is returned directly from the deleteFile() call itself. You can assign the result to a variable and work with it immediately.

When using the function in asynchronous mode, it returns a promise. This promise resolves to an object, which is sent to the callback functions you attach using .done() and .fail().

If the file is successfully deleted, the deleteFile() function returns an object providing the status of the deletion process. The object contains the following information:

              { status: 'OK' } 

            

If there's an error, it returns an error object containing an error name, a code and a description. The error object returned contains the following information:

              {
name: "CPQ-FileCab error",
code: "RCRD_DSNT_EXIST",
message: "That record does not exist. path: path/filename.extension"
} 

            

Parameters

Note:

The required parameter is either name or id. Set only one of them.

The deleteFile() can accept an object as a parameter. The object includes the following properties:

  • name - Specifies the file's name with its path. The file name has the following format:

                    'path/filename.extension' 
    
                  
  • id - Specifies the file internal ID.

  • async - Determines if the request is synchronous or asynchronous. This parameter defaults to true.

  • nocheck - If set to true, this parameter doesn't verify whether the file exists when deleting it using its ID. When deleting more than 20 files by ID, this parameter makes the process faster. However, it won't return an error if the file doesn't exist.

Examples

The following examples show how to use the deleteFile() function.

Deleting a File Using its ID

The following examples show how to delete a file using its ID asynchronously.

              deleteFile(30244).done(function(data) {
    console.log('Done', data);
}); 

            
              deleteFile('30244').done(function(data) {
    console.log('Done', data);
}); 

            
              deleteFile({
    id: '30244'
}).done(function(data) {
    console.log('Done', data);
}); 

            

Deleting a File Using its Name

The following examples show how to delete a file asynchronously using its name as a path.

              deleteFile('NotesFolder/notes.txt').done(function(data) {
    console.log('Done', data);
}); 

            
              deleteFile({
    name: 'NotesFolder/notes.txt'
}).done(function(data) {
    console.log('Done', data);
}); 

            

This example shows how to delete a file synchronously using its name.

              const deletedFile = deleteFile({
    name: 'NotesFolder/notes.txt',
    async: false
});
console.log(deletedFile); 

            

Related Topics

General Notices