// standard metadata structures variables.stdMetadata = structNew(); // variables.stdMetadata.pageID = 0; variables.stdMetadata.name = ""; variables.stdMetadata.title = ""; variables.stdMetadata.caption = ""; variables.stdMetadata.description = ""; variables.stdMetadata.globalKeywords = ""; variables.stdMetadata.categoryName = ""; variables.stdMetadata.subsiteID = ""; variables.stdMetadata.templateID = ""; // custom metadata structure variables.custMetadata = structNew(); // page data variables.pageID = 0; var i = 1; var j = 1; var k = 1; var dsmKey = ""; var customElementFormID = ""; var elementInformation = ""; var customData = ""; var stdMetadata = StructNew(); var textblockData =""; var data = StructNew(); var currentField = ""; // Use the flag in getCustomMetadata to convert Taxonomy Term Lists to TermID lists in taxonomy custom metadata fields var custMetadata = variables.csData.getCustomMetadata(pageid=arguments.sourcePageID,convertTaxonomyTermsToIDs=1); var sourcePage = variables.csData.getStandardMetadata(arguments.sourcePageID); var ccapiElements = ""; var newPage = ''; var elementTabs = ''; var populateContentResults = ''; var logStruct = StructNew(); try { //Error checking if ( ArrayLen(sourceNames) neq ArrayLen(destCCAPINames) ) { variables.utils.logAppend("Source custom element list is not the same length of custom element names.","copyPageLog.txt"); return false; } // Check to see if a destination standard metadata struct has been provided with any fields/values to be used to replace the Source page standard metadata values if ( !StructIsEmpty(arguments.destStandardMetadata) ) { for ( dsmKey IN arguments.destStandardMetadata ) { if ( StructKeyExists(sourcePage,dsmKey) ) sourcePage[dsmKey] = arguments.destStandardMetadata[dsmKey]; } } //Does the page exist? If so throw an exception telling them so if ( variables.csData.getCSPageByName(sourcePage.name,arguments.destinationSubsiteID) ) { variables.utils.logAppend("Page already exists: '#sourcePage.name#' in subsiteID: #arguments.destinationSubsiteID#","copyPageLog.txt"); return false; } //setup the stdMetadata from our source page stdMetadata = sourcePage; stdMetadata.templateID = arguments.destinationTemplateID; stdMetadata.subsiteID = arguments.destinationSubsiteID; //remove the pageid from the standard metadata StructDelete(stdMetadata,"pageid"); // Create the page newPage = createPage(stdMetadata,custMetadata); if(!newPage.pageCreated){//we couldnt create the page! Log the error and return out false. variables.utils.logAppend("There was an error while creating page: '#stdMetadata.name#' in subsiteID: #stdMetadata.subsiteID#","copyPageLog.txt"); return false; } //Page creation successful! newPageID = newPage.newPageID; variables.ccapi.initCCAPI(); ccapiElements = variables.ccapi.getElements(); //Iterate over each element and process the imports! for(i=1;i<=ArrayLen(arguments.sourceNames);i++){ //Verify the mapping exists if( !StructKeyExists(ccapiElements,arguments.destCCAPINames[i]) ){ variables.utils.logAppend("Destination element name #arguments.destCCAPINames[i]# is not mapped correctly in CCAPI configuration","copyPageLog.txt"); return false; } //Setup the data for each custom element data = StructNew(); data.subsiteID = arguments.destinationSubsiteID; data.pageID = newPageID; data.submitChange = 1; //If the element we are working with is a textblock handle things differently if(ccapiElements[arguments.destCCAPINames[i]].elementType eq "textblock"){ data.submitChange_comment = "Submit data for TextBlock through API"; //Get the textblock's data textblockData = variables.csData.getTextblockData(arguments.sourceNames[i],arguments.sourcePageID); data.textblock = textblockData.values.textblock; data.caption = textblockdata.values.caption; }else{ //this is a custom element. we know how to handle it! data.submitChange_comment = "Submit data for Custom element through API"; //Get the custom data customData = variables.ceData.getElementByNameAndCSPageID(arguments.sourceNames[i],arguments.sourcePageID); if(structIsEmpty(customData)){ variables.utils.logAppend("There was an error while getting element: '#sourceNames[i]#' from page: '#arguments.sourcePageID#'","copyPageLog.txt"); return false; } //Get the tabs, iterate over elementTabs = variables.ceData.getTabsFromFormID(customData.formID,true); //Iterate over each tab for(k=1;k<=ArrayLen(elementTabs);k++){ //Iterate over each field in the tab for(j=1;j<=ArrayLen(elementTabs[k].fields);j++){ //Get the current field for the current tab currentField = elementTabs[k].fields[j]; //Its a formatted text block! Fix the entities!} if(currentField.defaultValues.type == "formatted_text_block"){ customData.values[currentField.fieldName] = server.commonspot.udf.html.DECODEENTITIES(customData.values[currentField.fieldName]); } //Fill out data with the updated value data[currentField.fieldName] = customData.values[currentField.fieldName]; } } } //Populate the element with the data populateContentResults = application.ADF.csContent.populateContent(destCustomElementNames[i],data); if(!populateContentResults.contentUpdated){ variables.utils.logAppend("There was an error while updating element: '#destCustomElementNames[i]#' on page: '#stdMetadata.name#' in subsiteID: #stdMetadata.subsiteID#","copyPageLog.txt"); return false; } } //Log our success! variables.utils.logAppend("Page '#stdMetadata.name#' created in subsiteID: #stdMetadata.subsiteID# successfully.","copyPageLog.txt"); } catch ( ANY e ) { // Error caught // Log the error message also logStruct.msg = "#request.formattedTimestamp# - Error"; if ( StructKeyExists(e,"Message") AND LEN(TRIM(e.Message)) ) logStruct.msg = logStruct.msg & " [Message: #e.Message#]"; if ( StructKeyExists(e,"Details") AND LEN(TRIM(e.Details)) ) logStruct.msg = logStruct.msg & " [Details: #e.Details#]"; logStruct.logFile = "copyPageLog_errors.log"; ArrayAppend( logArray, logStruct ); variables.utils.bulkLogAppend(logArray); } return true;