ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Assign Default To Field

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

This tool will create a default value for a specified field. Whenever a new row is added to the table or feature class, the specified field will be set to this default value.

Usage

  • The default value is dependent on the field type chosen in the Field Name parameter. If you pick a field that is type LONG (long integer), the default value has to be type LONG.

  • Adding subtypes to the default value is optional. If you add a subtype, there must be a subtype field in the feature class or table. You can set the subtype field using the Set Subtype Field tool.

  • The subtypes of a feature class or table can also be managed in the Catalog window. Subtypes can be created and modified using the Subtypes Property page on the dataset Properties dialog box.

  • This tool may also be used to clear the default value of a field or subtype, if required.

Syntax

AssignDefaultToField_management (in_table, field_name, {default_value}, {subtype_code}, {clear_value})
ParameterExplanationData Type
in_table

Input table or feature class that will have a default value added to one of its fields.

Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View
field_name

The field that will have the default value added to it each time a new row is added to the table or feature class.

Field
default_value
(Optional)

The default value to be added to each new table or feature class. The value entered must match the data type of the field.

String
subtype_code
[subtype_code,...]
(Optional)

The subtypes that can participate in the default value.

String
clear_value
(Optional)

Specify whether to clear the default value for either the field or the subtype. To clear the default value, the default_value parameter must be passed in as an empty string. To clear the default value for the subtype, you must also specify the subtype which is to be cleared.

  • TRUE —The default value will be cleared (set to null).
  • FALSE —The default value will not be cleared. This is the default.
Boolean

Code sample

AssignDefaultToField example (Python window)

The following Python window script demonstrates how to use the AssignDefaultToField tool in immediate mode.

import arcpy
from arcpy import env
env.workspace = "C:/data/Montgomery.gdb/Landbase"
arcpy.CopyFeatures_management("blocks", "C:/output/output.gdb/blocks")
arcpy.AssignDefaultToField_management("C:/output/output.gdb/blocks", "Res", 1,
                                      ["0: Non-Residental", "1: Residental"])
AssignDefaultToField example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the AssignDefaultToField tool.

# Name: AssignDefaultToField_Example2.py
# Description: Assign a new default to a field along with subtypes
 
# Import system modules
import arcpy
from arcpy import env
 
# Set environment settings
env.workspace = "c:/data/Montgomery.gdb/Landbase"
 
# Set local variables
inFeatures = "blocks"
outFeatureClass = "c:/output/output.gdb/blocks"
fieldName = "Res"
defaultValue = 1
subTypes = ["0: Non-Residental", "1: Residental"]
 
# Execute CopyFeatures to make new copy of the input
arcpy.CopyFeatures_management(inFeatures, outFeatureClass)
 
# Execute AssignDefaultToField
arcpy.AssignDefaultToField_management(outFeatureClass, fieldName, 
                                      defaultValue, subTypes)

Environments

  • Current Workspace

Licensing information

  • ArcGIS for Desktop Basic: Yes
  • ArcGIS for Desktop Standard: Yes
  • ArcGIS for Desktop Advanced: Yes

Related topics

  • An overview of the Fields toolset

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal