Automation in code generation: Lesson 6 – Checking for pre-existing objects.

In scripts that create objects automatically, it is important to check whether such objects have already been created in the application, in order to avoid duplicated objects or even script errors.

There is no specific method to check this directly; to do so, one possibility is to search the object via Item method.

Set testObj = folder.Item(“DemoTag1”)

There are two possible outcomes:

  • If a script error appears on the row, it means the object does not exist.
  • I no script errors appear, it means the object exists.

Then, you will only need to handle errors in this script to be able to use this information and proceed with code development. Example:

'points to the desired location 
set folder = Application.GetObject("Data")

on error resume next

'looks for desired object
set testObj = folder.Item("DemoTag5")

'if a script error occurred 
If Err.Number <> 0 then

MsgBox "The object doesn't exist!"

'if no script errors occurred 
Else

MsgBox "The object exists!"

End If
on error goto 0

Since this verification can repeat at several points in the script, you may want to create a specific Function for this, in order to keep the script tidier and more organized.

Before proceeding to Lesson 7, we recommend reading the following articles:

Handling script errors.
KB-30665: Working with functions in E3 scripts.

Related articles


Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *