// Get the sync mapping data for the source form ID
var syncMapDataArray = application.ptSync.syncDAO.getSyncMapping(sourceCEFormID=arguments.srcFormID);
// Get the source formid data for the rec ID
var srcCEDataStruct = application.ptSync.ceData.getElementInfoByPageID(pageid=arguments.srcDataPageID, formid=arguments.srcFormID);
// Get the field names for the UUID and ParentUUID fields
var uuidName = application.ptSync.ceData.getElementFieldName(formID=syncMapDataArray[1].values.sourceCE, fieldID=syncMapDataArray[1].values.uuidField);
// Get the destionation CE Data
var destCEDataArray = "";
var destDataStruct = StructNew();
var ccapiStatus = StructNew();
try {
// Verify the rules for the CE to run the sync
if ( application.ptSync.syncService.verifyRules(sourceCEData=srcCEDataStruct) ) {
// Get the destionation CE Data
destCEDataArray = application.ptSync.syncDAO.getDestCEData(formID=syncMapDataArray[1].values.destCE,
uuidValue=srcCEDataStruct.values[uuidName],
uuidFieldName=uuidName);
// Check if the data exists on the destination site
if ( ArrayLen(destCEDataArray) ){
// Set the new data based on the source data set
destDataStruct = srcCEDataStruct.values;
destDataStruct[uuidName] = destCEDataArray[1].values[uuidName];
destDataStruct.datapageid = destCEDataArray[1].pageid;
}
else {
// Create the new record on the destination site
// Set the new data based on the source data set
destDataStruct = srcCEDataStruct.values;
destDataStruct[uuidName] = srcCEDataStruct.values[uuidName];
}
// Check if the UUID Field is a UUID value before updating to the destination
if ( application.ptSync.data.isCFUUID(destDataStruct[uuidName]) ){
// Validate the complex field types
destDataStruct = application.ptSync.syncService.validateComplexFields(destCEData=destDataStruct, srcFormID=syncMapDataArray[1].values.sourceCE);
// Create/Update the custom element on the destination site
ccapiStatus = application.ptSync.syncDAO.setDestCE(formID=syncMapDataArray[1].values.sourceCE,dataStruct=destDataStruct);
}
/*
application.ADF.utils.dodump(uuidName,"uuidName",false);
application.ADF.utils.dodump(syncMapDataArray,"syncMapDataArray",false);
application.ADF.utils.dodump(srcCEDataStruct,"srcCEDataStruct",false);
application.ADF.utils.dodump(destCEDataArray,"destCEDataArray",false);
application.ADF.utils.dodump(destDataStruct,"destDataStruct",false);
application.ADF.utils.dodump(ccapiStatus,"ccapiStatus",false);
*/
if ( StructKeyExists(ccapiStatus, "CONTENTUPDATED") AND (ccapiStatus.CONTENTUPDATED EQ true) ){
// Log the success sync
application.ptSync.syncService.setLog(message="Sync complete for Form ID [#arguments.srcFormID#] and Data Page ID [#arguments.srcDataPageID#]");
// Run the post sync hook
application.ptSync.syncService.postSyncHook(srcCEDataStruct);
// Return status
return ccapiStatus.CONTENTUPDATED;
}
else {
// Log the CCAPI error
if ( StructKeyExists(ccapiStatus, "msg") ) {
// Log the CCAPI failed for the Sync
application.ptSync.syncService.setLog(message="Sync Error with CCAPI. [Message: #ccapiStatus.msg#] for Form ID [#arguments.srcFormID#] and Data Page ID [#arguments.srcDataPageID#]",
state="fail");
}
else {
// Log the processing failed for the Sync
application.ptSync.syncService.setLog(message="Sync Error. Form ID [#arguments.srcFormID#] and Data Page ID [#arguments.srcDataPageID#]",
state="fail");
}
}
}
// Encountered error with processing the sync
}
catch (Any e){
// Log the processing failed for the Sync
application.ptSync.syncService.setLog(message="Sync Processing Error [#e.message#]. Form ID [#arguments.srcFormID#] and Data Page ID [#arguments.srcDataPageID#]",
state="fail");
}
return false;
var scheduleParams = StructNew();//Default Values
var commandArray = ArrayNew(1);
try {
// Delay and Records to run
scheduleParams.delay = application.ptSync.appConfig.schedDelay;
scheduleParams.tasksPerBatch = application.ptSync.appConfig.schedRecords;
// Build the Command Array Data
commandArray[1] = StructNew();
commandArray[1].bean = "syncController";
commandArray[1].method = "processSync";
commandArray[1].args = StructNew();
commandArray[1].args.srcFormID = arguments.srcFormID;
commandArray[1].args.srcDataPageID = arguments.srcDataPageID;
commandArray[1].args.srcControlID = arguments.srcControlID;
// Schedule the sync for the active content
application.ptSync.scheduler.scheduleProcess(scheduleName="PT-Sync-#arguments.srcFormID#-#arguments.srcDataPageID#",
commands=commandArray,
scheduleParams=scheduleParams,
startProcessNow=false);
// No problems, return
return true;
}
catch ( Any e ){
application.ptSync.syncService.setLog(message="Sync Error with Scheduling. [Message: #e.message#] - Form ID [#arguments.srcFormID#] - Data Page ID [#arguments.srcDataPageID#] - Control ID [#arguments.srcControlID#]",
state="fail");
return false;
}
// Get the UUID Field Name
var uuidFieldName = application.ptSync.ceData.getElementFieldName(formID=arguments.srcFormID,
fieldID=arguments.srcUUIDFieldID);
// Get the data page ID for the record based on UUID
var srcDataArray = application.ptSync.ceData.getCEData(
application.ptSync.ceData.getCENameByFormID(arguments.srcFormID),
uuidFieldName,
arguments.srcUUID);
try {
// Check that we have source data, then call the process sync
if ( ArrayLen(srcDataArray) EQ 1 ){
// Check the run time sync is enabled
if ( application.ptSync.appConfig.runTimeSync ){
// Run the SYNC for the record
syncStatus = processSync(srcFormID=arguments.srcFormID, srcDataPageID=srcDataArray[1].pageid);
}
else {
// Schedule the SYNC for the record
syncStatus = scheduleSync(srcFormID=attributes.inputStruct.formid, srcDataPageID=attributes.inputStruct.pageID);
}
}
else{
// Throw error Message for no source data
throw(type="Custom",
message="Source data not found for form ID [#arguments.srcFormID#]",
detail="Source data not found for form ID [#arguments.srcFormID#]");
}
// No problems, return
return true;
}
catch ( Any e ){
application.ptSync.syncService.setLog(message="Sync Error with Processing New Global Element. [Message: #e.message#] - Form ID [#arguments.srcFormID#] - Data Page ID [#srcDataArray[1].pageid#]",
state="fail");
return false;
}
var scheduleParams = StructNew();//Default Values
var commandArray = ArrayNew(1);
try {
// Delay and Records to run
scheduleParams.delay = application.ptSync.appConfig.schedDelay;
scheduleParams.tasksPerBatch = application.ptSync.appConfig.schedRecords;
// Build the Command Array Data
commandArray[1] = StructNew();
commandArray[1].bean = "syncController";
commandArray[1].method = "processDeleteSync";
commandArray[1].args = StructNew();
commandArray[1].args.srcFormID = arguments.srcFormID;
commandArray[1].args.srcDataPageID = arguments.srcDataPageID;
commandArray[1].args.srcControlID = arguments.srcControlID;
// Schedule the sync for the active content
application.ptSync.scheduler.scheduleProcess(scheduleName="PT-Sync-Delete-#arguments.srcFormID#-#arguments.srcDataPageID#",
commands=commandArray,
scheduleParams=scheduleParams,
startProcessNow=false);
// No problems, return
return true;
}
catch ( Any e ){
application.ptSync.syncService.setLog(message="Sync Error with Scheduling Delete Local Element. [Message: #e.message#] - Form ID [#arguments.srcFormID#] - Data Page ID [#arguments.srcDataPageID#] - Control ID [#arguments.srcControlID#]",
state="fail");
return false;
}
var scheduleParams = StructNew();//Default Values
var commandArray = ArrayNew(1);
// Get the destionation CE Data
var destCEDataArray = ArrayNew(1);
var syncMapDataArray = "";
var srcCEDataStruct = "";
var uuidName = "";
try {
// Get the sync mapping data for the source form ID
syncMapDataArray = application.ptSync.syncDAO.getSyncMapping(sourceCEFormID=arguments.srcFormID);
// Get the source formid data for the rec ID
srcCEDataStruct = application.ptSync.ceData.getElementInfoByPageID(pageid=arguments.srcDataPageID, formid=arguments.srcFormID);
// Get the field names for the UUID and ParentUUID fields
uuidName = application.ptSync.ceData.getElementFieldName(formID=syncMapDataArray[1].values.sourceCE, fieldID=syncMapDataArray[1].values.uuidField);
// Verify the rules for the CE to run the sync
if ( isStruct(srcCEDataStruct) AND application.ptSync.syncService.verifyDeleteRules(srcCEDataStruct) ) {
// Get the destionation CE Data
destCEDataArray = application.ptSync.syncDAO.getDestCEData(formID=syncMapDataArray[1].values.destCE,
uuidValue=srcCEDataStruct.values[uuidName],
uuidFieldName=uuidName);
// Check if the data exists on the destination site
if ( ArrayLen(destCEDataArray) ){
// Delay and Records to run
scheduleParams.delay = application.ptSync.appConfig.schedDelay;
scheduleParams.tasksPerBatch = application.ptSync.appConfig.schedRecords;
// Build the Command Array Data
commandArray[1] = StructNew();
commandArray[1].bean = "syncDAO";
commandArray[1].method = "deleteDestCE";
commandArray[1].args = StructNew();
commandArray[1].args.srcFormID = arguments.srcFormID;
commandArray[1].args.destFormID = destCEDataArray[1].formid;
commandArray[1].args.pageID = destCEDataArray[1].pageid;
// Schedule the sync for the active content
application.ptSync.scheduler.scheduleProcess(scheduleName="PT-Sync-Delete-#arguments.srcFormID#-#arguments.srcDataPageID#",
commands=commandArray,
scheduleParams=scheduleParams,
startProcessNow=false);
// No problems, return TRUE
return true;
}
}
}
catch ( Any e ){
application.ptSync.syncService.setLog(message="Sync Error with Scheduling Delete Global Element. [Message: #e.message#] - Form ID [#arguments.srcFormID#] - Data Page ID [#arguments.srcDataPageID#]",
state="fail");
return false;
}
return false;
// Get the sync mapping data for the source form ID
var syncMapDataArray = application.ptSync.syncDAO.getSyncMapping(sourceCEFormID=arguments.srcFormID);
// Get the CE Data versions
var srcCEDataVersionQry = application.ptSync.ceData.getElementVersionsForPageID(pageid=arguments.srcDataPageID,
formid=arguments.srcFormID,
controlid=arguments.srcControlID);
// Get the latest CE version from the Array
var srcCEDataArray = application.ptSync.ceData.getElementInfoVersionsByPageID(pageid=arguments.srcDataPageID,
formid=arguments.srcFormID,
versionID=srcCEDataVersionQry.versionID[srcCEDataVersionQry.recordCount],
controlid=arguments.srcControlID);
// Get the field names for the UUID and ParentUUID fields
var uuidName = application.ptSync.ceData.getElementFieldName(formID=syncMapDataArray[1].values.sourceCE, fieldID=syncMapDataArray[1].values.uuidField);
// Get the destionation CE Data
var destCEDataArray = "";
var destDataStruct = StructNew();
var delStatus = false;
// Verify the rules for the CE to run the sync
if ( ArrayLen(srcCEDataArray) AND application.ptSync.syncService.verifyDeleteRules(srcCEDataArray[1]) ) {
// Get the destionation CE Data
destCEDataArray = application.ptSync.syncDAO.getDestCEData(formID=syncMapDataArray[1].values.destCE,
uuidValue=srcCEDataArray[1].values[uuidName],
uuidFieldName=uuidName);
// Check if the data exists on the destination site
if ( ArrayLen(destCEDataArray) ){
// Delete the destination CE Data
delStatus = application.ptSync.syncDAO.deleteDestCE(srcFormID=arguments.srcFormID,
destFormID=destCEDataArray[1].formid,
pageID=destCEDataArray[1].pageid);
// If Delete failed, then log error
if ( delStatus EQ FALSE ){
application.ptSync.syncService.setLog(message="Sync Error with Delete. [Message: None] - Form ID [#arguments.srcFormID#] - Data Page ID [#arguments.srcDataPageID#] - Control ID [#arguments.srcControlID#]",
state="fail");
}
}
}
// TODO - Add error handling
return delStatus;
var retHTML = "Dude!";
var scheduleParams = StructNew();
// Get the sync mapping data record
var syncMapArray = application.ptSync.syncDAO.getSyncMapping(mappingID=arguments.mappingID);
// Set the scheduler name
var schedulerName = "PT-Sync-Auto-" & syncMapArray[1].values.sourceCE;
// Get all the schedules for the this task
//var schedTasksArray = application.ptSync.scheduler.getScheduledTasks(taskNameFilter=schedulerName);
var schedTasksArray = application.ptSync.scheduler.getScheduleStatus(scheduleName=schedulerName);
//application.ptSync.utils.dodump(schedTasksArray, "schedTasksArray", false);
if ( schedTasksArray.status EQ "active" OR schedTasksArray.status EQ "paused" ) {
// Get the current schedule status
retHTML = application.ptSync.syncService.buildDBHtmlActive(mappingID=arguments.mappingID, scheduleTaskName=schedulerName);
}
else if ( schedTasksArray.status EQ "complete" ) {
// Get the current schedule status
retHTML = application.ptSync.syncService.buildDBHtmlComplete(mappingID=arguments.mappingID, scheduleTaskName=schedulerName);
}
else {
retHTML = application.ptSync.syncService.buildDBHtmlNoSched(mappingID=arguments.mappingID);
}
return retHTML;
var retHTML = "Dude!";
var scheduleParams = StructNew();
var scheduleCommandData = ArrayNew(1);
// Get the sync mapping data record
var syncMapArray = application.ptSync.syncDAO.getSyncMapping(mappingID=arguments.mappingID);
// Set the scheduler name
var schedulerName = "PT-Sync-Auto-" & syncMapArray[1].values.sourceCE;
// Get all the schedules for the this task
//var schedTasksArray = application.ptSync.scheduler.getScheduledTasks(taskNameFilter=schedulerName);
var schedTasks = application.ptSync.scheduler.getScheduleStatus(scheduleName=schedulerName);
//application.ptSync.utils.dodump(schedTasksArray, "schedTasksArray", false);
if ( schedTasks.status EQ "active" ) {
}
else {
// Build New Scheduler Task
scheduleCommandData = application.ptSync.syncService.buildAutoSchedulerData(mappingID=arguments.mappingID);
// Call the Scheduler
if ( ArrayLen(scheduleCommandData) ) {
// Delay and Records to run
scheduleParams.delay = application.ptSync.appConfig.schedDelay;
scheduleParams.tasksPerBatch = application.ptSync.appConfig.schedRecords;
// Schedule the sync for the active content
application.ptSync.scheduler.scheduleProcess(scheduleName=schedulerName,
commands=scheduleCommandData,
scheduleParams=scheduleParams,
startProcessNow=false);
}
// Get the current schedule status
//retHTML = application.ptSync.scheduler.getScheduleHTML(scheduleName=schedulerName);
retHTML = application.ptSync.syncService.buildDBHtmlActive(mappingID=arguments.mappingID, scheduleTaskName=schedulerName);
}
return retHTML;
var httpRet = "";