Aller au contenu principal

Is it possible to set the Media in FS_REFERENCE Through Bean Shell

Commentaires

1 commentaire

  • Zendesk API User
    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

Vous devez vous connecter pour laisser un commentaire.