Jump to content

Simple Script Help


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

Recommended Posts

I need to write a very simple script, however I'm new to this so not sure what to do. All it basically has to do is when First file is updated in any way or a new record is inserted, the Second file needs to be automatically updated.

Thanks in advance,

Link to comment
Share on other sites

The first file has records with about 50 fields. The second file has the same records with only the name and address fields. So every time a record is added or updated in the first file, it als needs to be automatically updated in the second file. No relationships are setup yet. I'm not sure how all this works together in FM.

Link to comment
Share on other sites

OK, in both files create a calculated number field (call it cConstant) that returns a value of 1 (when you go to Define Fields and select calculation, enter the number 1 in the forumla window and make sure the field is set to be a number). From your 2nd file (the Child file) define a relationship to the 1st file (the Parent file) that is based on the cConstant field in both files. This is called a constant-to-constant relationship.

In both files create a auto-enter serial number field(this gives each record its own ID), called nID

In the Child file create a number field, nParentID. Create a realtionship from Child to Parent that links nParentID (in the Child file) to nID (in the Parent file).

OK, so instead of using the Name and Address fields in the Child file, you're going to create cacluated fields that get their value from the Parent file. In the Child file, create a calculated text field, called cName. When you do, you'll see at the top of the dialogue box a drop-down list which allows you to pick the data source for your fields - select the relationship that you just created to the Parent file and locate and select the Name field. Create a calculated text field for Address and do the same (obviously selecting the Address field from the Parent file). This means that any change you make to the Name or Adress fields in the Parent file will automatically be reflected in the Child file - no scripting required.

To setup new records:

In the Parent file create a global text field, called gID. Create the following script:

New Record/Request

Set Field (gID, nID)

Perform External Script (you're going to access a script in the Child file which you will create shortly)

Exit Record/Request

Halt

In the Child file create the following script (this is the script that you'll call from the script in the Parent file):

New Record/Request

Set Field (nParentID, constant-to-constant relationship::gID)

Exit Record/Request

Link to comment
Share on other sites

It doesn't seem to work. My first file contains over 1000 records. The second file is empty and needs to have all that data. I imported all the records before making the changes, however when I changes all the fields to "Calculation", they record fields didn't show anything. I thougt that I need to delete all records and import them once again, but now I can't import anything except the "nParentID" field.

Link to comment
Share on other sites

This topic is 6540 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
 Share

×
×
  • Create New...

Important Information

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