-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config and code to get latest record ID if multiple #38
base: master
Are you sure you want to change the base?
Conversation
I can definitely see the usefulness of needing to do this. You may want to consider and work with the 'Records::getRecordList' method built into REDCap. Behind the scenes there is a 'redcap_record_list' DB table that I believe tracks records by order of creation. The method allows you to only check the order of a specific group of records. Using this and just grabbing the last entry should give you the last created record chronologically. It should make this work even outside of the auto-ID process. |
@moorejr5 amazing. Thank you for suggesting this. I just updated the code with your recommendation. I tested it and it works as expected, though I'm very new to using this method so any review would be appreciated! |
getValue.php
Outdated
if (!is_null($useLatestRecordIdSetting) && isset($useLatestRecordIdSetting[0]) && $useLatestRecordIdSetting[0] === true) { | ||
$recordKeys = array_keys($filterData); | ||
$records = \Records::getRecordList($_POST['otherpid'], [], false, false, null, null, 0, $recordKeys); | ||
$recordId = end($records); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'getRecordList' function could possibly return 'false' in some instances. It's not likely, but you may want some default behavior in case '$records' ends up being false. Something like $recordId = end($records ?: [array_key_first($filterData)]); If you use 'array_key_first' you'd have to set the min-php version in config.json to 7.3, because apparently some people are still using this module on PHP 5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome thanks for bringing this to my attention. I don't want to force 7.3 if I don't need to, so I found and tested another solution.
@moorejr5 Thanks for approving this! What are the next steps? Should I add a blurb to the README? Do you merge it or do I? |
I think it would be worthwhile to update things to at least explain the use of the new setting. You can do the merge if you're fine with it. I believe this module is on the public repo, so it would need a new release version for this. I'm not sure if you've had to go through that process with modules. We can go over it sometime if you haven't so you can see the workflow. |
hi @moorejr5 - thanks for the suggestion. I've added to the docs, including new screenshot. I am very interested in setting learning how to release a new version, and I would love to learn how to do that from you. |
I am working with the PMI team on a solution that uses this plugin where the source project has an ID column called "snapshot_id". Because of a data integrity issue, there can be multiple records with the same snapshot_id, and the client always needs the most recent one. I could fork this EM and make my change for their needs, but I thought I would first consider making it an option on the existing plug-in.
This PR creates a new project-level config option called ``'use-latest-record-id'
that will use the latest record-id if multiple records exist for the Unique Match Field. The code logic is doing a simple
ksort`, so this only works for auto incr int IDs, but that is the default behavior so I think it is useful.What do you think?