File Extension

Certified Senior Developer

Hello Team,

I need to extract the file extension in a string StoneX - Dist. Agreement - XX Draft 12 Dec 2021.docx.

I cannot use the document function to extract the file extension since we have the option to delete/remove the file from repository and this will pop an error "document does not exist".

I'm current using the function getcontentobjectdetailsbyid(todocument(docId)) to extract the name.

Is there an easy way to extract the file using an OOTB function?

Thanks & Regards

Girish Katti

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I just use a pair of helper expression rules to get the document name from the ID (as it returns a whole name in a plaintext blob of info, we need to extract it from the output)

    a!localVariables(
      local!rawDetails: if(
        a!isNullOrEmpty(ri!doc),
        "",
        getcontentobjectdetailsbyid(ri!doc)
      ),
      local!wholeName: index(extract(
        local!rawDetails,
        "[Name: ",
        ", UUID:"
      ), 1, null()),
    
      rule!UTIL_processDocumentName(
        docName: local!wholeName
      )
    )

    That in turn calls UTIL_processDocumentName (which can be fed a "whole filename" from any source and for any reason) and uses Regex to help prevent weird corner-cases:

    a!localVariables(
      local!hasNoExtension: search(".", ri!docName) = 0,
      
      local!namePart: if(
        local!hasNoExtension,
        ri!docName,
        regexsearch(
          pattern: ".*(?=\.)",
          searchString: ri!docName,
          regexFlags: "i"
        )[1].match
      ),
      
      local!extension: if(
        local!hasNoExtension,
        "",
        regexsearch(
          pattern: "[^\.]*$",
          searchString: ri!docName,
          regexFlags: "i"
        )[1].match
      ),
      
      a!map(
        name: local!namePart,
        extension: local!extension
      )
    )

Reply
  • 0
    Certified Lead Developer

    I just use a pair of helper expression rules to get the document name from the ID (as it returns a whole name in a plaintext blob of info, we need to extract it from the output)

    a!localVariables(
      local!rawDetails: if(
        a!isNullOrEmpty(ri!doc),
        "",
        getcontentobjectdetailsbyid(ri!doc)
      ),
      local!wholeName: index(extract(
        local!rawDetails,
        "[Name: ",
        ", UUID:"
      ), 1, null()),
    
      rule!UTIL_processDocumentName(
        docName: local!wholeName
      )
    )

    That in turn calls UTIL_processDocumentName (which can be fed a "whole filename" from any source and for any reason) and uses Regex to help prevent weird corner-cases:

    a!localVariables(
      local!hasNoExtension: search(".", ri!docName) = 0,
      
      local!namePart: if(
        local!hasNoExtension,
        ri!docName,
        regexsearch(
          pattern: ".*(?=\.)",
          searchString: ri!docName,
          regexFlags: "i"
        )[1].match
      ),
      
      local!extension: if(
        local!hasNoExtension,
        "",
        regexsearch(
          pattern: "[^\.]*$",
          searchString: ri!docName,
          regexFlags: "i"
        )[1].match
      ),
      
      a!map(
        name: local!namePart,
        extension: local!extension
      )
    )

Children
No Data