@Minh_Tri_Do_Hang
You are correct, it replaced the description field text. Here is a script that appends the Embedly at the top of the Description field, maintaining all content of it.
const fibery = context.getService('fibery');
for (const entity of args.currentEntities) {
// Use the UUID for the template entity ID
const templateEntityId = 'f8d9eee0-7192-11ee-b1a4-a584e4600b45';
// Fetch the content of the 'Description' field from the template entity
const templateEntity = await fibery.getEntityById('Y Web Resource', templateEntityId, ['Description']);
const templateDescriptionContent = await fibery.getDocumentContent(templateEntity['Description'].Secret, 'html');
console.log('Template Description Content:', templateDescriptionContent);
// Fetch the current content of the 'Description' field from the entity
const currentDescriptionContent = await fibery.getDocumentContent(entity['Description'].Secret, 'html');
console.log('Current Description Content:', currentDescriptionContent);
// Extract the first URL from the current description content
const currentLink = currentDescriptionContent.match(/(https?:\/\/[^\s]+)/);
console.log('Current Link:', currentLink);
// Extract the URL from the template description content
const templateLink = templateDescriptionContent.match(/(https?:\/\/[^\s]+)/);
console.log('Template Link:', templateLink);
// Replace the template URL with the current URL in the template description content
const newTemplateDescriptionContent = templateDescriptionContent.replace(templateLink[0], currentLink[0]);
console.log('New Template Description Content:', newTemplateDescriptionContent);
// Append the modified template description content to the top of the current description content
const newDescriptionContent = newTemplateDescriptionContent + currentDescriptionContent;
console.log('New Description Content:', newDescriptionContent);
// Update the 'Description' field of the entity with the new content
await fibery.setDocumentContent(entity['Description'].Secret, newDescriptionContent, 'html');
}
- It fetches the first URL from the current entity’s Description field.
- It fetches the complete HTML content of the Template Description field.
- It extracts the URL from the Template Description field.
- It replaces the template URL with the current URL in the Template Description content.
- It appends the modified Template Description content to the top of the current entity’s Description field.
So this is the replacement of Script 2 mentioned before.