SaveRecord Method

The SaveRecord call is used to save new or existing records.

Parameters

  • Record
    • The record object to save.  If a new object is being created, only the RecordTypeName and custom fields need to be populated.

Returns

  • recordID
    • The record ID that was saved.

Usage

This is the universal method for saving new and existing records.  If you have a new record, you can save it using the code example below.  If you have an existing record, such as one retrieved from a GetRecord call, you can simply change the fields in the Record object as necessary and save it using this call.  Any fields that have not been changed will not be affected.

Note: The integer value returned from using the UGC “SaveRecord” method is the primary key of that inserted record.

SaveRecord call in JavaScript

//construct a new record object
//the RecordTypeName is required, specified in Agility
//the FirstName and LastName fields are custom fields
var record = {
	RecordTypeName: "Profile", 
	EmailAddress: "John@Doe.com",
	FirstName: "John"
}

//invoke the SaveRecord method with a known recordID variable
Agility.UGC.API.SaveRecord(record, function(data) {	
	
	if (data.ResponseType != Agility.UGC.API.ResponseType.OK) {
		//error occurred
		alert("An error occurred: " + data.Message);			
	} else {
		//data.ResponseData is the recordID of the saved record.
		var recordID = data.ResponseData;		
	}
});

//if you have a custom cache key that you wanted to invalidate the cache for, you would use the following:
var cacheKey = "MyCacheKey";  //normally this key will be a computed value, possibly container an id from another record.

Agility.UGC.API.SaveRecord(record, function(data) {	
	
	if (data.ResponseType != Agility.UGC.API.ResponseType.OK) {
		//error occurred
		alert("An error occurred: " + data.Message);			
	} else {
		//data.ResponseData is the recordID of the saved record.
		var recordID = data.ResponseData;		
	}
}, cacheKey);
                    

SaveRecord call in C#

//construct a new record object
//the RecordTypeName is required, specified in Agility
//the FirstName and LastName fields are custom fields
Record userRecord = new Record();
userRecord.RecordTypeName = "Profile";
userRecord["EmailAddress"] = email;
userRecord["FirstName"] = name;

using (Agility_UGC_API_WCFClient client = DataServiceUtil.GetUGCClient())
{
   DataServiceAuthorization auth =
     DataServiceUtil.GetDataServiceAuthorization(-1);

   int recordID = client.SaveRecord(auth, record);

}


//if you have a custom cache key that you wanted to invalidate the cache for, you would use the following:
var cacheKey = "MyCacheKey";  //normally this key will be a computed value, possibly container an id from another record.
using (Agility_UGC_API_WCFClient client = DataServiceUtil.GetUGCClient())
{
   DataServiceAuthorization auth =
     DataServiceUtil.GetDataServiceAuthorization(-1);

   int recordID = client.SaveRecord(auth, record, cacheKey);

}
                    

SaveRecord call in PHP

//construct a new record object
//the RecordTypeName is required, specified in Agility
//the FirstName and LastName fields are custom fields

RecordTypeName = “Profile”;
		$record->Values[0]->Key = “EmailAddress”;
		$record->Values[0]->Value = “John@Doe.com”;
		$record->Values[1]->Key = “FirstName”;
		$record->Values[1]->Value = “John”;
			
		
		$newID = $client->SaveRecord($record);
		
		echo "New record created with RecordID = $newID”;
  ?>
                    

LOGIN

Log in with your Agility username and password or
register for the site




Log In

REGISTER












Register

FORGOT PASSWORD