1 Reply Latest reply on Oct 24, 2017 2:13 AM by mlähde RSS
    dsawyer Explorer

    Creating Email alert based on % of target value

    Hi All

     

    I am trying to create an email alert that is based on a user defined % of a target value from a service calculation:

     

    var CurrentTime = new Date();
    var Midnight = new Date();
    Midnight.setHours(0,0,0,1);
    
    
    var params = {
    oldestFirst: true /* BOOLEAN */,
    maxItems: undefined /* NUMBER */,
    sourceTags: undefined /* TAGS */,
    endDate: CurrentTime /* DATETIME */,
    query: undefined /* QUERY */,
    source: source /* STRING */,
    startDate: Midnight /* DATETIME */,
    tags: undefined /* TAGS */
    };
    
    
    // result: INFOTABLE
    var result = Things["ApexReadingsStream"].QueryStreamEntriesWithData(params);
    
    var newField = new Object();
    newField.name = "Difference";
    newField.baseType = 'NUMBER';
    result.AddField(newField);
    
    var tableLength = result.rows.length;
    
    for (var x = 0; x < tableLength - 1; x++) {
        var newerRow = result.rows[x +1]
        var olderRow = result.rows[x];
        //row.Difference = row.Value-result.rows[x-1].Value;
        newerRow.Difference = (newerRow.Value-olderRow.Value) * 1000 ;
    }
    
    
    
    
    
    

     

     

    I am struggling to understand the concept of how to achieve this in thingworx?

     

    Any suggestions from anyone...

     

    Thanks

     

    Darryl