How to export file name?

Question

I have requirement to show the "document name" in the output file. I have added the “Service Field” with Image Source, but we just need the file name and not all the whole path for the export into CSV.

How to export only the file name instead of a full path of the Service field?

Answer

You can create an additional field where the document name will be placed.
To use the original filename as a part of the output file name, modify the document definition as described below:

  1. Open the document definition and create a new service field;
  2. Navigate to the field's properties > Data Source tab and select Image Source from the Source drop-down list.

    Note: if necessary, hide this field from the document form, so verification operators won't see it and prevent it from being exported by disabling Export field value and Show on verification options on the field's properties >  General tab.

  3. Create a new text field. Let's call it Name.
  4. Navigate to the field's properties > General tab and set only the Index field option as active.

    Note: you can also turn on the Show on verification option just to check whether the source file name will be displayed correctly.

  5. Go to the Rules tab and create a new script rule:
    • Add both the service field and the text one.
    • Remove the "Read Only" mark from the text field.
    • Enter the following code in the script editor window (it's C# code):
      using System.IO;
      string path = Context.Field("Service Field").Text;
      Context.Field("Name").Text = Path.GetFileName(path);
    • Save changes.

After that, the export can be configured in the Document Definition properties.
Then, the document definition should be saved and published.

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.