Appearance
Javascript代碼 ?
在瀏覽器中執(zhí)行自定義 JavaScript 代碼。
超時(shí) ?
設(shè)置 JavaScript 代碼執(zhí)行的超時(shí)時(shí)間,默認(rèn)為 20000ms(20 秒)。超時(shí)后工作流將繼續(xù)執(zhí)行后續(xù)組件。
執(zhí)行每個(gè)新標(biāo)簽頁(yè) ?
每次 MakAgent 新建或切換標(biāo)簽頁(yè)時(shí)都會(huì)執(zhí)行 JavaScript 代碼。
注意事項(xiàng):
- 啟用此選項(xiàng)后,JavaScript 代碼塊不再需要活動(dòng)標(biāo)簽頁(yè)即可工作
- 內(nèi)置函數(shù)(如
automaRefData、automaNextBlock等)將不可用

執(zhí)行上下文 ?
JavaScript 代碼 ?
你可以在代碼中調(diào)用幾個(gè)內(nèi)置函數(shù)。
automaNextBlock(data, insert?) ?
js
automaNextBlock(
data?: Object | Object[],
insert?: boolean | { insert?: boolean; nextBlockId?: string; replaceTable?: boolean }
): void;automaNextBlock(
data?: Object | Object[],
insert?: boolean | { insert?: boolean; nextBlockId?: string; replaceTable?: boolean }
): void;告訴工作流繼續(xù)執(zhí)行下一個(gè)塊。
使用 data 數(shù)將數(shù)據(jù)插入表中。此參數(shù)可以采用對(duì)象或?qū)ο髷?shù)組數(shù)據(jù)類型。并且對(duì)象的鍵必須在表中表中定義。
參數(shù) insert 用于控制是否將 data 參數(shù)中的數(shù)據(jù)插入到表中,默認(rèn)為 true。或者,你可以傳遞一個(gè)包含兩個(gè)可選屬性的對(duì)象:
insert: 是否向表中插入數(shù)據(jù)。nextBlockId: 指定要導(dǎo)航到的下一個(gè)塊的 ID 的字符串。replaceTable: 用第一個(gè)參數(shù)傳遞的值替換工作流表值。 例子
js
automaNextBlock({ title: 'Something', count: 200 });
//or
automaNextBlock([{ title: 'Foo', count: 300 }, { title: 'Bar', count: 200 }])
// Continue execution to a specific block
automaNextBlock({ title: 'Hello' }, { nextBlockId: '4dxcxa3' })automaNextBlock({ title: 'Something', count: 200 });
//or
automaNextBlock([{ title: 'Foo', count: 300 }, { title: 'Bar', count: 200 }])
// Continue execution to a specific block
automaNextBlock({ title: 'Hello' }, { nextBlockId: '4dxcxa3' })
agentSetVariable(name, value) ?
設(shè)置工作流變量的值。
例子
js
agentSetVariable('name', 'John Doe');
agentSetVariable('prices', [200, 1000, 4000, 900, 200]);
agentSetVariable('profile', { firstName: 'John', lastName: 'Doe' });agentSetVariable('name', 'John Doe');
agentSetVariable('prices', [200, 1000, 4000, 900, 200]);
agentSetVariable('profile', { firstName: 'John', lastName: 'Doe' });automaRefData(keyword, path) ?
使用此功能可以訪問(wèn)工作流數(shù)據(jù),如表、變量等。
閱讀更多: 表達(dá)式
例子
js
// Get the first row of the table
const firstRow = automaRefData('table', '0');
// Get the last row of the table
const firstRow = automaRefData('table', '$last');
// Get the "name" column on the first row of the table
const firstRow = automaRefData('table', '0.name');
// Get the global data of the workflow
const globalData = automaRefData('globalData');
// Get the iteration data of the loop data block
const data = automaRefData('loopData', 'loopId');
// Get the value of the "text" variable
const value = automaRefData('variables', 'text');// Get the first row of the table
const firstRow = automaRefData('table', '0');
// Get the last row of the table
const firstRow = automaRefData('table', '$last');
// Get the "name" column on the first row of the table
const firstRow = automaRefData('table', '0.name');
// Get the global data of the workflow
const globalData = automaRefData('globalData');
// Get the iteration data of the loop data block
const data = automaRefData('loopData', 'loopId');
// Get the value of the "text" variable
const value = automaRefData('variables', 'text');agentFetch(type, resource) ?
在擴(kuò)展后臺(tái)發(fā)起HTTP請(qǐng)求,用它來(lái)避免CORS。
type: 請(qǐng)求的響應(yīng)類型??赡艿闹?text&json;resource: 你希望獲取的資源。
例子
js
agentFetch('json', { url: 'https://api.example.com'}).then((result) => {
console.log(result);
})
agentFetch('json', {
url: 'https://api.example.com',
method: 'POST',
body: JSON.stringify({
title: 'Hello world',
}),
})agentFetch('json', { url: 'https://api.example.com'}).then((result) => {
console.log(result);
})
agentFetch('json', {
url: 'https://api.example.com',
method: 'POST',
body: JSON.stringify({
title: 'Hello world',
}),
})agentResetTimeout() ?
重置執(zhí)行超時(shí)。
預(yù)加載腳本 ?
在執(zhí)行 javascript 代碼之前加載一個(gè) javascript 文件。
- URL
javascript 文件的 URL。
MakAgent在線文檔