Search the FirstSpirit Knowledge Base
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 ??
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
Hello,
do you just want to set a fallback media object?
You can do that within the project configuration in "Substitutions" => "Substitution medium".
Regards,
Jascha
Hello,
do you need further help or did Jaschas reply already help you? If you found another solution by yourself it would be great, if you posted it here.
Best regards
Michaela
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