Bite #3: Store Sys IDs in User Preferences

Learn the best way to point to a particular group record from a script.

The Situation

  • Often times a script will need to reference a particular group (such as an advanced approval script).
  • Best Practice states that scripts should use the sys_id of the group rather than the name (because the name will often change).
  • Referencing a sys_id in a script makes it difficult to change groups in the future, which reduces flexibility.

The Solution

  1. Create a new System Property (table = sys_properties), and store the sys_id as the value of the property.
  2. In your script, reference the system property you created using “gs.getProperty(‘property name here’, ‘default value if desired’)”

Optional, but Recommended:

  1. After saving, use the related list to assign that System Property to a category.
  2. Create a new module under the related application that uses “URL from arguments”, and set the URL to be “system_properties_ui.do?sysparm_category={your category name here}”.


Categories: Developers, Scripting Tips

Tags: , , , , ,

1 reply

Trackbacks

  1. How to Ace your ACE Report | GarrettNow

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: