SeedCode Logo


fmxj.js
a JavaScript approach to FileMaker Custom Web Publishing™

gh LogoDownload on GitHub

editRecordURL(fileName, layoutName, editObj)

Create a FileMaker -edit or -new query url from a javascript object. These queries are then passed to the postQueryFMS() function which returns the results as a single object array.

fileName
Type: String
A String of the name of the hosted FileMaker file.
layoutName
Type: String
A String of the name of the target layout in the specified file.
editObj
Type: Object
An Object that specifies the changes to be made to the FileMaker record. Property names represent the FileMaker field names. Specifying a -recid property will edit the specified record with an -edit query. Not specifying the -recid will create a new FileMaker record with a -new query. The -modid property can be optionally specified to ensure you are editing the most current version of that record. See more about using the -mod id in FileMaker's XML CWP Guide
example 1
Create a new FileMaker record by not specifying the -recid in the edit object. If the record creation is succesful on the server, then the record will be returned and converted into an object.

var newRecord =	{
				"DateStart" : "02/25/2014" ,
				"DateEnd" : "02/25/2014" ,
				"Description" : "test" ,
				"Status" : "Open" ,
				"Summary" : "test summary ubi"
				} ;
var query = fmxj.editRecordURL("Events", "Events", newRecord) ;
fmxj.postQueryFMS(query, callBackFunction) ;

		
		
		
example 2
Specifying a -recid property in an object will create a edit query to edit the fields specified in the object. Retrieve the first record on the Events layout and toggle its status. If the status is open, set it to closed and vice-versa.

// query to find all records, unsorted and return the first one.
var query = fmxj.findRecordsURL("Events", "Events", null, null, 1);
fmxj.postQueryFMS(query,createEdit,null,relay); // Perform request
function createEdit(js){ //define handler for returned record
	var recid = js[0]["-recid"]; //retrieve record/object's -recid
	var modid = js[0]["-modid"]; //retrieve record/object's -modid
	var recordStatus = js[0]["Status"]; //retrieve record/object's status
	if ( recordStatus == "Open" ){ //toggle status
		 recordStatus = "Closed" 
	} 
	else {
		 recordStatus = "Open" 
	} ;
	var editObj = { //create new object to edit the record
		"-recid":recid,
		"-modid":modid,
		"Status":recordStatus,
				  };
	//create query from object
	var query = fmxj.editRecordURL("Events", "Events", editObj);
	fmxj.postQueryFMS(query,writeResult,null,relay); //POST edit query
	function writeResult(js){ //define handler for writing edited object.
		updateElement("example2", message, true);
	};
};