Sample One: Read/Write Fields

This sample script copies the value of the Title field to be copied to the Description field. It can be used in the pre-transition, post-transition, pre-state, or post-state contexts.
Note: To use this script, you must add it to SBM using the Scripts editor in SBM Composer. You must then associate it with a transition or state in the workflow in which the state or transition was defined.

Read/Write Field Script Contents

' SBM AppScript Example: ReadWriteFields.tsc

' ---------------------------------------
' This script reads from a field and writes its value to another field.
'
' Requirements:
' This script relies on Shell.Item, which only exists in pre-transition,
' post-transition, pre-state, and post-state contexts.
'
' Note: if reading a drop-down list field, do not use the GetFieldValue()
' function. Instead, retrieve the actual Field object, and use its
' GetDisplayValue() method.
' Require all variables to be declared before use Option Explicit
' MODIFY THESE CONSTANTS FOR YOUR DATABASE
' ----------------------------------------
' Names of the fields we will work with
const FLDNAME_SRC = "title"
const FLDNAME_DEST = "description"
' Find the item being transitioned
If Ext.ShellHasProp( "Item" ) Then
  ReadWriteFields
Else
  ' There is no current item, so write a message to the event viewer
  Call Ext.LogErrorMsg( "SBM AppScript error: Shell.Item does not exist." )
End If
' Read from one field, write back to another field
Sub ReadWriteFields()
  Dim fldValue, QUOTE
  QUOTE = Chr( 34 )  ' the only way to get a quote in VBScript
  ' Read from the source field
  If Not Shell.Item.GetFieldValue( FLDNAME_SRC, fldValue ) Then
    ' Error finding the field or reading from it
    Call Ext.LogErrorMsg( "Cannot read from field " _
      & QUOTE & FLDNAME_SRC & QUOTE )
    Exit Sub
  End If
  ' Write to the destination field
  If Not Shell.Item.SetFieldValue( FLDNAME_DEST, fldValue ) Then
    ' Error finding the field or writing to it
    Call Ext.LogErrorMsg( "Cannot write to field " _
      & QUOTE & FLDNAME_DEST & QUOTE )
    Exit Sub
  End If
End Sub