Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

Programmatically change asset name

Avatar

Level 4

Is this possible?

Couldn't find any methods in the API to do so.

 

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Try calling the MoveAsset method that belongs to this API:

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/adobe/granite/asset/api/AssetManager.html#moveAs..., java.lang.String)

Parameters:
assetPath - Absolute path of the asset to be moved
destAbsPath - Absolute path at with asset is to be moved

for destAbsPath  - specify the new name of the Asset.

To learn how to use the granite AssetManager API - see this article: 

https://helpx.adobe.com/experience-manager/using/graniteAPI.html (tested on AEM 6)

View solution in original post

8 Replies

Avatar

Correct answer by
Level 10

Try calling the MoveAsset method that belongs to this API:

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/adobe/granite/asset/api/AssetManager.html#moveAs..., java.lang.String)

Parameters:
assetPath - Absolute path of the asset to be moved
destAbsPath - Absolute path at with asset is to be moved

for destAbsPath  - specify the new name of the Asset.

To learn how to use the granite AssetManager API - see this article: 

https://helpx.adobe.com/experience-manager/using/graniteAPI.html (tested on AEM 6)

Avatar

Level 4

smacdonald2008 wrote...

Try calling the MoveAsset method that belongs to this API:

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/adobe/granite/asset/api/AssetManager.html#moveAs..., java.lang.String)

Parameters:
assetPath - Absolute path of the asset to be moved
destAbsPath - Absolute path at with asset is to be moved

for destAbsPath  - specify the new name of the Asset.

To learn how to use the granite AssetManager API - see this article: 

https://helpx.adobe.com/experience-manager/using/graniteAPI.html (tested on AEM 6)

 


Thank you Scott

Avatar

Level 3

smacdonald2008 Do AssetManager.moveAsset() method update the asset references as well in all the content or do we need to specifically handle it by writing custom code? When using "Move" option from author instance in Assets, it does update the content references of that particular asset which is moved, so wanted to confirm does API handle it automatically as well?

Avatar

Level 10

If you mean does it update in all pages referencing it - the answer is no. That is --  if you have a page referencing an asset in the DAM and you change the name - the reference in the page is not updated,

Avatar

Level 3

I am actually trying to figure what AEM uses internally when "Move" option is used from Assets UI. When the author Move an asset from Assets UI to a new destination, then all the pages where that asset was referenced, are automatically updated by AEM with the new destination path of the Asset. I need to do this Move from through a script, so thought of confirming if any API is there, which does update the references automatically or will I have to run queries to find all references and then update those references manually.

Avatar

Level 2

You can use CopyMoveCommandBuilder.java from package "com.day.cq.wcm.command.api" on 6.4.

e.g. :

@Reference
CommandBuilderFactory commandBuilderFactory;

CopyMoveCommandBuilder copyMoveCommandBuilder= commandBuilderFactory.createCommandBuilder(CopyMoveCommandBuilder.class).withCopy(false);

CopyMoveCommandPathArgument copyMoveCmdPathArg =

  (CopyMoveCommandPathArgument) copyMoveCommandBuilder.createPathArgumentBuilder()

  .withSrcPath(srcPath)

  .withDstPath(dstPath)

  .withAdjustRefPaths(adjustRefs)

  .withPublishPaths(publishRefs)

  .build();
   copyMoveCommandBuilder.withResourceResolver(resolver)

  .withAssetReferenceResolver(assetRefResolver)

  .withRetrieveAllRefs(true).withShallow(true)

  .withCheckIntegrity(true).withBeforeName(before)

  .withPathArgument(copyMoveCmdPathArg);
}

Command cmd = copyMoveCommandBuilder.build();
CopyMoveCommandResult result = (CopyMoveCommandResult)cmd.execute();

You need collect all the references and provide to this.

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now