Automic Workload Automation

Expand all | Collapse all

How to create an instance of the PromptSetDefinition API class

  • 1.  How to create an instance of the PromptSetDefinition API class

    Posted 04-11-2018 11:34 AM
    I am trying to find a way to attach a prompt set to an executable object using the Java APIs.

    All executable object classes have the values() method. This method returns an object of type ObjectValues. The ObjectValues  class has a method called addPromptSet that takes an object of type PromptSetDefinition as its argument. So how does one create an instance of the PromptSetDefinition class for a particular prompt set?


  • 2.  How to create an instance of the PromptSetDefinition API class

    Posted 04-12-2018 03:43 AM

    I found the answer. A note at the top of the page for PromptSetDefinition states:

    This class is created using the request com.uc4.communication.AddPromptSet An  instance of this class can be added to executable Objects (for example Jobs)  and default values for PromptElements can be set.

    The page for AddPromtSet does not clearly describe how to do this, but I figured it out eventually. It’s a multi-step process that involves instantiating one UC4ObjectName object (for the prompt set name) and two UC4Object ones (one for the prompt set, and another for the executable object to which you wish to attach it).

    private static void attachPromptSet(Connection myConnection, String execObjName, String promptSetName) throws IOException {
    // First, create an instance of AddPromptSet.
    UC4ObjectName promptSetUc4Name = new UC4ObjectName(promptSetName);
    UC4Object promptSetObject = openObject(myConnection,oIpromptSetName,true);
    AddPromptSet addPromptSet = new AddPromptSet(promptSetUc4Name , promptSetObject);
    myConnection.sendRequestAndWait(addPromptSet);
    closeObject(myConnection,promptSetObject);

    // Next, get the corresponding PromptSetDefinition.
    PromptSetDefinition promptSetDefinition = addPromptSet.getPromptSet();

    // Finally, open the executable object and attach the prompt set.
    UC4Object executableUc4Object = openObject(myConnection, execObjName, false);
    ObjectValues objectValues = getObjectValues(executableUc4Object);
    objectValues.addPromptSet(new PromptSetDefinition(promptSetDefinition));
    saveObject(myConnection, executableUc4Object);
    closeObject(myConnection,executableUc4Object);
    }

     

    In the above example, openObject, saveObject, and closeObject are simply wrapper methods I created to use the OpenObject, SaveObject , and CloseObject classes & then run Connection.sendRequestAndWait().

     

    The getObjectValues method might be interesting, so I’ll include it here. It is provides a way to get the ObjectValues of an executable object regardless of its type.

    public static ObjectValues getObjectValues(UC4Object uc4Object) {
    ObjectValues objectValues = null;
    String objectName = uc4Object.getName();
    String uc4ObjectClassName = uc4Object.getClass().getSimpleName();
    System.out.println(String.format("Object is an instance of class %s.", uc4ObjectClassName));
    switch (uc4ObjectClassName) {
    case "JobPlan":
    System.out.println(String.format("Object %s is a standard workflow.", objectName));
    objectValues = ((JobPlan) uc4Object).values();
    break;
    case "WorkflowIF":
    System.out.println(String.format("Object %s is an IF workflow.", objectName));
    objectValues = ((WorkflowIF) uc4Object).values();
    break;
    case "WorkflowLoop":
    System.out.println(String.format("Object %s is a FOREACH workflow.", objectName));
    objectValues = ((WorkflowLoop) uc4Object).values();
    break;
    case "Schedule":
    System.out.println(String.format("Object %s is a Schedule.", objectName));
    objectValues = ((Schedule) uc4Object).values();
    break;
    case "Script":
    System.out.println(String.format("Object %s is a Script.", objectName));
    objectValues = ((Script) uc4Object).values();
    break;
    case "TimeEvent":
    System.out.println(String.format("Object %s is a Time Event.", objectName));
    objectValues = ((TimeEvent) uc4Object).values();
    break;
    case "FileEvent":
    System.out.println(String.format("Object %s is a File Event.", objectName));
    objectValues = ((FileEvent) uc4Object).values();
    break;
    case "DatabaseEvent":
    System.out.println(String.format("Object %s is a DB Event.", objectName));
    objectValues = ((DatabaseEvent) uc4Object).values();
    break;
    case "ConsoleEvent":
    System.out.println(String.format("Object %s is a Console Event.", objectName));
    objectValues = ((ConsoleEvent) uc4Object).values();
    break;
    case "Job":
    System.out.println(String.format("Object %s is an OS Job.", objectName));
    objectValues = ((Job) uc4Object).values();
    break;
    case "FileTransfer":
    System.out.println(String.format("Object %s is a File Transfer.", objectName));
    objectValues = ((FileTransfer) uc4Object).values();
    break;
    default:
    System.out.println(String.format("Unknown object type."));
    objectValues = null;
    }
    return objectValues;
    }

     

    There’s surely a more concise & elegant way to do this, but it works.



  • 3.  Re: How to create an instance of the PromptSetDefinition API class

    Posted 04-20-2018 05:50 PM

    A few things to be aware of when using the API

    1. If you want to modify a value of a single element of the promptset you have to replace all the values. modifying only one will blank/default the rest

    2. If you remove a promptset from a job that has two promptsets, it will erase/default all the values of the other promptset

    3. Restarting/Executing a job with a promptset via the api requires doing some specific prompt set request handling that is not as well defined as I would have liked in the documentation



  • 4.  Re: How to create an instance of the PromptSetDefinition API class

    Posted 04-21-2018 06:24 AM

    Here’s what we have found regarding executing objects with prompt sets:

    • If you know the structure of the prompt set ahead of time, you can pre-fill the prompt buffer using the ExecuteObject.putPromptBuffer method. Then, assuming you provided all required values, you can just fire and forget.
    • If you don’t know the structure of the prompt set ahead of time (or if you’re using v9 or earlier), you must start an instance of DefaultNotificationListener to wait for the callback from the AE server notifying it of the prompt set. You must then submit the prompt set using SubmitPrompt.

     

    While searching for the documentation links, I found KB000089102; it describes both approaches.