SBM AppScript Reference → SBM AppScript Samples → Sample One: Read/Write Fields
' ---------------------------------------
' 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
Copyright © 2007–2017 Serena Software, Inc. All rights reserved.