Newbie asks about creating related records in a script
Hi, (Newbie on 8.5 Adv, Windows XP)
I'm using the following script to generate a particular number of new
records (and I'm stuck on the next step - making them related).
Here's the script (much thanks to Matt of this group):
Set Next Serial Value [Hardware::Serial; WorkOrders::StartSerial]
Set Variable [$Records; Value:WorkOrders::Quantity]
Go to Layout ["Hardware Form" (Hardware)]
Loop
New Record/request
Set Variable [$Records;Value:$Records-1]
Exit Loop If [$records=0]
End Loop
Go to Layout [original layout]
In Table WorkOrders, there are the following (relevant) fields;
Quantity
WorkOrder#
StartSerial
A description of the script:
>From one record in Table Work Orders, the script generates the number
of new records requested (set from WorkOrder's field Quantity) into
Table Hardware. The script sets the correct serial # for each new
hardware record, based on the starting point set in WorkOrder's field
StartSerial.
So while in table WorkOrders, with the click of a button, I can
generate beautiful new records in my Hardware table - and each record
has it's correct serial # already filled in.
The problem:
BUT! I need the new hardware records to be related to the WorkOrder#
from which they were born. I really need to be able to see the
Mothership WorkOrder# in each set of related Hardware records.
What I've tried:
Not knowing for sure how to do this, I made a matching foreign field
in my Hardware table, kf_WorkOrder#. It is linked in the relationships
graph to it's match in the WorkOrder table.
Now when the new hardware records are made, I'm guessing I need to
"copy" over the WorkOrder# in table WorkOrder, and have that same # be
"pasted" into every new hardware record...
thus making the records related based on WorkOrder#.
I tried putting a set field into my script...I tried (unsuccessfully)
to place the line before and into the loop. Hmmmmstuck. I also tried
setting the foreign key to auto enter (calc) the matching WorkOrder#
(didn't work).
Intuitively I can see why these attemps didn't work - what matching
field is there to base things on? But on the other hand, if the script
can enter the serial#, why won't it enter the duplicate the WorkOrder#
into the foreign key of all the new hardware records?
Any suggestions? Keep in mind I'm VERY new to scripting...
Much thanks,
cat
Re: Newbie asks about creating related records in a script
On 2007-08-13 14:43:39 -0700, cat <cathytyner [at] gmail.com> said:
> Intuitively I can see why these attemps didn't work - what matching
> field is there to base things on? But on the other hand, if the script
> can enter the serial#, why won't it enter the duplicate the WorkOrder#
> into the foreign key of all the new hardware records?
>
> Any suggestions? Keep in mind I'm VERY new to scripting...
You're so almost there, cat.
The reason you can't reach back to the kf_WorkOrder# field is that it's
probably not a global. And it shouldn't be, for purposes of
relationships.
However, you're already using a variable for your loop counter. Before
you leave the WorkOrder table, set another variable "$$WorkOrderNumber"
with the number you need. Then in your loop, have two Set Field
steps...one for the serial, one for the WO number.
--
Lynn Allen
--
www.semiotics.com
562.938.7890
Long Beach, CA
Re: Newbie asks about creating related records in a script
On Aug 13, 2:59 pm, Lynn Allen <l... [at] NOT-semiotics.com> wrote:
> On 2007-08-13 14:43:39 -0700, cat <cathyty... [at] gmail.com> said:
>
> > Intuitively I can see why these attemps didn't work - what matching
> > field is there to base things on? But on the other hand, if the script
> > can enter the serial#, why won't it enter the duplicate the WorkOrder#
> > into the foreign key of all the new hardware records?
>
> > Any suggestions? Keep in mind I'm VERY new to scripting...
>
> You're so almost there, cat.
>
> The reason you can't reach back to the kf_WorkOrder# field is that it's
> probably not a global. And it shouldn't be, for purposes of
> relationships.
>
> However, you're already using a variable for your loop counter. Before
> you leave the WorkOrder table, set another variable "$$WorkOrderNumber"
> with the number you need. Then in your loop, have two Set Field
> steps...one for the serial, one for the WO number.
> --
> Lynn Allen
> --www.semiotics.com
> 562.938.7890
> Long Beach, CA
Wow, very cool - thank Lynn, it works great! I've been stuck on this
one for a while, you've helped immensely. I will go read up on global
variables, I never really understood their purpose.
....Unfortunately I am now distracted learning about semiotics from the
link on your website.
-cat
Re: Newbie asks about creating related records in a script
On 2007-08-13 18:41:40 -0700, cat <cathytyner [at] gmail.com> said:
> ...Unfortunately I am now distracted learning about semiotics from the
> link on your website.
Focus, cat, focus!
--
Lynn Allen
--
www.semiotics.com
562.938.7890
FSA Associate
Long Beach, CA