variables.ElementName = getStorySectionCEName();
variables.CCAPIName = getCCAPIName(variables.elementName);
//variables.elementIDfield = "storyID";
if ( LEN(TRIM(arguments.uniqueID)) )
return application.npsStory.ceData.getCEData(variables.elementName, application.npsStory.appConfig.story.sectionFieldNames.UUID, TRIM(arguments.uniqueID));
else
return application.npsStory.ceData.getCEData(variables.elementName);
var dataArray = ArrayNew(1);
var dataStruct = StructNew();
var retStruct = StructNew();
var saveStatus = StructNew();
// Check to see if there is data in the element to be updated
if ( StructKeyExists(arguments.elementData, application.npsStory.appConfig.story.sectionFieldNames.UUID) AND LEN(TRIM(arguments.elementData[application.npsStory.appConfig.story.sectionFieldNames.UUID])) )
{
dataArray = getStorySection(uniqueID=arguments.elementData[application.npsStory.appConfig.story.sectionFieldNames.UUID]);
}
// If no record exists create one, if so update it
if ( NOT ArrayLen(dataArray) )
{
// Create the a new record
dataStruct = arguments.elementData;
// if no UUID field exists create one... but other we assume that a new UUID for this "new" data was already created
if ( NOT StructKeyExists(dataStruct, application.npsStory.appConfig.story.sectionFieldNames.UUID) )
dataStruct[application.npsStory.appConfig.story.sectionFieldNames.UUID] = createUUID();
// Set the update type
retStruct['type'] = 'created';
}
else
{
// Update the Record
// Set the existing values
dataStruct = dataArray[1].values;
// remove the UUID filed from the passed in data
if ( StructKeyExists(arguments.elementData, application.npsStory.appConfig.story.sectionFieldNames.UUID) )
StructDelete(arguments.elementData, application.npsStory.appConfig.story.sectionFieldNames.UUID);
// Override with the new values
// - Use the arguments.elementData to modify specific values for the keys in the dataStruct
StructAppend( dataStruct, arguments.elementData, true);
/*for ( key in arguments.elementData ) {
dataStruct[key] = arguments.elementData[key];
}*/
// Set the Page ID from the existing record
dataStruct.dataPageID = dataArray[1].PageID;
// Set the update type
retStruct['type'] = 'updated';
}
// Create the record
saveStatus = storySectionCCAPI(dataStruct);
// Build the status struct
if ( saveStatus['CONTENTUPDATED'] IS true )
retStruct['status'] = 'success';
else
retStruct['status'] = 'fail';
// Return the status struct
return retStruct;
var retStatusStruct = StructNew();
//application.ADF.utils.doDump(arguments.dataValues,"arguments.dataValues", false);
// Create the page
retStatusStruct = application.ADF.csContent.populateContent(variables.CCAPIName, arguments.dataValues);
/* retStatusStruct RETURNS: CONTENTUPDATED : true/false & CONTENTUPDATERESPONSE: Success:1 */