> For the complete documentation index, see [llms.txt](https://changelog.airship.co.uk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://changelog.airship.co.uk/august-2024/13-08-2024-data-uploader-unit-and-group-mapping.md).

# 13/08/2024 Data uploader unit and group mapping

patch version 1.2.0

## :tada: Unit and group mapping

**Units and Groups frontend**

* Add `Use Uploaded Location` option to the Unit selection dropdown list on `SelectUnit` page
  * Selecting this value restricts the Group selection to `Use Uploaded Group` and `Use Default Group`
  * Selecting this also removes the option of inserting a group name
* Add `Use Uploaded Group` to the group selection, this value is always available, even if a unit is selected
  * (07/08) Selecting this also removes the option of inserting a group name
* Add `Location ID` , `Location Name` , `Group ID` , `Group Name` to the field selector on the `MatchHeaders` page
  * If `Use Uploaded Location` is selected in the unit field, all options will be available
  * If a unit is chosen and `Use Uploaded Group` is selected in the group field, only the `Group ID` , `Group Name` will be available
  * If neither option is chosen, these fields will not be available for mapping.
  * If `Use Uploaded Location/Group` is selected on unit and or group, but no headers are mapped, the mapping page will return an error.
* A couple of wording changes, as requested on the linked Linear issue.

**Units and Groups backend**

* Instead of setting a unit & group for the full data upload, these are now mapped per contact.
* A new `customUnit` `customGroup` and `defaultGroup` session variable is being kept to keep track of the custom options throughout the functions.
* A `contactSourceIDs` session var array keeps track of the sources corresponding to each unit
  * We set these values on both load and confirmation of the `SelectUnit` page, because the load only gets called on unit change, not on group change.
* An `allowedUnits` and `allowedGroups` array are being kept to validate the groups and units
  * this reduces the number of database calls for each contact
  * this is not kept in session to prevent any wrongful unit and group mapping if these values are altered somehow
* If `Use Default Group` is selected on the group field, and the selected unit has multiple default groups, the contact will be added to all default groups.

**Source ID backend**

* If `Use Uploaded Location` is selected in the unit field, the source id will be mapped to the correct unit on a per-contact basis from a stored source id array.
* Fixed a bug in the contact class that led to contacts not being saved on root units
  * When a single unit and source are passed in, they will now be used (after validation)
  * (for SOAP) when a single group and source id are passed in, they will also now be used

**Singlestore Functionality fix**

* Retrieved data is ordered by `UploadedDataValue.UploadedDataValueID` to guarantee columns are rows are being returned consistently. The bug caused contact data to be mixed across contacts, and columns to appear unsorted. These used to change on page refreshes.

**Unrelated small fix**

* There was a typo in the first name and surname validator that should have prevented urls to be passed in but was not functional.

:man\_technologist: Iris
