Jump to content

chob1234

Members
  • Posts

    8
  • Joined

  • Last visited

Posts posted by chob1234

  1. Confused on why my toFixed(2) function is not rounding my output. Located at the bottom of my code here. My output is "501327.3600770543"

    //// Get the sq inch. for BuildIDs that start with AA and 
    //// sets value to the "result" variable
    var result=0;
    var params = {
    	maxItems: 100000 /* NUMBER */
    };
    
    //// result: INFOTABLE
    var itPartInfo = Things["Training.InfoTable.PartInfo"].GetDataTableEntries(params);
    
    // Return square inches of Oak needed for each build ID that starts with AA
    // Like type filters by a like criteria
    // filters rows from Infotable PartInfo
    var query = {
      filters: {
        "type": "AND",
        filters: 
        [
          {
            "fieldName": "BuildID",
            "type": "LIKE",
            "value": "AA*"
          },
          {
            "fieldName": "MaterialType",
            "type": "EQ",
            "value": "Oak"
          }
        ]
      }
    };
    var oakparams = {
    	t: itPartInfo /* INFOTABLE */,
    	query: query /* QUERY */
    };
    
    // result: INFOTABLE
    var sqresult = Resources["InfoTableFunctions"].Query(oakparams);
    
    //Infotable for loop snippet
    var tableLength = sqresult.rows.length;
    
    // for loop will loop through itPartInfo, calculate the sq. in. for each part that starts with AA and return 
    // sq. in. in "result"
    for (var x = 0; x < tableLength; x++) {
    	var row = sqresult.rows[x];
        	//Your code here
        	//+= addition assignment operator is basically same as "x = x + y"
        result += (row.Height*row.Width);
        result.toFixed(2);
    }
    
    

     

  2. Yeah I think you are right on that, I believe the only way as of now in the thingworx platform to remove undesired columns is the .removeField("field") function, which you would have to have a function for every single column which is very inconvenient. 

  3. var params = {
    	maxItems: 100000 /* NUMBER */
    };
    
    //// result: INFOTABLE
    var itPartInfo = Things["Training.InfoTable.PartInfo"].GetDataTableEntries(params);
    
    ///*****************************************
    
    //	ADD YOUR CODE BELOW
        
    //*****************************************/
    
    var query = {
      "filters": {
        "fieldName": "ID",
        "type": "EQ",
        "value": partID
      }
    //partID is an input
    };
    
    var idQuery = {
    	t: itPartInfo /* INFOTABLE */,
    	query: query /* QUERY */
    };
    
    //// result: INFOTABLE
    var result = Resources["InfoTableFunctions"].Query(idQuery);

    So this code will return an item in an infotable(thingworx) which is basically an array of objects, it can also be thought of as a table where the array entries are rows and the object properties of each object in the array are the columns. So currently my output is displaying what I have correctly, I need to know how I could display say partID, Color, and MaterialType, my thinking was a I could use a sort function like 

    var sort = new Object();
    sort.name = Color;
    sort.ascending = True;
    itPartInfo.Sort(sort);

    But I am getting errors. Any suggestions?

  4. 6 minutes ago, justsomeguy said:

     

    
    if(isNumeric(parseInt <= 10000)) {

     

    What exactly are you trying to do there?  parseInt is a function, why are you trying to check if a function is less than or equal to 10000?

    Yeah I am not sure exactly, I guess the goal is to convert the string input to an int, but confused.

  5. 19 hours ago, Funce said:

    You could create a function to check if the number can be converted.

    
    function isNumeric(n) {
      return !isNaN(parseFloat(n)) && isFinite(n);
    }

    Then all you need to do is

    
    if(isNumeric(someNumber)) {
      //You have a number
    } else {
      //You don't have a number
    }

    Implement parseInt as required.

    Use console.log as specified in your post.

    So I came up with this:

    function isNumeric(string) {
      return !isNaN(parseInt(string)) && isFinite(string);
    }
    
    if(isNumeric(parseInt <= 10000)) {
      //You have a number
    logger.debug("You have a number")
    
    } else {
      //You don't have a number
      logger.debug("This cannot be a number")
    }

    It only outputs "This cannot be a number"

    What am I doing wrong?

    I am logging in Thingworx so that is where the logger.debug is coming from.

  6. I am needing to convert an String input into an Integer.  But before converting the String input, i have to do a validation that the String input can be converted to a numeric value. So If it cannot, i need to log a message saying “This cannot”.  Then log another new log statement on the next line saying “be a number”. I understand I need a parseInt and isNan and if else statements but I am confused on exactly how they are implemented. I am new to javascript. 

×
×
  • Create New...