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]"/>
But I am not sure what should be the new file server relative url be
In my YAML file I stored the archive path like below
# Sharepoint
sharepoint:
siteUrl: "https://XXXXXXXX.sharepoint.com/sites/D365XXXXX"
auth:
username: "CCCCCC#abc.org"
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
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"]
Related
I have few files stored in document library. Most files will be under folders.
Eg: Folder1>A1json
Files Folder>F1Json
Folder2>A2Json
Files Folder>F2Json
Folder3>A3Json
Files Folder>F3Json
I need to display only json file name as lookup in other list like (A1Json/A2Json/A3Json).
Need not include files that come under "Files Folder". Kindly help if any logical filter can solve this.
Tried these method but not receiving the required result
1.Filter(Document, 'Folder path'="Shared Documents/")
Filter(Documents, 'Folder path' = "Shared Documents/" && IsFolder = false).Title.
Filter('Documents',(IsFolder= false && Not("Files/" in 'Full Path')),EndsWith('File name with extension',"json")).Name
I found a solution for my original question in another post Google Apps Script creates sheets version of excel file.
Testing with the code provided in the answer I ran into another issue. Every time I run the script it creates the Spreadsheets version of the .xlsx files again even if they already exist. I have tried modifying the code withing the last If with no results. Then went back to run your code as posted in case I have missed something but it keeps creating versions of the same files.
Any idea of what could I do to fix this will be really appreciated.
The code provided int he answer is the following.
// Convert the user's stored excel files to google spreadsheets based on the specified directories.
// There are quota limits on the maximum conversions per day: consumer #gmail = 250.
function convertExcelToGoogleSheets()
{
var user = Session.getActiveUser(); // Used for ownership testing.
var origin = DriveApp.getFolderById("origin folder id");
var dest = DriveApp.getFolderById("destination folder id");
// Index the filenames of owned Google Sheets files as object keys (which are hashed).
// This avoids needing to search and do multiple string comparisons.
// It takes around 100-200 ms per iteration to advance the iterator, check if the file
// should be cached, and insert the key-value pair. Depending on the magnitude of
// the task, this may need to be done separately, and loaded from a storage device instead.
// Note that there are quota limits on queries per second - 1000 per 100 sec:
// If the sequence is too large and the loop too fast, Utilities.sleep() usage will be needed.
var gsi = dest.getFilesByType(MimeType.GOOGLE_SHEETS), gsNames = {};
while (gsi.hasNext())
{
var file = gsi.next();
if(file.getOwner().getEmail() == user.getEmail())
gsNames[file.getName()] = true;
}
// Find and convert any unconverted .xls, .xlsx files in the given directories.
var exceltypes = [MimeType.MICROSOFT_EXCEL, MimeType.MICROSOFT_EXCEL_LEGACY];
for(var mt = 0; mt < exceltypes.length; ++mt)
{
var efi = origin.getFilesByType(exceltypes[mt]);
while (efi.hasNext())
{
var file = efi.next();
// Perform conversions only for owned files that don't have owned gs equivalents.
// If an excel file does not have gs file with the same name, gsNames[ ... ] will be undefined, and !undefined -> true
// If an excel file does have a gs file with the same name, gsNames[ ... ] will be true, and !true -> false
if(file.getOwner().getEmail() == user.getEmail() && !gsNames[file.getName()])
{
Drive.Files.insert(
{title: file.getName(), parents: [{"id": dest.getId()}]},
file.getBlob(),
{convert: true}
);
// Do not convert any more spreadsheets with this same name.
gsNames[file.getName()] = true;
}
}
}
}
You want to convert Excel files in origin folder to Google Spreadsheet and put the converted Spreadsheet to dest folder.
When the filename of converted file is existing in dest folder, you don't want to convert it.
If my understanding is correct, how about this modification?
From:
if(file.getOwner().getEmail() == user.getEmail() && !gsNames[file.getName()])
To:
if(file.getOwner().getEmail() == user.getEmail() && !gsNames[file.getName().split(".")[0]])
Note:
In this modification, when the filename of converted file is found in the dest folder, the file is not converted.
When the filename has the extension like ###.xlsx and it is converted to Google Spreadsheet, it seems that the extension is automatically removed. I think that this is the reason that the duplicated files are created. So I used split(".")[0] for this situation.
Reference:
split()
My project is about sending an email with a pdf attachment.
All my pdf are in a folder on google drive and I need to look for that specific pdf associated to that specific customer.
The pdf contains text only and contains the customer number.
Thus i need a script to extract the text from the pdf to a string and study this string to find out if it contains the customer number.
For now I use this:
function myFunction() {
// Creates a new file and logs its content
var file = DocsList.getFileById('my pdf file id here')
Logger.log(file.getContentAsString()); // logs 'sample file contents'
}
But the log shows an encoding issue:
m��:�B�C-�BݣXaP�{��
u�hu#���(�="���j�=��%C���g(r{����j��/��=��Ev���3�=���P���>��̓�e(r{��yX�Pd�PޗEv�j�#�ݣ2�Eq��b����h�="�(�{�,v���GE�O�_����������q�o�v�)��p���u�\9�[�G��
Does someone knows how to extract text from a pdf to a string?
The pdfToText() utility from Get pdf-attachments from Gmail as text uses the advanced Drive service and DocumentApp to convert PDF to Google-Doc to text. You can get the OCR'd text this way, or save it directly to a txt file in any folder on your Drive.
// Start with a Blob object
var blob = DriveApp.getFilesByName("my.pdf")[0];
// filetext will contain text from pdf file, no residual files are saved:
var filetext = pdfToText( blob, {keepTextfile: false} );
Once you have the text, a search for keywords becomes dead easy!
if (filetext.indexOf( keyword ) !== -1) {
// Found keyword...
}
I am using Haxe and OpenFL and I got a program that generates a Xml file.
However, I can't figure out how to save that file. I can create Xml tree and check it's valid, but for my life I can't figure out how to write the file.
So, in simple, how to do I write(and create) a file in Haxe? I want to be able to save my newly created Xml File (they serve as sort of settings file and initialization files for my program) on computer, so that I can load it later?
Found the solution right after writing this question.
Solution is to first to use sys.io.File.write() to create the file, then File.saveContent() to save the data in. You can get string from Xml with toString function, the ultimate solution looks like this:
if (!FileSystem.exists("maps"))
{
FileSystem.createDirectory("maps");
}
var number:Int = 1;
if (FileSystem.exists("maps/" + filename + ".xml"))
{
while(FileSystem.exists("maps/" + filename + number +".xml"))
{
number++;
}
filename = filename + number;
}
File.write("maps/" + filename + ".xml", false);
File.saveContent("maps/" + filename + ".xml", root.toString());
This checks if the directory exist and if not, create it and if the file exist, create a new numbered file rather than override it (for the moment, still working on the save feature)
This solution only works on c++, haven't tested others much yet but Flash does not work
I am accessing SharePoint via its web services... Which are a bit limited, as a result I have turned to WebDav to perform some create folder functionality...
I have a document library, and I am about to create a folder using webdav, but I can't find any documentation on the internet or anywhere else on how to check if a folder already exists using webdav, so is there a way to check if a folder exists in a document library in SharePoint, any hack and slash methods welcome!
Somehow, I don't get your question. First sentence states you are using web service (I'd normally understand it as the SOAP web services provided by SharePoint). The next one says you are using WebDAV which is a completely different protocol.
So, WebDAV is the protocol "Windows Explorer" uses to access SharePoint, if you open it it "Explorer mode". Since all these requests are actually HTTP requests, you can spy on them, using the "Fiddler" tool.
I believe, before opening a folder, Windows Explorer tries to query sharepoint, if such folder exists. If I try to open an unexistant path \\mysrv\sites\myweb\mylib\notthere (but \\mysrv\sites\myweb\mylib is an existing document library!) thru windows explorer, the last HTTP call I see is:
PROPFIND /sites/myweb/mylib HTTP/1.1
User-Agent: Microsoft-WebDAV-MiniRedir/6.1.7600
Depth: 1
translate: f
Where SharePoint responds with: a list of subfolders and pages in this folder (very long XML, but it contains items like this):
<D:multistatus
xmlns:D="DAV:"
xmlns:Office="urn:schemas-microsoft-com:office:office"
xmlns:Repl="http://schemas.microsoft.com/repl/"
xmlns:Z="urn:schemas-microsoft-com:">
<D:response>
<D:href>http://sites/myweb/mylib</D:href>
<D:propstat>
<D:prop>
<D:displayname>mylib</D:displayname>
<D:lockdiscovery/>
<D:supportedlock/>
<D:isFolder>t</D:isFolder>
<D:iscollection>1</D:iscollection>
<D:ishidden>0</D:ishidden>
<D:getcontenttype>application/octet-stream</D:getcontenttype>
<D:getcontentlength>0</D:getcontentlength>
<D:resourcetype>
<D:collection/>
</D:resourcetype>
<Repl:authoritative-directory>t</Repl:authoritative-directory>
<D:getlastmodified>2009-12-07T09:07:19Z</D:getlastmodified>
<D:creationdate>2009-11-06T13:30:26Z</D:creationdate>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
<!---List of other <D:response> elements -->
</D:multistatus>
If the contained element is a folder, it must have "D:isFolder" value "t". This way you can find, if the parent folder contains the folder you are going to create.
EDIT: created a small c# sample which first reads the result stream and then parses the result a bit. You need to make it better, to see if the list contains the folders you need or not.
System.Net.HttpWebRequest oReq;
string sUrl = "http://yoursite/sites/somesite/DocumentLibrary";
oReq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(sUrl);
oReq.Method = "PROPFIND";
oReq.Credentials = System.Net.CredentialCache.DefaultCredentials;
oReq.AllowAutoRedirect = true;
oReq.UserAgent = "Microsoft-WebDAV-MiniRedir/6.1.7600";
//this causes all of the items to be enumerated,
//if it is 0, only the folder itself is returned in the response
oReq.Headers["Depth"] = "1";
oReq.Headers["translate"] = "f";
System.IO.StreamWriter oRequest =
new System.IO.StreamWriter(oReq.GetRequestStream());
oRequest.WriteLine();
oRequest.Close();
System.IO.StreamReader oResponse =
new System.IO.StreamReader(oReq.GetResponse().GetResponseStream());
string sResponse = oResponse.ReadToEnd();
oResponse.Close();
//done with the webclient stuff, check the results
System.Xml.XmlDocument oMyDoc = new System.Xml.XmlDocument();
oMyDoc.LoadXml(sResponse);
System.Xml.XmlNamespaceManager oNsMgr =
new System.Xml.XmlNamespaceManager(oMyDoc.NameTable);
oNsMgr.AddNamespace("D", "DAV:");
System.Xml.XmlNodeList oAllResponses =
oMyDoc.SelectNodes(".//D:multistatus/D:response", oNsMgr);
foreach (System.Xml.XmlNode oNode in oAllResponses)
{
Console.WriteLine("Name: " +
oNode.SelectSingleNode("./D:propstat/D:prop/D:displayname",
oNsMgr).InnerText);
if (oNode.SelectNodes("./D:propstat/D:prop/D:isFolder", oNsMgr).Count > 0)
{
Console.WriteLine("Is folder: " +
oNode.SelectSingleNode("./D:propstat/D:prop/D:isFolder",
oNsMgr).InnerText);
}
else
{
Console.WriteLine("Is folder: f");
}
Console.WriteLine();
}
YOu don;t need to, if it already exists, trying to create a new folder with that name will "silently" return the already existing folder.