📖
📖
📖
📖
Getint.io
Ask or search…
K

Advanced (Scripting)

Advanced mode (scripting) provides a way to customize app logic when it comes to building data that is going to be sent out to apps via API.
The script should be compliant with JS syntax. It is basically JavaScript code that is run by GetInt when specific events will be triggered.
Here is the list of events for which you can define the script, and available functions / variables:

On before integration runs

Is run every time just before integration runs
api.leftApp.fetch(url) - fetch data from endpoint from LEFT side app
api.leftApp.post(url, postData) - post data to LEFT side app
api.rightApp.fetch(url) - fetch data from endpoint from RIGHT side app
api.rightApp.post(url, postData) - post data to RIGHT side app
api.log(string) - write a log line to log file of the run

On before item request object sent

Is run before CREATE or UPDATE requests are sent with item data
api.leftApp.fetch(url) - fetch data from endpoint from LEFT side app
api.leftApp.post(url, postData) - post data to LEFT side app
api.rightApp.fetch(url) - fetch data from endpoint from RIGHT side app
api.rightApp.post(url, postData) - post data to RIGHT side app
api.log(string) - write a log line to log file of the run
state.syncAction - Create or Update
state.reqObj - request object data (containing fields) that was prepared by GetInt
state.triggerObj - data of the trigger/source object
e.g. if ITEM-1 was modified in Jira and will be synced with Azure Work Item #32, state.triggerObj contains data of ITEM-1 and state.reqObj is a constructed data object that will update #32

On before comment is created

api.leftApp.fetch(url) - fetch data from endpoint from LEFT side app
api.leftApp.post(url, postData) - post data to LEFT side app
api.rightApp.fetch(url) - fetch data from endpoint from RIGHT side app
api.rightApp.post(url, postData) - post data to RIGHT side app
api.log(string) - write a log line to log file of the run
state.comment - comment data that was prepared by GetInt to send
If state.comment.skipped flag is set up and equal true comment will be skipped and the request won't be sent.

Example

Migrating GitLab issue to Jira. Except for field data we want to copy to Jira information about related merge requests to the given GitLab issue. GitLab offers API where we can that necessary information and obtain Pull Requests data in JSON format. Jira is on the left side in integration and GitLab is on the right side. To achieve what we need we have to put below JavaScript code under the Before item request object sent (left app) option.
// 1 - fetch merge requests data frmo rightApp (GitLab)
var links = api.rightApp.fetch('/api/v4/projects/' + state.triggerObj.project_id + '/issues/' + state.triggerObj.iid + '/related_merge_requests');
if (links) {
// 2 - iterate over links and add to the array
for (var i=0; i<links.length; i++) {
var link = links[i].web_url;
linksArray.push('[' + link + '|' + link + ']');
}
}
// 3 - join links together and insert into a customfield
state.reqObj.fields['customfield_10174'] = mergesArray.join('\n');