Skip to content

I want to transfer the value of a parent table column to a child table column

Answer

Use "Script".
This can be achieved with the "Lookup" function in .NET Framework version 0.50.251 and later, and .NET Core version 1.1.27 and later.


Overview

In tables that are parent-child relationships using the "Link" function, the value of the column entered in the parent table is transferred to the column in the child table.
As an example, when [Table A (parent)] [Table B (child)], the sample code for setting the value of "ClassA" in Table A to "ClassB" in Table B as the link column is shown below. (In this example, a script is set in Table B).
In Pleasanter, if you use $p.apiGet, you can obtain values ​​by ajax POST request just by specifying the record ID.
*If you are using version 1.3.12.0 or earlier, some of the description will be different. Please check the comments in the sample code.

Operation Procedure

  1. Select the table for which you want to set the script and display the record list screen
  2. From the navigation menu, select [Manage]-[Manage Table] to display the Manage table screen
  3. Select the [Script] tab and press the "Create New" button to set the script
  4. After writing the "Title" and "Script", check "Create New" and "Edit" in "Output to"
    *If you have set [Edit in Dialog], you must also check "List"

Code Samples

JavaScript
//Event when loading the edit screen
$p.events.on_editor_load = function () {
    getParentData();
}

//Event called each time the value of "ClassA" in table B is changed
$(document).on('change', '#' + $p.getControl('ClassA')[0].id, function () {
    getParentData();
});

getParentData = function() {
    //Get the value of the specified record in table A only if a value is set in table B's "ClassA"
    if ($p.getControl('ClassA').val()) {
        $p.apiGet({
            //Specify the value (record ID) of table B's "ClassA"
            'id': $p.getControl('ClassA').val(),
            'done': function (data) {
                //Set the value of "ClassA" obtained from table A to table B's "ClassB"
                //*If you are using version 1.3.12.0 or earlier, remove the // at the beginning of the following comment line and delete the line that follows.
                //$p.set($p.getControl('ClassB'), data.Response.Data[0].ClassA);
                $p.set($p.getControl('ClassB'), data.Response.Data[0].ClassHash.ClassA);
            },
            'fail': function (data) {
                console.log(data);
            }
        });
    } else {
        //If no value is set in "ClassA" of table B, set an empty string to "ClassB" of table B
        $p.set($p.getControl('ClassB'), '');
    }
}