DEV Community

Peter + AI
Peter + AI

Posted on

Unlocking Uniface's Automation Superpower: A Simple Guide to the $ude Function πŸš€

Hey everyone! πŸ‘‹ If you're working with the Uniface low-code platform, you know it's great for building robust applications. But did you know there's a powerful built-in function that can automate many of your development and deployment tasks? Let's dive into the $ude function in Uniface 10.4!

A quick note: This post was put together with the help of an AI assistant to make the official documentation a bit more digestible. πŸ€–

What is the $ude function? πŸ€”

Think of $ude as your personal assistant for the Uniface repository. It's a ProcScript function that lets you perform actions directly on your development objects and resources. Instead of manually clicking through the IDE (Integrated Development Environment), you can write a script to do things like compiling, exporting, or importing objects. This is a game-changer for automating your build processes and creating your own development tools. βš™οΈ

The Basic Syntax

The function looks a bit intimidating at first, but it's quite logical. Here is the general structure:

$ude(Action, Argument1, Argument2, Argument3, {OptionList})

  • Action: A string telling $ude what to do (e.g., "compile", "export").
  • Arguments: These specify what the action should target (e.g., the object type, the name, the destination).
  • OptionList: Optional settings to fine-tune the action.

What Can You Do with $ude? ✨

The $ude function can perform a wide range of actions. Here are some of the most common ones:

  • "compile": Compile your components, applications, services, and other objects directly from code. Perfect for continuous integration pipelines!
  • "export": Export objects from your repository into files (like XML). This is great for source control or backing up your work.
  • "import": The opposite of export. It lets you import objects from a file back into your repository.
  • "copy": Copy or convert data between different formats.
  • "delete": Remove a resource. Use this one with care! πŸ—‘οΈ
  • "exist": Check if an object or resource already exists before trying to create or compile it.

A Simple Example: Copying a File

Let's look at a practical example from the documentation:

$result = $ude("copy", "misc", "myexportfile.xml", "def:")

Here's what this line does:

  1. Action: "copy" - We want to copy something.
  2. Argument1: "misc" - The type of object we're dealing with.
  3. Argument2: "myexportfile.xml" - This is our source file.
  4. Argument3: "def:" - This is our destination.

In short, this command copies a file named myexportfile.xml. It's a simple action, but imagine scripting this for hundreds of files!

Did it Work? Checking the Results βœ…βŒ

This is where it gets a little tricky, and it's a common point of confusion. The direct return value of $ude (which we stored in $result) doesn't tell you the whole story.

  • If $result is >= 0, it means the $ude function itself ran without a critical failure. It does NOT mean your action (like compiling) was successful. For example, it could return 0 if it tried to compile components but found none that matched your criteria.
  • If $result is < 0, it means a serious error occurred and the function couldn't even execute properly (e.g., you used an invalid action name).

The Real Details are in $procReturnContext! πŸ”

To find out what really happened, you need to check the global variable $procReturnContext. After running $ude, this variable is filled with detailed information about the operation.

For instance, if you ran a $ude("compile", "form", "my*", "") command, $procReturnContext might look something like this (formatted for readability):


Context=UDE compile;
InputComponents=2;
OutputComponents=1;
Warnings=2;
Errors=1;
Details=...
Enter fullscreen mode Exit fullscreen mode

This tells you everything you need to know:

  • It found 2 components to compile (InputComponents).
  • It only successfully compiled 1 of them (OutputComponents).
  • It generated 2 warnings and 1 error.

If OutputComponents was 0, you would know that nothing was actually compiled, even if $ude returned 0!

🚨 One Very Important Prerequisite!

Here's a typical problem developers run into: the $ude function won't work just anywhere. It needs access to the Uniface IDE's functionality. This means your application or component must be:

  • Run using ide.exe on Windows.
  • OR configured to include usys:ide.uar in its list of resources.

If you forget this, you'll likely get a -1700 UDEERR_UDE_NOT_AVAILABLE error. So, remember to set up your environment correctly!

Conclusion

The $ude function is an incredibly powerful tool for any serious Uniface developer. By mastering it, you can automate repetitive tasks, integrate Uniface into a modern DevOps workflow, and build custom tools to manage your projects. It might take a little practice, but the payoff in time saved is huge. Happy scripting! πŸŽ‰

Top comments (0)