Pass chain parameters from document suggestion widget

Hi,

I'm trying to pass parameters from a nuxeo-document-suggestion widget to the automation chain returning the suggested documents.

Here is the widget :

<nuxeo-document-suggestion
    value="{{document.properties.mfs:documents}}"
    label="[[i18n('manufacturing_summary.documents')]]"
    multiple="true"
    min-chars="0"
    role="widget"
    stayOpenOnSelect="true"
    operation="SearchDocuments"
    params="{'searchTerm':'?', 'doctype':'hwp_document', 'parentId':'#{documentManager.getParentDocument(currentDocument.parentRef).id}'"
></nuxeo-document-suggestion>

And here is the automation chain :

<chain id="SearchDocuments">
    <param type="string" name="searchTerm"/>
    <param type="string" name="doctype"/>
    <param type="string" name="parentId"/>
    <operation id="GetSearchQuery">
        <param type="string" name="searchTerm">expr:ChainParameters['searchTerm']</param>
        <param type="string" name="doctype">expr:ChainParameters['searchTerm']</param>
        <param type="string" name="parentId">expr:ChainParameters['parentId']</param>
    </operation>
    <operation id="Context.SetInputAsVar">
        <param type="string" name="name">query</param>
    </operation>
    <operation id="Repository.Query">
        <param type="string" name="language">NXQL</param>
        <param type="string" name="query">expr:Context['query']</param>
        <param type="stringlist" name="sortBy">dc:title</param>
        <param type="stringlist" name="sortOrder">ASC</param>
    </operation>
</chain>

As you can see, I tried to pass them through the “params” field (as suggested by the documentation), but :

  1. I'm really not sure about the “?” syntax for the search parameter
  2. The chain parameters are empty when they get called by the GetSearchQuery operation

I could try to directly access those parameters from the automation context, but being called from a widget in the creation form, the current document (i.e. the parent of the document being created) is not accessible in this context.

0 votes

1 answers

106 views

ANSWER



Ok, I think that I managed to solve this on my own (I don't even know why I still post stuff here, I never get any answer).

  1. The searchTerm parameter is automatically passed to the operation's parameters, so no need to include it in the “params” field of the widget.
  2. Things mess up when passing the parameters directly as a string representation of a javascript object. You should first create a javascript object in the Polymer script, then pass this object to the widget. Here's the fixed code :

The widget :

<nuxeo-document-suggestion  value="{{document.properties.mfs:documents}}"
                            label="[[i18n('manufacturing_summary.documents')]]"
                            multiple="true"
                            min-chars="0"
                            role="widget"
                            placeholder="[[i18n('dublincoreEdit.directorySuggestion.placeholder')]]"
                            operation="SearchDocuments"
                            params="[[params]]"
></nuxeo-document-suggestion>

The script :

<script>
    Polymer({
        is: 'nuxeo-manufacturing_summary-create-layout',
        behaviors: [Nuxeo.LayoutBehavior],
        properties: {
            /**
             * @doctype manufacturing_summary
             */
            document: Object,

            params: {
                type: Object,
                value: {"doctype": "hwp_document", "docId": document.id}
            },
        },
    });
</script>

BUT my troubles are not over because my docId param is empty, which makes sense because my document is not created yet, and all its properties are empty.

document.id or document.path both return a null value, and I have no idea how to get the parent's ref (that's my ultimate goal). If you have ANY idea please feel free to share.

Have a good day !

0 votes