Skip to content

Commit 3813a53

Browse files
committed
Implemented "duplicate" method
1 parent 1b68309 commit 3813a53

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

FMDataAPI.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,33 @@ public function create($data = null, $portal = null, $script = null)
637637
}
638638
}
639639

640+
/**
641+
* Duplicate record.
642+
* @param int $recordId The valid recordId value to duplicate.
643+
* @param array $script scripts that should execute right timings. See FileMakerRelation::query().
644+
* @throws Exception In case of any error, an exception arises.
645+
*/
646+
public function duplicate($recordId, $script = null)
647+
{
648+
try {
649+
if ($this->restAPI->login()) {
650+
$request = "{}"; //FileMaker expects an empty object, so we have to set "{}" here
651+
$headers = ["Content-Type" => "application/json"];
652+
$params = ['layouts' => $this->layout, 'records' => $recordId];
653+
if (!is_null($script)) {
654+
$request = $this->buildScriptParameters($script);
655+
}
656+
$this->restAPI->callRestAPI($params, true, 'POST', $request, $headers);
657+
$this->restAPI->storeToProperties();
658+
$this->restAPI->logout();
659+
} else {
660+
return null;
661+
}
662+
} catch (\Exception $e) {
663+
throw $e;
664+
}
665+
}
666+
640667
/**
641668
* Delete on record.
642669
* @param int $recordId The valid recordId value to delete.

0 commit comments

Comments
 (0)