How to publish content fragment reference as part of workflow | Community
Skip to main content
New Participant
February 6, 2024
Solved

How to publish content fragment reference as part of workflow

  • February 6, 2024
  • 3 replies
  • 1242 views

Hello Team,

 

We're on 6.5.14, We have content fragments like news/articles, as part of authoring, authors associcate the assets like images or tags to CFs. And to publish these CFs we use custom workflow for approval. CFs is publishing fine after approval but the assoicated assets like images / tags aren't publishing. And more ever, in the DAM no way to select the reference assets while creating workflow (assets workflow isn't a wizard like page workflow). Is there way to publish the references of CFs in custom workflow .?

 

Thanks,

Venkat

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anish-Sinha

Hi @madalavenkat7 ,

The OOTB workflow step "Activate Page/Asset" is not suitable for this scenario. It is necessary to create a custom workflow process step where you can incorporate the code to replicate pages/assets/CF and their related assets.

AssetReferenceSearch API can be of use

 

Helpful links:

 https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq/dam/commons/util/AssetReferenceSearch.html

 

Sample code:

https://www.flexibledesigns.rs/activate-a-page-programmatically/

 

3 replies

SureshDhulipudi
New Participant
February 11, 2024

Write a custom workflow to include a step for attached / referenced / associated assets etc.

You need to identify the assets that are associated with the CF. You can do this by traversing the CF's structure and collecting all the references to assets.

 

=== sample code structure ===

import com.day.cq.dam.api.Asset;
import com.day.cq.replication.Replicator;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Reference;

public class PublishCFCustomWorkflowProcess implements WorkflowProcess {

@3214626
private Replicator replicator;

@9944223
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
try {
ResourceResolver resolver = workflowSession.adaptTo(ResourceResolver.class);
PageManager pageManager = resolver.adaptTo(PageManager.class);
Page page = pageManager.getContainingPage(workItem.getWorkflowData().getPayload().toString());

// Get the associated assets
List<Asset> assets = getAssociatedAssets(page);

// Publish the associated assets
for (Asset asset : assets) {
replicator.replicate(workflowSession.getSession(), ReplicationActionType.ACTIVATE, asset.getPath());
}
} catch (Exception e) {
throw new WorkflowException("Failed to publish associated assets", e);
}
}

private List<Asset> getAssociatedAssets(Page page) {
// Implement this method to return the list of assets associated with the page

//You need to identify the assets that are associated with the CF. You can do this by traversing the CF's structure and collecting all the references to assets.
}
}

Imran__Khan
New Participant
February 11, 2024

@madalavenkat7 This require a custom code with the same or next workflows process step to identify the assets eligible for replication.

Anish-Sinha
Anish-SinhaAccepted solution
Employee
February 6, 2024

Hi @madalavenkat7 ,

The OOTB workflow step "Activate Page/Asset" is not suitable for this scenario. It is necessary to create a custom workflow process step where you can incorporate the code to replicate pages/assets/CF and their related assets.

AssetReferenceSearch API can be of use

 

Helpful links:

 https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/index.html?com/day/cq/dam/commons/util/AssetReferenceSearch.html

 

Sample code:

https://www.flexibledesigns.rs/activate-a-page-programmatically/