Sign in to follow this  
Followers 0

Import .xls using variables in script

3 posts in this topic


Sorry, new here so please forgive me if I am in the wrong area!

I have a file which relies totally on externally provided data. I cannot link directly to the data and have to download the individual .xls files manually from the internet and I store them in a child-folder called "Lincs" in the My Documents folder using a direct path name.

Problem is, this will be used by other people in other countries and the route to their My Documents folder is differnet to mine.

To get round this problem I used the following in my script:

Set Error Capture [ On ]

Set Variable [ $file; Value:"filewin:" & Get ( DocumentsPath ) & "namefolder" & settings::globaltextnamefilewithextension ]

Import Records [ Source:“$file”; Method:Update existing; Character Set:“Windows ANSI”] [ No dialog ]I

f [ Get ( LastError ) = 100 ]

Show Custom Dialog [ Title: "Error"; Message: "File Does Not Exist"; Buttons: “OK” ]

End If

This seems to work OK.


When I set the filepath manually within the script (ie [file:../../../../../Temp/BostonRD.xls]) I click OK, then select 'Sheet 1' of the file, and then select 'data' as the 'First Row Option'. Then, when I click on 'Specify Import Order', the source fields are displayed which I can match up. I can also select 'Don't Import First Record (contains field names)", and then click OK again. Then click on 'Import Options' and select 'Import'. All works great.

However, when I use a variable to import the file, I am not given the 'Sheet No' option and when I try to specify the import order no source options are displayed. Also I cannot choose to omit the first record containing the field names.

It works in principle, but imports the 'title fields' or a blank record from the .xls file. Also, how does it know which fields to match up?

As I say, it works in principle but I don't understand why and how can I stop it importing the 'title fields' from the .xls file?

Any help would be greatly appreciated.


Share this post

Link to post
Share on other sites

Using a variable for a path to import records can be a little tricky since FileMaker cant find the file via your variable while you are editing your script. So, while editing the script, set the filepath manually so you can specify the import options, then you can change the path back to the variable path, and it should work.

You can also just specify multiple paths, and leave it like that. To do this, enter this text in the "Specify File" window:



Share this post

Link to post
Share on other sites

Hi Dan

Thanks for that. Yes, makes sense when you think about it. As I said, it seemed to work OK, I just couldn't see why!


Share this post

Link to post
Share on other sites

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
Sign in to follow this  
Followers 0

  • Similar Content

    • By Peter Barfield
      Hi all not sure if this is the right area for this post  however,any Help appreciated
      in a design that i am working on for a small point of sale i have an issue (or challenge)
      the normal price is set as a Retail Price (all good)
      however I have been asked to now fulfill this next part.
      A Multi-buy concept.
      so e.g. a bottle of wine would normally sell for $12.99
      however there is a promotion where you can get 2 for $20 ea (or a breakdown of $10 ea)
      Now I have put a field in inventory table for multi buys i.e. fields 
      1. a checkbox for whether it is a multi buy item.
      2. a field which indicates the qty of item that is applicable as in the above example 2
      3. a field which indicates the multi buy price.
      4. A field which calculates the individual price as in the example above $10. (multi buy price / qty)
      and just to throw a little more into it there is the possibility of a situation whereby it could be 2 OR MORE.
      so I have created a field which is a further checkbox which indicates whether OR MORE is applicable or just the base qty.
      I guess the question is how does one tie this into the POS where an item would usually under normal circumstances be scanned and price picked up from the inventory table 
      I am just a little lost on this. I thought of a script that checks for multi buy applicable then pops the qty and price into variables which could somehow be used back at the POS screenoveriding the "usual price". Then the issue of OR MORE came into play and that is just for me draining my limited grey matter.
      or am i looking at this completely wrong and is there a possible better way ie use of a related table etc.
      Any Ideas would be appreciated.
      I hope this makes sense.
    • By kisertn
      I am new to FM, coming to it from a SQL Server/Oracle/Access background.  I have created a database with layouts and while there is certainly much more for me to learn it generally is working as I desire it.  However, I need to perform a task that I do not understand how it would be done in FM.  The example below is not my actual problem but does exemplify my core issue and hopefully is easier to understand than if I described my project.
      I have a table of Users, a table of Entitlements, and a join table of UserEntitlements.    I want to execute SQL that, for a given User, will read from the Entitlements table and insert rows into UserEntitlements for this user.  The query will read from Entitlements, insert a row for every entitlement for this user and, based on data in Entitlements take, will mark some of the entitlements as 'active'.
      Ideally, every time I created a new user this SQL would be called  (I'd have it as a trigger in a SQL or Oracle database, or I'd have a batch process that ran frequently looking for new users).   Basically, as a new user is created I want to create their entitlements profile and activate standard entitlements.
      I don't need/expect a full answer - was just hoping I could get pointed in the right direction: is 'scripts' the area I need to explore?  Is there a SQL capability to FM?  I have not found it if there is.
      Thank you for any assistance you can provide,
    • By surfninja13
      Hello All,
      This may have been addressed before and I am very new to scripting in filemaker.  Basically what I am trying to create is a script where I can find records from a carriage return separated list.  I have created a field and a button to execute the script.
      For Example: If I have 50 records for every US State, in the field I could put:
      Thus populating just the 3 records.  
      Any help would be greatly appreciated.
    • By RDWirr
      I am running FileMaker 14 on a Win 10 machine. I have a set of records that each have a field with a starting number and a field with an ending number. I have to perform a find that locates the record where the find criteria is greater than or equal to the starting number AND less than or equal to the ending number. I need to write a script that will just let the user enter the find criteria in a edit box and then go to the record. This will theoretically be only one record that would match from the dataset. Can anyone point me in the right direction with this?
    • By Luke Cottingham
      1st of all - I have personally refrained from posting for help on a forum as I wanted to try and read, learn and solve my problems using trial and error! I am learning the FMP platform from scratch and am currently in week 2 of it.
      My question relates to a file I have attached to this post - the products area.
      For each product I have a number of 'size options' within it and each with their own unique SKU (stock keeping unit). Each SKU needs its own barcode. My job now is to produce a method to easily assign an 'available' barcode to a specific SKU.
      Barcodes are purchased from GS1 and are globally unique. I have a table hosting a pool of barcodes that I have available to me. They can only be assigned to one SKU and once assigned, needs to be removed from the available selection of barcodes in this pool.
      I wanted to set a placeholder text for 'EAN-13' field in the product layout (this is the barcode). This field is a button! When clicked it can perform a script to open a popover or window containing all barcodes that do not have a 'ProductOptionID' assigned to it.
      How do I structure this script? Click the EAN field button - this sets the 'ProductOptionID' variable globally (is this correct to do) - [$$productOptionID] The script then opens the object 'Barcodes'. This is a popover button with a portal inside filtering all barcodes from the pool that do NOT have a productOptionID value in the foreign key field The script must then pause whilst I manually select a barcode and set a $BarcodeID variable? Or should I script it to pick a barcode at random from the pool of available barcodes (i've already set a script to give available a figure of 1 and unavailable a figure of 0) Then the script must put the BarcodeID variable in the product option record Is the above the right way to go about it? I also need a way to un-assign a barcode from a product and therefore remove the value from the product option id field in the barcode pool I have one more query. I have a relationship between Product Option table and the Barcode Pool. This relationship is O2M the barcodeIDpk with a lookup for the actual EAN (barcode) value on the Product Option table. When I set a barcode ID in the Product Option table - shouldn't the ProductOptionIDfk field update in the Barcode pool with the ID of the product option that the barcode is assigned to??
      I am convinced I had it working earlier - but not anymore and cannot see to figure out why?
      See my relationship graph below and the solution attached.
      CRM Trial barcode.fmp12