Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Importing csv email attachments in FMS from plug-in function


This topic is 5393 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I am migrating an email processing solution that used to run in a FM Pro client robot to a FMSA version running with recurring scheduled events.

With the FM client the logic of my script would store the attachment in a field and then I would do the step:

Export Field [Email_Attachments::Object; "$attachment_path" ]

// Which is not compatible with FM Server

// so I could finally import the csv attachment as records into another FM table

Import Records [No dialog; Source:"$attachment_path" ; Add ; Windows ANSI ]

My problem is I cannot use the Export Field command in Server.

Using the Email Plug-in I thought, no problem: I don't need the Export Field command because the plug-in already stores the file in a local path, so I can direct the Import Records function to that location..

But somehow that logic is not working.

This is what I am doing after I have successfully connected and downloaded messages from my IMAP host:

Set Variable [$attachments ; Value: EmailReadMessageValue( "attachments" )]

....

// Some other stuff, like validations, creating records with the emails in some related tables, etc.

// everything within the same script and not calling any other plug-in functions

....

Set Variable [$attachment_path ; Value: EmailReadAttachment( "$attachments" )]

// All these steps are working, because I can create a record with the attachment file and the correct path which looks something like this in one example:

C:Documents and SettingsDavidLocal SettingsTempkxlfq4.pjma4e@localhostNV_ordersfeed_20100210-163003.csv

// And now, the step that doesn't work

Import Records [No dialog; Source:"$attachment_path" ; Add ; Windows ANSI ]

// Is giving me an ERROR 10 (File doesn't exist)

Any idea what I could be doing wrong?

Thanks

PS. While testing and debugging, I am running the script in FMP in a windows machine, when ready for production the script will run in FMSA 10 in a Mac X Serve (I mention it in case it makes any difference in the path configuration)

Posted

Seems to me that the import path needs to be a FM path, not an OS path. That is something like, file: & Get (TemporaryPath) & $filename.

Why import? Do you need a record to know where the attachment is? If so, you can set a field to the attachment path.

Posted

Barbara,

Thanks for you advice, I will look into the syntax of the path and test several options.

In regards to your second comment -why do I need to import- I am not sure if you understand my problem or if there is really another way to handle my need.

Let me clarify, my clients send me emails with flat files (mostly csv and xls) as email attachments, these emails need to be imported automatically into FM.

The flat files will contain a number of rows and columns with order header and order line item data.

When I downloaded the email attachment via FM client (as opposed to FM Server) I wouldn't have issues re-exporting it to a designated path so I could re-import it with its corresponding mapping into my orders table.

Answering you question, I also kept a copy of the original attachment in a container field related to the order for archival purposes and as safeguard in case I had to refer to it for whatever reason.

Are you implying there would be a way for me to automatically navigate inside the contents of a FM container object, such as csv and parse it rather than import it?

Thanks

Posted

I finally got it to work on Windows with FMPA 10

I had to do what you suggested Barbara and another extra thing to make it work:

1) I had to modify the path provided by the plugin replacing the forward with the backward slashes

$new_path = Substitute ($original_path ; "" ; "/" ) - I had to escape the escape symbol

2) Then I performed the import function adding "file:/" and it worked

Import (file:/$new_path)

The problem is that it is not working for my FMSA 10 running on mac, I also tried with FMPA 10 running on that same machine and the debugger but it is not working either, I keep getting the -100 Error, file not Found -

I suspect it could be an issue with folder access privileges, but I am unable to find that temporary folder to change the privileges, assuming that is the problem ( I am not very proficient with Mac)

By the way for the mac version I also tried filemac:/

and without replacing the slashes, since I noticed with data-viewer that in the mac those come directly as "/" not like "" in windows

Any ideas?

Posted

Hey 360works,

Could you give me a hand with this issue I have? I can import from an email attachment path given by the plug In in Windows but I can't in Mac.

This works on windows:

Set Variable [$attachment_path ; Value: EmailReadAttachment( "$attachments" )]

Set Variable [$new_path = Substitute ($attachment_path ; "" ; "/" )]

Import Records [No dialog; Source:file:/$new_path ; Add ; Windows ANSI ]

When I try to do the equivalent with mac

Set Variable [$attachment_path ; Value: EmailReadAttachment( "$attachments" )]

Import Records [No dialog; Source:filemac:/$attachment_path ; Add ; Windows ANSI ]

I get a FILE MISSING error code

Any idea of what could be going wrong?

Thanks

Posted

You should not specify "File:" when downloading attachments. You will need to call EmailReadMessageValue("attachments") to get the list of file attachments and parse them into paths for each file using the getValue or Middle functions (if you have more than one attachment). These paths can then be passed to the EmailReadAttachment function which will read the attachment into the container field.

I recommend looking at the Email Plugin Sample Client.fp7 file, which has examples of how this script should be worked.

This topic is 5393 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.