diff --git a/client/src/app/_models/script.ts b/client/src/app/_models/script.ts index 0fa47861..eb1892e1 100644 --- a/client/src/app/_models/script.ts +++ b/client/src/app/_models/script.ts @@ -189,6 +189,14 @@ export class SystemFunctions { params:['array', false, false], paramsText: 'script.sys-fnc-getHistoricalTag-params', paramFilter: ScriptParamFilterType.history + }, + { + name: '$sendMessage', + mode: null, + text: 'script.sys-fnc-sendMessage-text', + tooltip: 'script.sys-fnc-sendMessage-tooltip', + params: [false, false, false], + paramsText: 'script.sys-fnc-sendMessage-params' } ]; } diff --git a/client/src/app/_services/script.service.ts b/client/src/app/_services/script.service.ts index dc4fa182..b3ff5003 100644 --- a/client/src/app/_services/script.service.ts +++ b/client/src/app/_services/script.service.ts @@ -93,6 +93,7 @@ export class ScriptService { code = code.replace(/\$invokeObject\(/g, 'this.$invokeObject('); code = code.replace(/\$runServerScript\(/g, 'this.$runServerScript('); code = code.replace(/\$getHistoricalTags\(/g, 'this.$getHistoricalTags('); + code = code.replace(/\$sendMessage\(/g, 'this.$sendMessage('); return code; } @@ -167,4 +168,8 @@ export class ScriptService { const query: DaqQuery = { sids: tagIds, from: fromDate, to: toDate }; return await lastValueFrom(this.hmiService.getDaqValues(query)); } + + public async $sendMessage(to: string, subject: string, message: string) { + return await this.projectService.runSysFunctionSync('$sendMessage', [to, subject, message]); + } } diff --git a/client/src/assets/i18n/en.json b/client/src/assets/i18n/en.json index ad9676a0..f3dc0fdc 100644 --- a/client/src/assets/i18n/en.json +++ b/client/src/assets/i18n/en.json @@ -1268,6 +1268,9 @@ "script.sys-fnc-getHistoricalTag-text": "$getHistoricalTags(TagIds array, from msec., to msec.)", "script.sys-fnc-getHistoricalTag-tooltip":"get historical tags by milliseconds range: $getHistoricalTags([TagIds] as array, from as number, to as number)", "script.sys-fnc-getHistoricalTag-params":"'Tag Ids array', 'From msec.', 'To msec.'", + "script.sys-fnc-sendMessage-text": "$sendMessage(address, subject, message)", + "script.sys-fnc-sendMessage-tooltip": "System function to send Message (Mail): $sendMessage(address as string, subject as string, message as string)", + "script.sys-fnc-sendMessage-params": "'address', 'subject', 'message'", "script.template-chart-data-text": "Customized chart data", "script.template-chart-data-tooltip": "Code template of customized chart data to return", diff --git a/server/runtime/scripts/index.js b/server/runtime/scripts/index.js index cb64f8e1..42b9d0a7 100644 --- a/server/runtime/scripts/index.js +++ b/server/runtime/scripts/index.js @@ -229,6 +229,7 @@ function ScriptsManager(_runtime) { sysFncs['$getDeviceProperty'] = runtime.devices.getDeviceProperty; sysFncs['$setDeviceProperty'] = runtime.devices.setDeviceProperty; sysFncs['$getHistoricalTags'] = runtime.devices.getHistoricalTags; + sysFncs['$sendMessage'] = _sendMessage; return sysFncs; } @@ -237,6 +238,11 @@ function ScriptsManager(_runtime) { let command = { command: ScriptCommandEnum.SETVIEW, params: [view, force] }; runtime.scriptSendCommand(command); } + + var _sendMessage = async function (address, subject, message) { + var temp = await runtime.notificatorMgr.sendMailMessage(null, address, subject, message, null, null); + return temp; + } } module.exports = {