updateRecord updates all un-named field as undefined

hi I am tring to try the updateRecord() , update one record with id = 1 in Cats. I only want to change the name to “test”, once I run the code, the name is changed to “test”, all other fields are changed to “undefined”. Can someone explain this to me?

updateRecord(“Cats”, {id:2, Name:‘Test’}, function(record, success) {

});

Second questions is : in java scripts, if the filed is “Maximum Life Span”, with spaces in between words, it will give a compile erreo. but in the data table in app lab, there are so many fields with the multiple words and spaces among them. should we manally edit the table in order to access it in the code?

Thanks.

Please share a link to the project.

updateRecord updates the entire record. Any columns that are not specified will be set to undefined. Normally you would use readRecords and then change the record you get before using updateRecord. In that way, any unaltered columns are left the same.

Column names with spaces can be represented as strings. So you could do something like this readRecords("Cats",{"Name":"Abyssinian"},gotResults); if you needed to.

When manipulating a record you can either do this record.Name or this record.["Name"] if you need to.

It can be a nuisance to call readRecords every time you need to update. A good idea is to create a function that automatically does this for you.

function UpdateRecord(table, record ,callback){
   readRecords(table, {id:record.id}, function(records){ //read the records with the id provided
      for (var prop in records[0]){ //iterate through the record's properties
         if (!record[prop]){ //if the parameter does not include the property
            record[prop]=records[0][prop]; //then add it
         }
      }
      updateRecord(table,record,callback); //call updateRecord
   }
}