6.5.1 Action scripts (UI Version 1.0)

The script specified by the “file” label in the Script YAML file must be created in advance. Please write the script in JavaScript. The following is a list of action execution timings for each component and the names of functions that are called. The customer should define the function name in the corresponding script and write the contents of the action.

(Table) List of execution timing and function names for each component (UI Version 1.0)

Component Action execution
timing
Name of function
called in the script
Function arguments
Data format Value to be set
Grid When the window is displayed handleLoad - -
Button When the button is clicked handleClick - -
Form When the value changes handleChange Object Value after change
When the selection is changed handleChange Object Value after change
When a checkbox selection is changed handleChange boolean Value after change
When focus is lost handleBlur - -
Table When the cell value changes handleCellValueChange string Value after change
When the line selection changes handleSelectionModelChange Array<string> ID of the selected line

The following is a list of function names that can be used when describing the contents of an action.

(Table) List of function names that can be used when describing the contents of an action (UI version 1.0)

Class name Function name Function arguments Content of action
Data format Variable name Value to be set
OIWindow open string - type Specify "move", "new_window", or "new_tab".
  • "move": Display the specified page in the active tab.
  • "new_window": Display the specified page in a new window.
  • "new_tab": Display the specified page in a new tab.
Open a page or UI.
Object options -
string url If type is "move", "new_window", or "new_tab", specify the URL of the page to be displayed in url.
Example) {url:'/sys_task'}
OIWindow showMessage string - type Specify "snackbar" to display messages in a snackbar, or "modal" to display messages in a dialog box. Display a snackbar or message dialog box. If "modal" is specified for type, when the first button is clicked, "ok" is set as the return value, and when the second button is clicked, "cancel" is set as the return value in Promise<string> type.
Object options -
string typeMess If the type is "snackbar", specify "error", "warning", "info", or "success". If the type is "modal", two buttons are displayed, and it is possible to determine which one was clicked by receiving the return value.
string content Specify the message that is displayed.
string title If the type is "modal", specify a title.
Object btnOk If the type is "modal", set the content to be displayed in the label of the first button.
string btnCancel If the type is "modal", set the content to be displayed in the label of the second button.
If both btnOk and btnCancel are omitted, the "OK" button will be displayed.
OIWindow refresh string - type Specify the data to be refreshed as either "form" or "table". Refreshes the form and table display data.
Used to reflect data registered with OIData.insertCurrentRecord and data deleted with OIData.deleteCurrentRecord in forms and tables.
string - name Specify the name of the component to be refreshed.
OIData insertCurrentRecord Object currentRecord - Insert records into any table in the database using Ops I REST API graphql. Set the Response Body as a Promise<Object> type in the return value.
string table Specify the table name into which the record will be inserted.
Object Field name of the inserted record Specify the value to be set in the field of the inserted record. Any number can be specified, but it must correspond to the field name of the table where it is to be inserted. The value to be set should match the field type; for example, "string" for a string field, or "number" for a numeric field.
string - ctxId Specify the context ID to be associated with the record to be inserted.
OIData getRecords string - tableName Specify the table name of the record to be obtained. Uses the Ops I REST API graphql to obtain records from any table in the database, and set the Response Body as a Promise<Object> type in the return value.
string - obj Specify the GraphQL query for the record obtain condition.
Example 1) When specifying the fields to be obtained: '{field1 field2}'
Example 2) When obtaining field1 and field2 for the same record as the specified record ID: '(where: {id: {_eq: "record ID" } }){field1 field2}}'
OIData updateCurrentRecord Object currentRecord - Uses the Ops I REST API graphql to update any record in a table in the database, and sets the Response Body as a Promise<Object> type in the return value.
string table Required. Specify the table name of the record to be updated.
string id Required. Specify the ID of the record to be updated.
Object Field name of the updated record Specify the value to be set in the field of the record to be updated. Any number can be specified, but it must correspond to the field name of the table where it is to be updated. The value to be set should match the field type; for example, "string" for a string field, or "number" for a numeric field.
OIData deleteCurrentRecord string - tableName Specify the table name of the record to be deleted. Uses the Ops I REST API graphql to delete any record from a table in the database, and sets the Response Body as a Promise<Object> type in the return value.
string - currentId Specify the ID of the record to be deleted.
OIData query Object query - Use the Ops I REST API graphql to execute any GraphQL query and set the Response Body as a Promise<Object> type in the return value.
string query Specify the GraphQL query to be executed as a string.
Object variables Specify variables to be embedded in the GraphQL query.
OIApi call string - url Specify the URL of the REST API to be executed. The REST API you specify must have a Response Body in JSON format. Execute the REST API and set the Response Body as a Promise<Object> type in the return value.
Object - option Specify the parameters. If omitted, {} is set.
Example) {method: 'GET', headers: {'Content-Type': 'application/json'}
boolean - showError Specify whether to display error details on the window when an error occurs in REST API. If omitted, will be set to "true".
OIForm setStatus string - field Specify the target field name for which the status is to be set. Set the status of the field in the form. Only field types with a function to output validation errors are supported.
string - status Set the status. Setting "error" will result in an error state, and setting anything else will cancel the error state.
OIForm setHelperText string - field Specify the target field name for which the helper text is to be set. Set the helper text for the form field. Only field types with a function to output validation error messages are supported.
string - helperText Set the helper text.
OIForm removeHelperText string - field Specify the field name for which the helper text is to be deleted. Delete the helper text for the form field. Only field types with a function to output validation error messages are supported.
OICommon* show - - - - Display the components.
OICommon* hide - - - - Hide the components.
OICommon* enable - - - - Enable use of the components.
OICommon* disable - - - - Disable use of the components.
OICommon* getComponent Object options - Obtains information for the specified component and sets it as a Promise<Object> type in the return value.
If the component is "form", set the workflow information. If it is "table", set the UUID of the selected row.
For details of return values, see "(Table) getComponent return values".
boolean allForm If "true" is specified, all forms are obtained in addition to the component specified by OICommon (component name).
OICommon* setComponent Object - value Specify the values to be updated. Update information for the specified component. Can be used only when the component is "form". Specify the updated value of the object of the return value that can be obtained by getComponent for value.
Also, the only values that can be updated are the data values of the records set in object.current.table. No other values are updated.
OICommon getUserProfile - - - - Obtains the profile of the logged-in user and sets it as a Promise<Object> type in the return value. static function.
OICommon getDateWithUserTimezone - - - - Obtains the current date and time (YYYY-MM-DDTHH:mm:ssZ) in the time zone of the logged-in user and sets it as a string in the return value. static function.
Example) 2022-09-21T15:36:20+09:00
OICommon showLoadingScreen - - - - Show the loading window. static function.
To cancel the displayed loading window, the same number of calls to hideLoadingScreen are required as calls to showLoadingScreen.
When data changes and executions such as OIData.insertCurrentRecord, OIWorkflow.respond or OIWorkflow.start are performed in the processing of operations such as button presses by the user, it is necessary to execute showLoadingScreen to prevent multiple executions.
OICommon hideLoadingScreen - - - - Cancel display of the loading window. static function.
To cancel the displayed loading window, the same number of calls to hideLoadingScreen are required as calls to showLoadingScreen.
Ensure that hideLoadingScreen is always called, even in the event of an error, by using a try-finally clause, etc. If it is not called, it will remain on the loading window and no window operations will be possible.
If the loading window is not displayed when this method is called, this method will have no effect on the window and will end normally.
OICommon getLocation - - - - Obtains information about the current position of the current document using Window.location (Web API built into the browser), and sets the return value as a Promise<Object> type.
The following information is set in the return value. For details on return values, check the Window.location specification.
  • hash
  • host
  • hostname
  • href
  • origin
  • pathname
  • port
  • protocol
  • search
static function.
OIWorkflow respond string - contextID Context ID Responds to the workflow and sets the execution result as the return value of the Promise<Object> type.
string - activityName Reply activityName (Task name specified in tasks in the workflow definition)
Object - params Specifies one of the following as the action to be taken in response: "accept", "reject", "pull_back", or "cancel".
Example)
{
  "oi_response": "accept"
}
OIWorkflow start string - contextID Context ID Executes the workflow associated with the specified context ID and sets the execution result as the return value of the Promise<Object> type.
Object - body Specifies the contents of the parameters to be set in the workflow.
Example)
{
  "params": {
    "param1": "string",
    "param2": "string",
    "param3": "string"
  }
}
*The target component name is specified as an argument for the constructor of the OICommon class.

(Table) getComponent return values

Specified
Component
Type Variable name Value to be set
form array activities List of information (explanations, status, definitions, etc.) for the steps being executed or that have been executed. Information about steps that have never been executed is not included.
Object activitySelected Out of the activities, information (explanations, status, definitions, etc.) for steps with a status of Pending is set.
Object context Workflow information (steps, assigned users, etc.) is set.
Object current.table Data for the record displayed in the form. In dictionary format, the table name is set to key and a dictionary of fields and data is set to value.
Object currentActivity Reserved field. Always set to null.
Object schedule Information on the workflow schedule is set.
Object workflow Workflow information defined in manifest.yaml is set.
table string rowSelected A UUID is set to identify the data in the selected table row.

<Definition example>

function handleClick() {
  (async () => {

    const oiCommon = new OICommon(’lend_vm_form’);
    const formContext = await oiCommon.getComponent();

    // 1. Update current record.
    const table = formContext?.lend_vm_form?.current.table;
    const tableName = Object.keys(table)[0];
    const currentRecord = { …table[tableName]};
    currentRecord.table = ‘u_’ + tableName;
    const now = new Date();
    const nowString 
    = now.getFullYear()
    + (now.getMonth() + 1).toString().padStart(2,“0”) 
    + now.getDate().toString().padStart(2,“0”) 
    + now.getHours().toString().padStart(2,“0”) 
    + now.getMinutes().toString().padStart(2,“0”) 
    + now.getSeconds().toString().padStart(2,“0”);
    
    var prefix = "";
    if(currentRecord.sys_name == “order_mgt_sys”){
      prefix= “XXX”;
    }else if(currentRecord.sys_name == “customer_mgt_sys”){
      prefix= “YYY”;
    }
    else{
      prefix=“ZZZ”;
    }
    currentRecord.vm_name = prefix + nowString;
    currentRecord.log_result = “Outputs the log results when generating a VM”;
    await OIData.updateCurrentRecord(currentRecord);

    // 2.Respond to task.
    const currentTaskname = formContext?.lend_vm_form?.activitySelected?.name;
    const contextID = formContext?.lend_vm_form?.context?.id;

    await OIWorkflow.respond(contextID,currentTaskname,
      {
        ‘oi_response’: ‘accept’,
      });

    // 3.Transition to workflow list.
    OIWindow.open(‘move’, {‘url’: ’/sys_task/workflow/workflow_list’});
  })();
}