PDFsuite Custom Forms Workflow

Handle Document Tasks

This script allows you to have PDFsuite create document tasks on a custom table rather than the PDFsuite Document Task table [x_uxs_pdfsuitedoc_document_task].

The script serves two functions, creating task records and closing them. This will be denoted by the action variable, which will be one of the following values:

  • 'CREATE' - Creating a document task record
  • 'CLOSE' - Closing a document task record

When the action is 'CREATE' the following variables are provided:

  • current - A GlideRecord for the current record.
  • form - The current UXform.
  • user - The user to assign the document task to.
  • group - The group to assign the document task to
  • description - A description of the document task.
  • shortDescription - A brief description of the document task.

When action is 'CLOSE' the following variables are provided:

  • task - The GlideRecord of the document task to close.

The result of the script should be assigned to the result variable.

  • When the action is 'CREATE' the result should be an object containing the table name and sys_id of the newly created document task
    {
      table: 'TABLE_NAME',
      sys_id: 'SYS_ID'
    }
    
    or false if unsuccessful.
  • When action is 'CLOSE' the result should be true/false indicating success.

Example

// set up a function that creates a document task record
function create(current, form, user, group, description, shortDescription){
  var table = 'x_pre_app.my_task_table'
  var gr = new GlideRecord(table);
  gr.table = current.getTableName() + '';;
  gr.recordID = current.sys_id+'';
  gr.form = form+'';
  gr.user = user.sys_id+'';
  gr.group = group.sys_id+'';
  gr.description = description+'';
  gr.form = shortDescription+'';
  var sys_id = gr.insert();
  if(!sys_id){
      return
  }
  return {
    table: table,
    sys_id: sys_id
  }
}
// set up function to close the record
function close(task ){
  if(task){
    task.state = 'closed';
    return task.update(); 
  }
  return false;
}

if (action === 'CREATE'){
  result = create(current, form, user, group, description, shortDescription);
} else if(action === 'CLOSE'){
  result = close(task);
}