September 24, 201015 yr I am trying to write a simple script to copy a bill to address into a ship to address when they are the same. I found a script that does what I want using the set field command. I have tried to reproduce this same script using my database, but its not working properly. When I go to run the script, the data that i typed in to the bill to fields gets erased. I have attached a screen shot of the script. I am new to this so it might be something very simple that I am missing. thanks in advance mhburris
September 24, 201015 yr I just did something like using copy and paste. I wrote a script to copy each Bill To field to the corresponding Ship To field, and then put a button on the layout that runs the script when needed. There may be a better way to do it, but this gets the job done.
September 24, 201015 yr It's hard for me to read your attachment, but it looks like it should work, unless you have reversed the fields. The field to be set is the one that currently doesn't have the data, with the field that does have the data. HTH Lee
September 25, 201015 yr I can't really read it either but (zooming to max), I can tell that you aren't setting fields at all. If you had selected a field, it would look something like: Set Field [ table::field ; "CF" ] ... instead you have: Set Field [ "CM" , "CF" ] ... and I honestly don't know how you were able to exit the calculation dialog without an error. Anyway, since you aren't specifying a field, it is setting whatever field you are currently on (which is most likely the BillTo address). Script ... Set Field ... check 'specify target field' and select your ShipTo field. Then click Calculation Result and point to your BillTo field. Nix the 'copy/paste'. Copy/paste requires that the field be on the layout AND it destroys the Users' clipboard contents. Use Set Field[] instead. :^)
September 25, 201015 yr I wasn't familiar with the Set Field method of doing this, so I did it the way that seemed easiest to me. I joined the forum so I could learn new ways of doing things, so thanks for the tip. I've also been reading all sorts of threads and picking up ideas, many of which are yours. Having said that, if I'm the only user, and have to be on that particular layout where I enter data to determine if the Bill To and Ship To info is the same, is there anything wrong with using a copy and paste method, other than the fact it erases what's on the clipboard?
September 25, 201015 yr It's just a really bad practice to get into. Also, it has the significant limitation that the fields must be on the layout. Using Set field does not require the fields to be on the layout.
September 25, 201015 yr Hi Ron, It would be a bad habit to get into. Why not use Set Field[] which is designed for the purpose? Using copy/paste will cause you grief; trust me. Set Field[] is much more flexible (it can set fields in related tables, set fields not on the layout at all) and, as I said originally, the field must be on the layout for paste. One day you'll forget to place the field on the layout (or remove the field thinking you no longer need it) and you'll waste time trying to figure out why it didn't work. But do as you wish ... sometimes we all do. And one day you will be surprised when you are working elsewhere in other programs and paste, only to find your Word document now full of 3,000 FM records instead of the graphic you expected. I've done the exact same thing. Then remember this thread. Knowledge is power; now you know. :smile2:
September 25, 201015 yr Okay. You convinced me. I wrote a script following your instructions and it worked the first time, so now I have a few others to rewrite. Always like to learn something new. Thanks.
Create an account or sign in to comment