Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hi everyone,
I want to use AddOrUpdateAlert to change the property Alert in service,I am using below code :
//Create the Attributes Infotable for AddOrUpdateAlert call
var params = {
infoTableName: "alertAttr" /* STRING */
};
var attrs = Resources["InfoTableFunctions"].CreateInfoTable(params);
// limit - Minimum value at which the alert will trigger.
var field = new Object();
field.name = "minimum";
field.baseType = "NUMBER";
attrs.AddField(field);
// limitInclusive - Is the condition Greater than (>) or Greater than or equal (>=)?
field.name = "minimumInclusive";
field.baseType = 'BOOLEAN';
attrs.AddField(field);
// limit - Maximum value at which the alert will trigger.
field.name = "maximum";
field.baseType = "NUMBER";
attrs.AddField(field);
// limitInclusive - Is the condition Greater than (>) or Greater than or equal (>=)?
field.name = "maximumInclusive";
field.baseType = 'BOOLEAN';
attrs.AddField(field);
var row = new Object();
row.minimum = 2; // Alert will trigger when field <2
row.minimumInclusive = true;
row.maximum = 9; // Alert will trigger when field >=9
row.maximumInclusive = false;
attrs.AddRow(row);
me.AddOrUpdateAlert({
property: "temp" /* STRING */,
alertType: "InRange" /* STRING */,
alertName: "stateAlert" /* STRING */,
description: "myTestAlert" /* STRING */,
enabled: true /* BOOLEAN */,
priority: 1 /* INTEGER */,
attributes: attrs /* INFOTABLE */,
persistent: true /* BOOLEAN */
});
Error Message :Error executing service alertAdd. Message :: Alert Attributes For [InRange] are not valid - See Script Error Log for more details
I was able to do this for an Above and Below alert but can't get it to work with an "InRange" or "OutOfRange" alert type refert to this Article:CS230216 - What is the Expected Format of the Attributes InfoTable for the AddOrUpdateAlert Service on ThingWorx? (ptc.com)
Anyone help with it ?
Thanks!
Solved! Go to Solution.
Hi,
1. Please send your error log here: https://support.ptc.com/apps/case_logger_viewer/cs/auth/ssl/log
2. Read this article - "Creating "InRange" or "OutOfRange" Alert type through service in ThingWorx": https://www.ptc.com/en/support/article/CS299728
Hi,
1. Please send your error log here: https://support.ptc.com/apps/case_logger_viewer/cs/auth/ssl/log
2. Read this article - "Creating "InRange" or "OutOfRange" Alert type through service in ThingWorx": https://www.ptc.com/en/support/article/CS299728
Applies To
ThingWorx Platform 8.0 to 9.0 F000
Description
InRange or OutOfRange alerts cannot be created through service in ThingWorx
ERROR : Execution error in service script [CreateAlert] :: Alert Attributes For [InRange] are not valid
How to create InRange or OutOfRange alerts through service in ThingWorx ?
Resolution
Reported to R&D as JIRA ticket PSPT-6179
Steps to create an InRange alert through service:
1.Create a Thing
2.Add a property to trigger an alert
3.Create a service with Output Base Type NOTHING
4.Add the sample code to the service:
============================================
var params = {
infoTableName : "InfoTable",
dataShapeName : "IntegerRangeAlert" // This depends on the property used to trigger the alert
}; // In example we are triggering Integer property hence IntegerRangeAlert DS is used
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(NumberRangeAlert)
var table = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
table.minimum = <Add the Minimum integer to trigger the alert>;
table.minimumInclusive = true;
table.maximum = <Add the Maximum integer to trigger the alert>;
table.maximumInclusive = true;
table.calculationValue = <Calculation value for Min and Max from alert value>;
table.calculationType = "Percentage";
var params = {
alertType: "InRange" /* STRING */,
alertName: "temp" /* STRING */,
property: "<Give the name of the property created in step 2>" /* STRING */,
description: undefined /* STRING */,
attributes: table /* INFOTABLE */,
persistent: true /* BOOLEAN */,
priority: 1 /* INTEGER */,
enabled: true /* BOOLEAN */
};
me.AddOrUpdateAlert(params);
==============================================
5.Save the service
6.Test the service
7.Go to Properties and check if the alert is triggered
Note: The DataShape called in the code depends on the Property Base Type:
Integer Base type uses IntegerRangeAlert DataShape
Number Base type uses NumberRangeAlert DataShape
Long Base type uses LongRangeAlert DataShape