How to pass data fetched from journey1 to another journey (dynamic data)
How to pass data generated from journey1 and pass it to journey2 dynamically? is there an extension available or any other better way of doing this?
-
We use setTestData extension to store dynamic value to a datatable and then refer to the same table in another journey to pick the data. Hope this input helps.
setTestData("environment", "give your token here", “TableName”, "RowNumber", “project ID”, “columnname:data”)
extension:
endpoints = {
PRODUCTION: "https://api.virtuoso.qa/api",
STAGING: "https://api-staging.virtuoso.qa/api",
DEVELOPMENT: "https://api-dev.virtuoso.qa/api",
APP2: "https://api-app2.virtuoso.qa/api"
}
const BASE_URL = endpoints[env]
if (!BASE_URL) {
doneError("Invalid environment " + env + ". Please use PRODUCTION, STAGING, DEVELOPMENT or APP2")
}
async function getTable () {
const endpoint = `${BASE_URL}/projects/${projectId}/dataTables?envelope=false&token=${token}`
const dataTables = await axios.get(endpoint)
.catch(error => {
doneError('Error fetching data table id : ' + error);
})
const dataTable = Object.values(dataTables.data).find(value => value.name === table)
if (!dataTable) return doneError(`Table ${table} not found`)
return dataTable
}
function getColumnId(table, columnName) {
const column = Object.values(table.attributes).find(attribute => attribute.name === columnName)
if (!column) {
doneError(`Could find column ${columnName} in table`)
}
return column.id
}
function getColumnName(table, columnId) {
const column = Object.values(table.attributes).find(attribute => attribute.id === columnId)
if (!column) {
doneError(`Could find column with ID ${columnId} in table`)
}
return column.name
}
async function getTableValues (tableId) {
const endpoint = `${BASE_URL}/testdata/tables/${tableId}/values?envelope=false&token=${token}`
const { data: tableValues } = await axios.get(endpoint)
.catch(error => {
doneError('Error fetching data table values : ' + error);
})
return tableValues
}
async function updateTable (tableId, newValues, modifiedDate) {
const endpointUrl = `${BASE_URL}/testdata/tables/${tableId}/values?envelope=false&token=${token}`
const requestData = {
modifiedDate: modifiedDate,
newTestDataValues: newValues
}
await axios.put(endpointUrl, requestData)
.catch(error => {
doneError('Error updating table');
})
}
function updateTableValues(table, row, oldValues, data) {
let dataObj = {}
try {
dataObj = JSON.parse(data)
}
catch (e) {
doneError("Could not parse data, make sure that it's correctly formatted in JSON")
}
for (const [key, value] of Object.entries(dataObj)) {
const columnId = getColumnId(table, key)
try {
if (!oldValues[row]) oldValues[row] = {}
oldValues[row][columnId] = value
}
catch (e) {
doneError(`Error updating value ${key} in row ${row} of table`)
}
}
return oldValues
}
async function setTableData(data, row) {
const tableObj = await getTable()
const oldValues = await getTableValues(tableObj.id)
const newValues = updateTableValues(tableObj, row, oldValues, data)
await updateTable(tableObj.id, newValues, tableObj.modifiedDate)
done("Table Updated")
}
setTableData(data, row)
0 -
Virtuoso flows might be helpful - https://docs.virtuoso.qa/library/apps/flow/#virtuoso-flow
0
Please sign in to leave a comment.
Comments
2 comments