User Manual

08.14.2024

MANUAL

FAQ: How can I get the ID of a record I created?

## Answer Please use "[Script](/en/manual/table-management-script)". --- ## Overview If you want to create a new record in the parent table and a linked record in the child table at the same time, and you want to get the ID of the newly created record, you need to implement "[Script](/en/manual/table-management-script)". This is a sample of creating a record in the checklist table (child) linked to the record created in the customer table (parent). ## Preparation This FAQ will proceed based on the parent-child table shown below. ![image](https://pleasanter.org/binaries/79b27676835845ac9d43d45bd8ca53d2) The item used for the link in the checklist table (child) is Class A. Please refer to the following page for how to set up the link. [Table Management: Editor: Detailed Item Settings: Choices: Link \| Pleasanter](https://pleasanter.org/manual/table-management-choices-text-link) ## Operation Procedure 1. Register the following script in script in the table management of the customer table (parent). The execution timing is "Create new". 1. Create a new record in the customer table. 1. Go to the checklist table. 1. Confirm that a record linked to the record created in 2. has been created. ## Sample Code ##### JavaScript ``` $p.events.before_set_Create = function (args) { console.log(args.json); craeteCheckListRecored(args.json[0].Value); } function craeteCheckListRecored(recordId) { $p.apiCreate({ id: 242196, data: { Offset: 0, Title: 'This record was created when a record was created in the customer table.', ClassA: recordId }, done: (data) => { console.log('Success!'); console.log(data); }, fail: (data) => { console.log(data); } }) } ``` ### Supplementary Explanation The part below obtains the record ID when a record is created in the above script. ##### JavaScript ``` $p.events.before_set_Create = function (args) { console.log(args.json); craeteCheckListRecored(args.json[0].Value); } ``` The created record information is stored in the response (args) when the "$p.events.before_set_Create" event is executed. You can check the record ID with "args.json[0].Value". ## Related Information <div id="ManualList"><ul><li><a href="/en/manual/table-management-script">Table Management: Script</a><span>08.13.2024 up</span></li></ul></article></div><input id="SearchTextHidden" type="hidden" value="" />
TOP
このページをシェアする
記載された商品名、各製品名は各社の登録商標または商標です。 © Implem Inc.