2 Replies Latest reply on Apr 24, 2015 11:36 AM by newtofilemaker

    duplicating only selected fields.



      duplicating only selected fields.



        I would like my client to duplicate a record with option to select fields to duplicate.

      So I created a Global table with a text field (Globals::whichchk)  in the Header section of the form. The format of this global field is  Check box list and displays a value list which has names of all fields on the form. The client can check the box to select the fields he would like duplicate.

      I have created a script that uses getvalue(Global::whichchk,1) to check if the first item in the value list is 1 or 0. If it is unchecked then that field in the duplicated record is set to "" (null).


      The name of the value list is chklist. It is the list of name. strain, generation, birth date etc. 

      So the global field  Globals::whichchk in the header section of the form shows a checkbox list of name, strain, generation and birth date.

      I created  a button in the header section which when clicked perfoems the following script.

      Duplicate Record/Request

      Go to Recordd/Request/Page (last)


      Case (GetValue ( Globals::whichchk ;1) =0;mytable::name="";
                GetValue ( Globals::whichchk ;2) =0;mytable::strain="";
                 GetValue ( Globals::whichchk ;3)=0;mytable::Generation ="";
                 GetValue ( Globals::whichchk ;4)=0;mytable::Birthdate="";


      End if

      The Globals table and mytable are not linked.

      I get the following error when I click on a check box of the global field.


      ‘This operation could not be completed because target is not a part of a related record.

      I do not know what is wrong.

      Can we not have global fields in the header of a form?

      Do we need to link global table with mytable ?


        • 1. Re: duplicating only selected fields.

          You have more than one problem

          The error message indicates that the attempted field reference that triggered it refers to a field that is neither global nor from a related table occurrence. If this is a reference to a field in your globals table, I suggest checking storage options on that field as it appears that global storage has not been specified for it.

          But your case function will not work reliably. To understand why, make a copy of your check box formatted field next to the check box formatted copy, but return it's format to "Edit box" configuration. Now click different check boxes and in different orders and note what appears in the edit box. Note how the order in which you click check boxes affects the order of the values that appear in the edit box formatted copy.

          The solution is to use the FilterValues function to check to see if a particular value is selected.

          Then you have the problem that the second part of your case function cannot be used to assign a value to a field. mytable::name="" is a Boolean expression that returns 1 (True) if the name field is equal to an empty string and 0 (False) if it is not.

          You'd need to use a series of IF steps in a script rather than a single case function in a calculation. The first would look like this:

          If [ IsEmpty ( Filtervalues ( Globals::whichchk ; "name" ) ) ]
             Set Field [ mytable::name ; "" ]
          End If

          But if the values in your check box value list are exactly the names of your fields, you could also use this script:

              Set Variable [$K ; value: $K + 1 ]
              Exit Loop If [ $K > valuecount ( Globals::whichchk ) ]
              Set Field By Name ["mytable::" & GetValue ( Globals::whichchk ; $K ) ; "" ]
          End Loop

          But make sure that whichchk is truly a field with global storage specified or none of the above will work.

          • 2. Re: duplicating only selected fields.

            Brilliant !!!

            First of all, you understood my problem correctly even though I thought I was not able to express it clearly.

             Yes, I had not defined globals::whichck with Global Storage – (Common sense but it flies out of the window when under pressure)

            I learnt something new when I created an edit box of the globals::whichck, right next to

            globals::whichck formatted as a value list.

            I saw that the edit box showed the fields I had check marked not ( 0 or 1 for each field that I selected) as I had thought.

            Thanks. I had never thought of seeing a value list based field as an edit box.

            Also, thanks for the loop statement that taught me how to make it generic.

            There is a lot to learn but your prompt reply taught me a lot.

            Thanks again.