update metadata through workflow. | Community
Skip to main content
New Participant
January 22, 2024
Solved

update metadata through workflow.

I'm trying to update metadata with user id through workflow, when I was run the workflow on the particular that asset metadata should be update with the user id.

Write a workflow to save the name/id of the user on the metadata of the asset on which the workflow was run on in the field- "user id".

I need java code for this.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Mahesh_GunajeAccepted solution
Level 7
January 22, 2024

@nandigama_vamsi 

I hope this article might help you.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-do-we-get-current-aem-author-logged-in-user-id-in-osgi/m-p/322534

 

I hope you are aware of wring custom work flow process (Java which implements WorkflowProcess).  Here, you need to write the actual logic.

4 replies

Raja_Reddy
New Participant
January 22, 2024

Hi @nandigama_vamsi   
how to update the metadata of an asset with the user ID using a workflow

import com.adobe.granite.workflow.WorkflowSession; import com.adobe.granite.workflow.exec.WorkItem; import com.adobe.granite.workflow.exec.WorkflowData; import com.adobe.granite.workflow.metadata.MetaDataMap; import org.apache.sling.api.resource.ResourceResolver; public class UpdateMetadataWorkflowProcess { public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) { try { // Get the user ID String userId = workItem.getWorkflow().getInitiator(); // Get the asset path String assetPath = workItem.getWorkflowData().getPayload().toString(); // Get the resource resolver ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class); // Update the metadata of the asset Resource assetResource = resourceResolver.getResource(assetPath); ModifiableValueMap metadata = assetResource.adaptTo(ModifiableValueMap.class); metadata.put("user id", userId); resourceResolver.commit(); // Log the success message workflowSession.getWorkflowData().getMetaDataMap().put("success", "Metadata updated successfully"); } catch (Exception e) { // Log the error message workflowSession.getWorkflowData().getMetaDataMap().put("error", "Failed to update metadata: " + e.getMessage()); } } }


 Ref :
https://experienceleague.adobe.com/docs/experience-manager-65/content/implementing/developing/extending-aem/extending-workflows/workflows-step-ref.html?lang=en 

Translate
Level 7
January 22, 2024

Hi @raja_reddy   @nandigama_vamsi 

I have checked above logic by implementing WorkflowProcess .

 

public class UpdateMetadataWorkflowProcess implements WorkflowProcess { ...}

 

String userId = workitem.getWorkflow().getInitiator();
// value of userId: workflow-service

Session session = worksession.adaptTo(Session.class);
String userId = session.getUserID();
// value of userId: workflow-process-service

 

@nandigama_vamsi  are you expecting this user ID?  or the logged in user ID (the guy has uploaded the DAM asset).

 

Translate
New Participant
January 23, 2024

Thank you for the reply.

@raja_reddy 

@mahesh_gunaje 

 

when I'm run the workflow the asset metadata property user id field as to create and fill with my userid that logging.

Example if I login with admin, when I run the workflow the metadata property of user id field updated with admin.

              

Translate
Mahesh_GunajeAccepted solution
Level 7
January 22, 2024

@nandigama_vamsi 

I hope this article might help you.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-do-we-get-current-aem-author-logged-in-user-id-in-osgi/m-p/322534

 

I hope you are aware of wring custom work flow process (Java which implements WorkflowProcess).  Here, you need to write the actual logic.

Translate