dynamic http put

Hi all,

I am trying to figure out a way to update any fields with xml sent as a body over http. I could hard code all 102 columns into the ws_read, but their names are always changing and we’re always adding and removing columns.

I was wondering if there was a way to use jsTable.getColumnNames() to put the column names in an array then match any columns in XML to the columns in the array. Kind of like this:

/**
 * // TODO generated, please specify type and doc for the params
 * 
 * @param {Object} part
 * 
 * @param {String} id
 * 
 * 
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"8CADE4C5-727A-4889-BE9F-F204A88F9F06"}
 * 
 * @AllowToRunInFind
 */
function ws_update(part, id){
	if(part && id && foundset.find())
	{
		foundset.fld1 = id
		if(foundset.search() == 1)
		{
			
			[b]var jsTable = databaseManager.getTable(foundset)
			var columnNames = jsTable.getColumnNames()[/b]
			
			
			var record = foundset.getRecord(1)
			if(part.fld1 && id != part.fld1) record.fld1 = part.fld1
			[b]if(part.columnNames) record.columnNames = part.columnNames[/b]
			//if(part.fld2) record.fld2 = part.fld2
			return databaseManager.saveData(record)
			
			
			}
			
		}
			return false
		}

I found the answer I was looking for.

Instead of using only one object property at a time from the xml data like so:

var record = foundset.getRecord(1);
if (emp.id && id != emp.id) record.employeeid = emp.id
if (emp.firstName) record.firstname = emp.firstName
if (emp.lastName) record.lastname = emp.lastName
return databaseManager.saveData(record)

One can use the in operator to use all emp properties and compare your tag names to column names in a foundset:

function ws_update(emp, id)
{
	// update 1 part
	if (data && id && foundset.find())
	{
		foundset.fld1 = id
		if (foundset.search() == 1)
		{
			var record = foundset.getRecord(1);
			for (var x in emp)
			{
				var fieldname = x.toString()
				if (record[fieldname]) record[fieldname] = data[fieldname]
			}
			
			return databaseManager.saveData(record)
		}
	}
	
	
	return false
}