Is it possible to set the Media in FS_REFERENCE Through Bean Shell
Author: vasanth
Publication Date: 3/6/2014 15:47
Hello,
I am working in the Migration to 5.0. But the existing project has lots of Pages (FS_REFERENCE) with out media. So is that possible to set the media through bean shell ??
Tags: fs_reference
-
Author: Anonymous - 3/28/2014 13:18
Hi Vasanth(?),
we've got a custom search client that help searching and selecting images and files and setting them into a FS_REFERENCE via Executable instead of BeanShell-script. You click a FS_BUTTON inside the elements form, after searching (which you have to do on your own, e.g. selecting a medium in BeanShell-script) the following code is executed:
// get the field and context from executable parameter-map
FormField<TargetReference> referenceField = (FormField<TargetReference>) params.get("referenceField");
BaseContext context = (BaseContext) params.get("context");
// get the store agent in order to receive the media store root
StoreAgent storeAgent = context.requestSpecialist(StoreAgent.TYPE);
MediaStoreRoot mediaStore = (MediaStoreRoot) storeAgent.getStore(Store.Type.MEDIASTORE);
// get the medium for a given ID
// it's the selected search hit in my custom search
Media medium = mediaStore.getMediaByUid(params.get("selectedMediumId")); // here you have to insert your own ID of the medium to put into the FS_REFERENCE
// create a new targetreference to put into the FS_REFERENCE-field
TargetReference targetReference = TargetReference.TargetReferences.newInstance(context.project.getMasterLanguage(), medium, null);
// set the new value of the FS_REFERENCE-field
referenceField.set(targetReference);
While doing these operations, the form has to be locked with the user that executes the script/executable.
Best,
Nils
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
1 Kommentar