Mulesoft Sharepoint File move connector

211 views Asked by At

I am trying to build an Mulesoft application which will pick up a XML file from the folder on a Sharepoint site. Once the file is dropped in to the folder I am trying to pick up and doing processing, creating records in Salesforce. Once it is picked up I need to remove (move) from the source folder to the archive folder, which I am not able to do it.

Below is the setting for the file pick up

<flow name="listener-flow" doc:id="1a2f1eb3-0d64-45bd-9a61-9faf7b102c0d" >
    <sharepoint:created-objects doc:name="On New Objects" doc:id="c87373ee-8251-4f62-ae01-2a4969923d6e" config-ref="Sharepoint_Sharepoint_online" objectType="FILE" path="${sharepoint.listener.path}" recursive="true">
        <scheduling-strategy >
            <fixed-frequency frequency="${sharepoint.listener.polling.frequency}" timeUnit="SECONDS" startDelay="${sharepoint.listener.polling.startDelay}"/>
        </scheduling-strategy>
    </sharepoint:created-objects>
    <sharepoint:file-get-content doc:name="File get content" doc:id="c4ff33bb-d232-4194-a727-cb6e18ea83c5" config-ref="Sharepoint_Sharepoint_online" fileServerRelativeUrl="#[payload.ServerRelativeUrl]"/>
    <ee:transform doc:name="Map File Content to JSON" doc:id="70fbc3d7-9e37-4197-af61-5594cd6dc719" >
        <ee:message >
            <ee:set-payload ><![CDATA[%dw 2.0
                output application/json
                ---
                read(payload, 'application/xml')]]></ee:set-payload>
        </ee:message>
    </ee:transform>
    <sharepoint:file-move doc:name="File move" doc:id="2d604ac1-4d33-4e61-8310-9d59671fe9c1" config-ref="Sharepoint_Sharepoint_online" fileServerRelativeUrl="#[payload.ServerRelativeUrl]"/>
    

enter image description here

But I am not sure what should be the new file server relative url be

enter image description here

In my YAML file I stored the archive path like below

# Sharepoint
sharepoint:
  siteUrl: "https://XXXXXXXX.sharepoint.com/sites/D365XXXXX"
  auth:
    username: "[email protected]"
    password: "ABCDDD"
  listener:
    path: "/sites/D365Ad/NP Int/SF"
  archive:
    path: "/sites/D365Ad/NP Int/SF/Archive"
    polling:
      frequency: "60" # In seconds
      startDelay: "30" # In seconds

The ${sharepoint.archive.path} stores the archive folder path where the file has to to be moved. Alos if the source file name is XYZ I need to set the archived file name as sourcefilename_datetime.xml how or where can it be done.. Any help is greatly appreciated as this is my first project with Mulesoft

1

There are 1 answers

0
aled On BEST ANSWER

To use a property like ${sharepoint.archive.path} inside an expression use the p() function to get is value as p("sharepoint.archive.path"). Then concatenate it with the file name and a timestamp. Assuming the file name is stored in a variable called vars.filename:

#[p("sharepoint.archive.path") ++ "/" ++ vars.filename ++ "_" ++ now() as String {format:"yyyyMMddTHHmmss"} ++ ".xml"]