Expand my Community achievements bar.

SOLVED

How to publish content fragment reference as part of workflow

Avatar

Level 2

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

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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...

 

Sample code:

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

 

View solution in original post

3 Replies

Avatar

Correct answer by
Employee Advisor

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...

 

Sample code:

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

 

Avatar

Level 10

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

Avatar

Community Advisor

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 {

@reference
private Replicator replicator;

@Override
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.
}
}