Scripts

🔣 Automate tasks and enhance functionality with scripts.

Scripts allow you to automate tasks and perform various actions based on events and conditions. This section will provide a guide and background information to help write scripts.

1. Tasks

Scripts are typically used to perform tasks responding to specific events or triggers. Here are some essential functions related to tasks in scripts:

1.1. C.utilityInputs.task()

The C.utilityInputs.task() has information regarding the current deployment being performed. It has information about the event that triggered the deployment and all the scripts in the deployment.

Below is the response sample of the task:

1.2. C.getEvent()

To access information about the event itself, you can use the C.getEvent() helper function.

Below is the response sample of the event:

1.3. C.getEventMetadata()

The C.getEventMetadata() function retrieves event metadata containing information such as user, role, and more. Additional details regarding event metadata:

  • The values passed are always in iov format.
  • For "before-edit" and "after-edit events":
    • If called from the entry layout, only the edited field values are passed.
    • If called from the generic edit page, all the field values are passed whether it is edited or not.

The eventMetadata is also passed with additional data based on different events.

  1. "Before Edit" and "After Edit" Events

In these events, the metadata includes details about the user, role, form ID, data values, subrecords, and the event's source.

{
	"user": {},
  "role": {},
  "formId": 233451, 
  "data": {
    "values": {
      "title": "test workflow 6"
		},
    "subrecords": {
      "toAdd": {},
      "toEdit": {},
      "toDelete": {},
      "subrecordInternalIds":[],
      "added": {}
    }
	},
	"source": "V3_API"
}
  1. "After Add" Event

For "after add" events, the metadata provides a complete view, including user, role, form ID, data values, sub records, and added entries (see the values and subrecords objects).

{
   "user": {},
   "role": {},
   "formId":233451,
   "data":{
      "values":{
         "status":[
            "564931"
         ],
         "title":"test workflow 6",
         "team":[
              "248050"
         ],
         "submitted-by":[
              "23643"
         ],
         "owner":[
           		"23643"
         ],
         "scope-status":[
              "244632"
         ],
				 "tags":[
              "564921"
         ],
				"effort-days": 1
      },
      "subrecords":{
         "toAdd":{
           "kalysys-dependencies":[
             {
              	 "task":[
                   "108018"
                 ],
                 "type":[
                   "106284"
                 ],
                 "offset":1,
                 "index":0,
                 "id":"TEMP-BBR-LIEU",
                 "parent":""
              }
            ]
         },
         "toEdit":0,
         "toDelete":0,
         "subrecordInternalIds":[
           "kalysys-dependencies"
         ]
         "added":{
        	 "kalysys-dependencies": [
        			737459	 
        	 ]
   			 }
			}
		},
		"source":"V3_API"
}
  1. Additional Information in "After Add" Events:

In "after add" events, you may also receive the addedEntryId and addedSubrecordIds to further enhance the event details.

"added":	{
	"kalysys-dependencies": [
		737463
	]
},
"addedEntryId": 737462
📘

Info:

To get all the values of the currently edited entry, use the C.getEntry() function.

2. Working with Multiple Scripts

In a deployment, multiple scripts may run sequentially.

{
  "status": "success",
  "scriptIndex": 0,
  "result":
  	"success": true,
  	"payload": {
  		"returnValue": {
  		...
			}
		}
	}
}

Here are functions that help you interact with scripts in this context:

FunctionsDescription
C.getCurrentScriptIndex() Get the index of the current script.
C.getCurrentScriptUid()Get the unique ID of the current script.
C.getScriptIdOfIndex(index)Get the ID of the script that ran at a specific index.
C.getScriptState("script id") or C.getScriptStateBasedOnIndex(index)Check the state of a script.
C.isScriptSuccess("scriptId")Verify if a script was executed successfully.
C.getScriptStatus("scriptId")Retrieve the status of a script, which can be pending, in_progress, success, or error.

2.1. Access the Return Value of a Script

You can access the return value of a specific script using the C.getScriptReturnValue("scriptid") function. This allows you to retrieve whatever was returned by the specified script.

📌 Need Help?

If you require assistance or encounter any issues, please don't hesitate to contact us for further support.