how to use sortBy in kotlin - kotlin
Hey I want to sort the data class in kotlin. I tried to sort by ascending order, but it not sorting correctly.
ProductVariant.kt
data class ProductVariant(
val strength: String? = null,
val quantity: String? = null,
val subscription: String? = null
)
First I need to sort by strength value then after sorting, I want to sort by quantity value in ascending order. I tried some code to sort first by strength it's not working.
Options.kt
fun main() {
val list = getUnSortedDataList()
val sortedList = list.sortedBy {
it.subscription
}
sortedList.forEach {
println(it)
}
}
fun getUnSortedDataList(): List<ProductVariant> {
return listOf(
ProductVariant(strength = "75", quantity = "14", subscription = "1"),
ProductVariant(strength = "75", quantity = "14", subscription = "3"),
ProductVariant(strength = "75", quantity = "14", subscription = "6"),
ProductVariant(strength = "75", quantity = "14", subscription = "9"),
ProductVariant(strength = "75", quantity = "14", subscription = "12"),
ProductVariant(strength = "25", quantity = "8", subscription = "1"),
ProductVariant(strength = "25", quantity = "8", subscription = "3"),
ProductVariant(strength = "25", quantity = "8", subscription = "6"),
ProductVariant(strength = "25", quantity = "8", subscription = "9"),
ProductVariant(strength = "25", quantity = "8", subscription = "12"),
ProductVariant(strength = "50", quantity = "14", subscription = "1"),
ProductVariant(strength = "50", quantity = "14", subscription = "3"),
ProductVariant(strength = "50", quantity = "14", subscription = "6"),
ProductVariant(strength = "50", quantity = "14", subscription = "9"),
ProductVariant(strength = "50", quantity = "14", subscription = "12"),
ProductVariant(strength = "75", quantity = "10", subscription = "1"),
ProductVariant(strength = "75", quantity = "10", subscription = "3"),
ProductVariant(strength = "75", quantity = "10", subscription = "6"),
ProductVariant(strength = "75", quantity = "10", subscription = "9"),
ProductVariant(strength = "75", quantity = "10", subscription = "12"),
ProductVariant(strength = "25", quantity = "2", subscription = "1"),
ProductVariant(strength = "25", quantity = "2", subscription = "3"),
ProductVariant(strength = "25", quantity = "2", subscription = "6"),
ProductVariant(strength = "25", quantity = "2", subscription = "9"),
ProductVariant(strength = "25", quantity = "2", subscription = "12"),
ProductVariant(strength = "25", quantity = "4", subscription = "1"),
ProductVariant(strength = "25", quantity = "4", subscription = "3"),
ProductVariant(strength = "25", quantity = "4", subscription = "6"),
ProductVariant(strength = "25", quantity = "4", subscription = "9"),
ProductVariant(strength = "25", quantity = "4", subscription = "12"),
ProductVariant(strength = "25", quantity = "6", subscription = "1"),
ProductVariant(strength = "25", quantity = "6", subscription = "3"),
ProductVariant(strength = "25", quantity = "6", subscription = "6"),
ProductVariant(strength = "25", quantity = "6", subscription = "9"),
ProductVariant(strength = "25", quantity = "6", subscription = "12"),
ProductVariant(strength = "25", quantity = "10", subscription = "1"),
ProductVariant(strength = "25", quantity = "10", subscription = "3"),
ProductVariant(strength = "25", quantity = "10", subscription = "6"),
ProductVariant(strength = "25", quantity = "10", subscription = "9"),
ProductVariant(strength = "25", quantity = "10", subscription = "12"),
ProductVariant(strength = "25", quantity = "12", subscription = "1"),
ProductVariant(strength = "25", quantity = "12", subscription = "3"),
ProductVariant(strength = "25", quantity = "12", subscription = "6"),
ProductVariant(strength = "25", quantity = "12", subscription = "9"),
ProductVariant(strength = "25", quantity = "12", subscription = "12"),
ProductVariant(strength = "25", quantity = "14", subscription = "1"),
ProductVariant(strength = "25", quantity = "14", subscription = "3"),
ProductVariant(strength = "25", quantity = "14", subscription = "6"),
ProductVariant(strength = "25", quantity = "14", subscription = "9"),
ProductVariant(strength = "25", quantity = "14", subscription = "12"),
ProductVariant(strength = "50", quantity = "2", subscription = "1"),
ProductVariant(strength = "50", quantity = "2", subscription = "3"),
ProductVariant(strength = "50", quantity = "2", subscription = "6"),
ProductVariant(strength = "50", quantity = "2", subscription = "9"),
ProductVariant(strength = "50", quantity = "2", subscription = "12"),
ProductVariant(strength = "50", quantity = "4", subscription = "1"),
ProductVariant(strength = "50", quantity = "4", subscription = "3"),
ProductVariant(strength = "50", quantity = "4", subscription = "6"),
ProductVariant(strength = "50", quantity = "4", subscription = "9"),
ProductVariant(strength = "50", quantity = "4", subscription = "12"),
ProductVariant(strength = "50", quantity = "6", subscription = "1"),
ProductVariant(strength = "50", quantity = "6", subscription = "3"),
ProductVariant(strength = "50", quantity = "6", subscription = "6"),
ProductVariant(strength = "50", quantity = "6", subscription = "9"),
ProductVariant(strength = "50", quantity = "6", subscription = "12"),
ProductVariant(strength = "50", quantity = "10", subscription = "1"),
ProductVariant(strength = "50", quantity = "10", subscription = "3"),
ProductVariant(strength = "50", quantity = "10", subscription = "6"),
ProductVariant(strength = "50", quantity = "10", subscription = "9"),
ProductVariant(strength = "50", quantity = "10", subscription = "12"),
ProductVariant(strength = "50", quantity = "12", subscription = "1"),
ProductVariant(strength = "50", quantity = "12", subscription = "3"),
ProductVariant(strength = "50", quantity = "12", subscription = "6"),
ProductVariant(strength = "50", quantity = "12", subscription = "9"),
ProductVariant(strength = "50", quantity = "12", subscription = "12"),
ProductVariant(strength = "75", quantity = "2", subscription = "1"),
ProductVariant(strength = "75", quantity = "2", subscription = "3"),
ProductVariant(strength = "75", quantity = "2", subscription = "6"),
ProductVariant(strength = "75", quantity = "2", subscription = "9"),
ProductVariant(strength = "75", quantity = "2", subscription = "12"),
ProductVariant(strength = "75", quantity = "6", subscription = "1"),
ProductVariant(strength = "75", quantity = "6", subscription = "3"),
ProductVariant(strength = "75", quantity = "6", subscription = "6"),
ProductVariant(strength = "75", quantity = "6", subscription = "9"),
ProductVariant(strength = "75", quantity = "6", subscription = "12"),
ProductVariant(strength = "75", quantity = "8", subscription = "1"),
ProductVariant(strength = "75", quantity = "8", subscription = "3"),
ProductVariant(strength = "75", quantity = "8", subscription = "6"),
ProductVariant(strength = "75", quantity = "8", subscription = "9"),
ProductVariant(strength = "75", quantity = "8", subscription = "12"),
ProductVariant(strength = "75", quantity = "12", subscription = "1"),
ProductVariant(strength = "75", quantity = "12", subscription = "3"),
ProductVariant(strength = "75", quantity = "12", subscription = "6"),
ProductVariant(strength = "75", quantity = "12", subscription = "9"),
ProductVariant(strength = "75", quantity = "12", subscription = "12"),
ProductVariant(strength = "50", quantity = "8", subscription = "1"),
ProductVariant(strength = "50", quantity = "8", subscription = "3"),
ProductVariant(strength = "50", quantity = "8", subscription = "6"),
ProductVariant(strength = "50", quantity = "8", subscription = "9"),
ProductVariant(strength = "50", quantity = "8", subscription = "12"),
ProductVariant(strength = "75", quantity = "4", subscription = "1"),
ProductVariant(strength = "75", quantity = "4", subscription = "3"),
ProductVariant(strength = "75", quantity = "4", subscription = "6"),
ProductVariant(strength = "75", quantity = "4", subscription = "9"),
ProductVariant(strength = "75", quantity = "4", subscription = "12")
)
}
Getting output through above code is
ProductVariant(strength=75, quantity=14, subscription=1)
ProductVariant(strength=25, quantity=8, subscription=1)
ProductVariant(strength=50, quantity=14, subscription=1)
ProductVariant(strength=75, quantity=10, subscription=1)
ProductVariant(strength=25, quantity=2, subscription=1)
ProductVariant(strength=25, quantity=4, subscription=1)
ProductVariant(strength=25, quantity=6, subscription=1)
ProductVariant(strength=25, quantity=10, subscription=1)
ProductVariant(strength=25, quantity=12, subscription=1)
ProductVariant(strength=25, quantity=14, subscription=1)
ProductVariant(strength=50, quantity=2, subscription=1)
ProductVariant(strength=50, quantity=4, subscription=1)
ProductVariant(strength=50, quantity=6, subscription=1)
ProductVariant(strength=50, quantity=10, subscription=1)
ProductVariant(strength=50, quantity=12, subscription=1)
ProductVariant(strength=75, quantity=2, subscription=1)
ProductVariant(strength=75, quantity=6, subscription=1)
ProductVariant(strength=75, quantity=8, subscription=1)
ProductVariant(strength=75, quantity=12, subscription=1)
ProductVariant(strength=50, quantity=8, subscription=1)
ProductVariant(strength=75, quantity=4, subscription=1)
ProductVariant(strength=75, quantity=14, subscription=12)
ProductVariant(strength=25, quantity=8, subscription=12)
ProductVariant(strength=50, quantity=14, subscription=12)
ProductVariant(strength=75, quantity=10, subscription=12)
ProductVariant(strength=25, quantity=2, subscription=12)
ProductVariant(strength=25, quantity=4, subscription=12)
ProductVariant(strength=25, quantity=6, subscription=12)
ProductVariant(strength=25, quantity=10, subscription=12)
ProductVariant(strength=25, quantity=12, subscription=12)
ProductVariant(strength=25, quantity=14, subscription=12)
ProductVariant(strength=50, quantity=2, subscription=12)
ProductVariant(strength=50, quantity=4, subscription=12)
ProductVariant(strength=50, quantity=6, subscription=12)
ProductVariant(strength=50, quantity=10, subscription=12)
ProductVariant(strength=50, quantity=12, subscription=12)
ProductVariant(strength=75, quantity=2, subscription=12)
ProductVariant(strength=75, quantity=6, subscription=12)
ProductVariant(strength=75, quantity=8, subscription=12)
ProductVariant(strength=75, quantity=12, subscription=12)
ProductVariant(strength=50, quantity=8, subscription=12)
ProductVariant(strength=75, quantity=4, subscription=12)
ProductVariant(strength=75, quantity=14, subscription=3)
ProductVariant(strength=25, quantity=8, subscription=3)
ProductVariant(strength=50, quantity=14, subscription=3)
ProductVariant(strength=75, quantity=10, subscription=3)
ProductVariant(strength=25, quantity=2, subscription=3)
ProductVariant(strength=25, quantity=4, subscription=3)
ProductVariant(strength=25, quantity=6, subscription=3)
ProductVariant(strength=25, quantity=10, subscription=3)
ProductVariant(strength=25, quantity=12, subscription=3)
ProductVariant(strength=25, quantity=14, subscription=3)
ProductVariant(strength=50, quantity=2, subscription=3)
ProductVariant(strength=50, quantity=4, subscription=3)
ProductVariant(strength=50, quantity=6, subscription=3)
ProductVariant(strength=50, quantity=10, subscription=3)
ProductVariant(strength=50, quantity=12, subscription=3)
ProductVariant(strength=75, quantity=2, subscription=3)
ProductVariant(strength=75, quantity=6, subscription=3)
ProductVariant(strength=75, quantity=8, subscription=3)
ProductVariant(strength=75, quantity=12, subscription=3)
ProductVariant(strength=50, quantity=8, subscription=3)
ProductVariant(strength=75, quantity=4, subscription=3)
ProductVariant(strength=75, quantity=14, subscription=6)
ProductVariant(strength=25, quantity=8, subscription=6)
ProductVariant(strength=50, quantity=14, subscription=6)
ProductVariant(strength=75, quantity=10, subscription=6)
ProductVariant(strength=25, quantity=2, subscription=6)
ProductVariant(strength=25, quantity=4, subscription=6)
ProductVariant(strength=25, quantity=6, subscription=6)
ProductVariant(strength=25, quantity=10, subscription=6)
ProductVariant(strength=25, quantity=12, subscription=6)
ProductVariant(strength=25, quantity=14, subscription=6)
ProductVariant(strength=50, quantity=2, subscription=6)
ProductVariant(strength=50, quantity=4, subscription=6)
ProductVariant(strength=50, quantity=6, subscription=6)
ProductVariant(strength=50, quantity=10, subscription=6)
ProductVariant(strength=50, quantity=12, subscription=6)
ProductVariant(strength=75, quantity=2, subscription=6)
ProductVariant(strength=75, quantity=6, subscription=6)
ProductVariant(strength=75, quantity=8, subscription=6)
ProductVariant(strength=75, quantity=12, subscription=6)
ProductVariant(strength=50, quantity=8, subscription=6)
ProductVariant(strength=75, quantity=4, subscription=6)
ProductVariant(strength=75, quantity=14, subscription=9)
ProductVariant(strength=25, quantity=8, subscription=9)
ProductVariant(strength=50, quantity=14, subscription=9)
ProductVariant(strength=75, quantity=10, subscription=9)
ProductVariant(strength=25, quantity=2, subscription=9)
ProductVariant(strength=25, quantity=4, subscription=9)
ProductVariant(strength=25, quantity=6, subscription=9)
ProductVariant(strength=25, quantity=10, subscription=9)
ProductVariant(strength=25, quantity=12, subscription=9)
ProductVariant(strength=25, quantity=14, subscription=9)
ProductVariant(strength=50, quantity=2, subscription=9)
ProductVariant(strength=50, quantity=4, subscription=9)
ProductVariant(strength=50, quantity=6, subscription=9)
ProductVariant(strength=50, quantity=10, subscription=9)
ProductVariant(strength=50, quantity=12, subscription=9)
ProductVariant(strength=75, quantity=2, subscription=9)
ProductVariant(strength=75, quantity=6, subscription=9)
ProductVariant(strength=75, quantity=8, subscription=9)
ProductVariant(strength=75, quantity=12, subscription=9)
ProductVariant(strength=50, quantity=8, subscription=9)
ProductVariant(strength=75, quantity=4, subscription=9)
I want like this
Expected output
ProductVariant(strength = "25", quantity = "2", subscription = "1"),
ProductVariant(strength = "25", quantity = "2", subscription = "3"),
ProductVariant(strength = "25", quantity = "2", subscription = "6"),
ProductVariant(strength = "25", quantity = "2", subscription = "9"),
ProductVariant(strength = "25", quantity = "2", subscription = "12"),
ProductVariant(strength = "25", quantity = "4", subscription = "1"),
ProductVariant(strength = "25", quantity = "4", subscription = "3"),
ProductVariant(strength = "25", quantity = "4", subscription = "6"),
ProductVariant(strength = "25", quantity = "4", subscription = "9"),
ProductVariant(strength = "25", quantity = "4", subscription = "12"),
ProductVariant(strength = "25", quantity = "6", subscription = "1"),
ProductVariant(strength = "25", quantity = "6", subscription = "3"),
ProductVariant(strength = "25", quantity = "6", subscription = "6"),
ProductVariant(strength = "25", quantity = "6", subscription = "9"),
ProductVariant(strength = "25", quantity = "6", subscription = "12"),
ProductVariant(strength = "25", quantity = "8", subscription = "1"),
ProductVariant(strength = "25", quantity = "8", subscription = "3"),
ProductVariant(strength = "25", quantity = "8", subscription = "6"),
ProductVariant(strength = "25", quantity = "8", subscription = "9"),
ProductVariant(strength = "25", quantity = "8", subscription = "12"),
ProductVariant(strength = "25", quantity = "10", subscription = "1"),
ProductVariant(strength = "25", quantity = "10", subscription = "3"),
ProductVariant(strength = "25", quantity = "10", subscription = "6"),
ProductVariant(strength = "25", quantity = "10", subscription = "9"),
ProductVariant(strength = "25", quantity = "10", subscription = "12"),
ProductVariant(strength = "25", quantity = "12", subscription = "1"),
ProductVariant(strength = "25", quantity = "12", subscription = "3"),
ProductVariant(strength = "25", quantity = "12", subscription = "6"),
ProductVariant(strength = "25", quantity = "12", subscription = "9"),
ProductVariant(strength = "25", quantity = "12", subscription = "12"),
ProductVariant(strength = "25", quantity = "14", subscription = "1"),
ProductVariant(strength = "25", quantity = "14", subscription = "3"),
ProductVariant(strength = "25", quantity = "14", subscription = "6"),
ProductVariant(strength = "25", quantity = "14", subscription = "9"),
ProductVariant(strength = "25", quantity = "14", subscription = "12"),
ProductVariant(strength = "50", quantity = "2", subscription = "1"),
ProductVariant(strength = "50", quantity = "2", subscription = "3"),
ProductVariant(strength = "50", quantity = "2", subscription = "6"),
ProductVariant(strength = "50", quantity = "2", subscription = "9"),
ProductVariant(strength = "50", quantity = "2", subscription = "12"),
ProductVariant(strength = "50", quantity = "4", subscription = "1"),
ProductVariant(strength = "50", quantity = "4", subscription = "3"),
ProductVariant(strength = "50", quantity = "4", subscription = "6"),
ProductVariant(strength = "50", quantity = "4", subscription = "9"),
ProductVariant(strength = "50", quantity = "4", subscription = "12"),
ProductVariant(strength = "50", quantity = "6", subscription = "1"),
ProductVariant(strength = "50", quantity = "6", subscription = "3"),
ProductVariant(strength = "50", quantity = "6", subscription = "6"),
ProductVariant(strength = "50", quantity = "6", subscription = "9"),
ProductVariant(strength = "50", quantity = "6", subscription = "12"),
ProductVariant(strength = "50", quantity = "8", subscription = "1"),
ProductVariant(strength = "50", quantity = "8", subscription = "3"),
ProductVariant(strength = "50", quantity = "8", subscription = "6"),
ProductVariant(strength = "50", quantity = "8", subscription = "9"),
ProductVariant(strength = "50", quantity = "8", subscription = "12"),
ProductVariant(strength = "50", quantity = "10", subscription = "1"),
ProductVariant(strength = "50", quantity = "10", subscription = "3"),
ProductVariant(strength = "50", quantity = "10", subscription = "6"),
ProductVariant(strength = "50", quantity = "10", subscription = "9"),
ProductVariant(strength = "50", quantity = "10", subscription = "12"),
ProductVariant(strength = "50", quantity = "12", subscription = "1"),
ProductVariant(strength = "50", quantity = "12", subscription = "3"),
ProductVariant(strength = "50", quantity = "12", subscription = "6"),
ProductVariant(strength = "50", quantity = "12", subscription = "9"),
ProductVariant(strength = "50", quantity = "12", subscription = "12"),
ProductVariant(strength = "50", quantity = "14", subscription = "1"),
ProductVariant(strength = "50", quantity = "14", subscription = "3"),
ProductVariant(strength = "50", quantity = "14", subscription = "6"),
ProductVariant(strength = "50", quantity = "14", subscription = "9"),
ProductVariant(strength = "50", quantity = "14", subscription = "12"),
ProductVariant(strength = "75", quantity = "2", subscription = "1"),
ProductVariant(strength = "75", quantity = "2", subscription = "3"),
ProductVariant(strength = "75", quantity = "2", subscription = "6"),
ProductVariant(strength = "75", quantity = "2", subscription = "9"),
ProductVariant(strength = "75", quantity = "2", subscription = "12"),
ProductVariant(strength = "75", quantity = "4", subscription = "1"),
ProductVariant(strength = "75", quantity = "4", subscription = "3"),
ProductVariant(strength = "75", quantity = "4", subscription = "6"),
ProductVariant(strength = "75", quantity = "4", subscription = "9"),
ProductVariant(strength = "75", quantity = "4", subscription = "12"),
ProductVariant(strength = "75", quantity = "6", subscription = "1"),
ProductVariant(strength = "75", quantity = "6", subscription = "3"),
ProductVariant(strength = "75", quantity = "6", subscription = "6"),
ProductVariant(strength = "75", quantity = "6", subscription = "9"),
ProductVariant(strength = "75", quantity = "6", subscription = "12"),
ProductVariant(strength = "75", quantity = "8", subscription = "1"),
ProductVariant(strength = "75", quantity = "8", subscription = "3"),
ProductVariant(strength = "75", quantity = "8", subscription = "6"),
ProductVariant(strength = "75", quantity = "8", subscription = "9"),
ProductVariant(strength = "75", quantity = "8", subscription = "12"),
ProductVariant(strength = "75", quantity = "10", subscription = "1"),
ProductVariant(strength = "75", quantity = "10", subscription = "3"),
ProductVariant(strength = "75", quantity = "10", subscription = "6"),
ProductVariant(strength = "75", quantity = "10", subscription = "9"),
ProductVariant(strength = "75", quantity = "10", subscription = "12"),
ProductVariant(strength = "75", quantity = "12", subscription = "1"),
ProductVariant(strength = "75", quantity = "12", subscription = "3"),
ProductVariant(strength = "75", quantity = "12", subscription = "6"),
ProductVariant(strength = "75", quantity = "12", subscription = "9"),
ProductVariant(strength = "75", quantity = "12", subscription = "12"),
ProductVariant(strength = "75", quantity = "14", subscription = "1"),
ProductVariant(strength = "75", quantity = "14", subscription = "3"),
ProductVariant(strength = "75", quantity = "14", subscription = "6"),
ProductVariant(strength = "75", quantity = "14", subscription = "9"),
ProductVariant(strength = "75", quantity = "14", subscription = "12")
val sortedList = list.sortedWith(
compareBy<ProductVariant> { // or compareByDescending
it.strength?.toIntOrNull() ?: 0 // or java.lang.Integer.MAX_VALUE
}.thenBy { // or thenByDescending
it.quantity?.toIntOrNull() ?: 0 // or java.lang.Integer.MAX_VALUE
}
)
Edit: Changed from toInt() to toIntOrNull() as suggested by Ivo Beckers (see his comment below).
You sort strings, not numbers and by default strings are sorted in lexicographic order. You just need to convert these values to integers:
list.sortedBy { it.strength?.toInt() }
Use sortedWith + compareBy:
val sortedList = list.sortedWith(compareBy({ it.strength?.toInt() ?: 0 }, { it.quantity?.toInt() ?: 0 }, { it.subscription?.toInt() ?: 0 }))
Related
All data from first table is not showing proper data in sql
I am trying to add two tables, in which first table contains all the video details, and in second table details of video seen by the user with user_id and video_id. I just want to add both the tables and it will show all the list of videos from first table but if the video is seen by the user, status will show 1 else 1. Here is my query, SELECT videos.id, videos.lang_id, videos.medical_type_id, videos.name, videos.description, videos.thumbnail, videos.video, videos.video_type, videos.delete_status, CASE WHEN video_quews.user_id = $user_id THEN $user_id ELSE 'ok' END AS user_id, video_quews.video_id, video_quews.created_at, CASE WHEN video_quews.video_id = videos.id THEN 1 ELSE 0 END AS status FROM videos LEFT JOIN video_quews ON videos.id = video_quews.video_id ORDER BY video_quews.video_id DESC Currently, videos are repeating. Please help me out here is my response, { "message": "All related videos", "status": "success", "code": 200, "videos": [ { "id": "30", "lang_id": "2", "medical_type_id": "15", "name": "Fracture", "thumbnail": "thumbnail_images/1579869167.png", "video": "videos/fracture.m4v", "video_type": "2", "delete_status": "1", "user_id": "6", "video_id": "30", "created_at": "2021-03-04 23:29:50", "status": "1" }, { "id": "16", "lang_id": "2", "medical_type_id": "14", "name": "Electrocution", "thumbnail": "thumbnail_images/1579698529.png", "video": "videos/ELECTROCUTION.m4v", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": "16", "created_at": "2021-03-05 08:19:29", "status": "1" }, { "id": "15", "lang_id": "2", "medical_type_id": "13", "name": "Adult CPR & AED(Cardiac Arrest)", "thumbnail": "thumbnail_images/1579698505.png", "video": "videos/CPR1.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": "15", "created_at": "2021-03-05 08:18:38", "status": "1" }, { "id": "14", "lang_id": "2", "medical_type_id": "12", "name": "Choking", "thumbnail": "thumbnail_images/1579698405.png", "video": "videos/Choking.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": "14", "created_at": "2021-03-05 08:17:47", "status": "1" }, { "id": "13", "lang_id": "2", "medical_type_id": "11", "name": "Chest pain", "thumbnail": "thumbnail_images/1579698381.png", "video": "videos/CHESTPAIN.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": "13", "created_at": "2021-03-05 08:17:20", "status": "1" }, { "id": "12", "lang_id": "2", "medical_type_id": "10", "name": "Burns", "thumbnail": "thumbnail_images/1579698360.png", "video": "videos/Burns.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": "12", "created_at": "2021-03-05 08:16:39", "status": "1" }, { "id": "11", "lang_id": "2", "medical_type_id": "9", "name": "Breathing Difficulties", "thumbnail": "thumbnail_images/1579698344.png", "video": "videos/BreathingDifficulties.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": "11", "created_at": "2021-03-05 08:16:19", "status": "1" }, { "id": "8", "lang_id": "2", "medical_type_id": "6", "name": "Asthma", "thumbnail": "thumbnail_images/1579698286.png", "video": "videos/ASTHMA.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": "8", "created_at": "2021-03-05 08:15:59", "status": "1" }, { "id": "24", "lang_id": "2", "medical_type_id": "22", "name": "Fits/Seizures", "thumbnail": "thumbnail_images/1579698775.png", "video": "videos/SEIZURES.m4v", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "26", "lang_id": "2", "medical_type_id": "24", "name": "Sprain, strain", "thumbnail": "thumbnail_images/1579698853.png", "video": "videos/SPRAIN&STRAIN.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "28", "lang_id": "2", "medical_type_id": "26", "name": "Disposing Glove", "thumbnail": "thumbnail_images/1579698903.png", "video": "videos/disposingglove.mp4", "video_type": "1", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "31", "lang_id": "2", "medical_type_id": "8", "name": "Bleeding", "thumbnail": "thumbnail_images/1581498917.png", "video": "videos/bleeding.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "18", "lang_id": "2", "medical_type_id": "16", "name": "Gunshot Wound", "thumbnail": "thumbnail_images/1579698550.png", "video": "videos/Gunshot.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "20", "lang_id": "2", "medical_type_id": "18", "name": "Hypoglycemia", "thumbnail": "thumbnail_images/1579698684.png", "video": "videos/Hypoglycemia.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "22", "lang_id": "2", "medical_type_id": "20", "name": "Nose Bleeding", "thumbnail": "thumbnail_images/1579698728.png", "video": "videos/nosebleeding.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "25", "lang_id": "2", "medical_type_id": "23", "name": "Snake Bite", "thumbnail": "thumbnail_images/1579698801.png", "video": "videos/SnakeBite.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "27", "lang_id": "2", "medical_type_id": "25", "name": "Stroke", "thumbnail": "thumbnail_images/1579698879.png", "video": "videos/STROKE.m4v", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "29", "lang_id": "2", "medical_type_id": "27", "name": "Dog Bite", "thumbnail": "thumbnail_images/1579698934.png", "video": "videos/Dogbite.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "32", "lang_id": "2", "medical_type_id": "7", "name": "Allergy", "thumbnail": "thumbnail_images/1581580973.png", "video": "videos/Allergy.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "19", "lang_id": "2", "medical_type_id": "17", "name": "Hyperthermia(Heat Exhaustion)", "thumbnail": "thumbnail_images/1579698575.png", "video": "videos/Hyperthermia.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "21", "lang_id": "2", "medical_type_id": "19", "name": "Introduction", "thumbnail": "thumbnail_images/1579698707.png", "video": "videos/intro.mp4", "video_type": "1", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" }, { "id": "23", "lang_id": "2", "medical_type_id": "21", "name": "Recovery Position", "thumbnail": "thumbnail_images/1579698747.png", "video": "videos/RecoveryPosition.mp4", "video_type": "2", "delete_status": "1", "user_id": "ok", "video_id": null, "created_at": null, "status": "0" } ], } Below is my database, enter image description here
I just want to add both the tables and it will show all the list of videos from first table but if the video is seen by the user, status will show 1 else 1. I think you want a flag indicating if a user has seen a video. For this, I suggest EXISTS: select v.*, (case when exists (select 1 from video_quews vq where v.id = vq.video_id and vq.user_id = $user_id ) then 1 else 0 end) as has_user_flag from videos v
Flatten multiple names arrays within variant json column in snowflake
I have a web scraper dumping data into a variant column in a Snowflake database. This is acraping page data as then creates json arrays for various tables found within the page. Here is an example of the type of json i would find using a Soccer analogy: { "dom_url": "https://www.soccertables.com/european_tables", "event_id": "01b2722a-d8e6-4f67-95d0-8dd7ba088a4a", "event_utc_time": "2020-05-11 09:01:14.821", "ip_address": "125.238.134.96", "table_1": [ { "position": "1", "team_name": "Liverpool", "games_played": "29", "games_won": "26", "games_drawn": "2", "games_lost": "1", "goals_for": "75", "goals_against": "35" "points": "80" }, { "position": "2", "team_name": "Man. City", "games_played": "29", "games_won": "20", "games_drawn": "5", "games_lost": "4", "goals_for": "60", "goals_against": "45" "points": "65" }, { "position": "...", "team_name": "...", "games_played": "...", "games_won": "...", "games_drawn": "...", "games_lost": "...", "goals_for": "...", "goals_against": "..." "points": "..." } ], "table_2": [ { "position": "1", "team_name": "Bayern Munich", "games_played": "29", "games_won": "26", "games_drawn": "2", "games_lost": "1", "goals_for": "75", "goals_against": "35" "points": "80" }, { "position": "2", "team_name": "Bayer Leverkussen", "games_played": "29", "games_won": "20", "games_drawn": "5", "games_lost": "4", "goals_for": "60", "goals_against": "45" "points": "65" }, { "position": "...", "team_name": "...", "games_played": "...", "games_won": "...", "games_drawn": "...", "games_lost": "...", "goals_for": "...", "goals_against": "..." "points": "..." } ], "referrer_url": "https://www.soccertables.com", } Ideally, i'd like the output of this to be a flat, relational table: table_name position team_name games_played etc... table_1 1 Liverpool 29 ... table_1 2 Man. City 29 ... table_2 1 Bayern Munich 29 ... .... I know that if i were only interested in table_1 i could do this: SELECT v.value:position::NUMBER POSITION , v.value:team_name::STRING TEAM_NAME , v.value:games_played::NUMBER GAMES_PLAYED , ... FROM JSON_TABLE a1, LATERAL FLATTEN(JSON_DATA:table_1) v and that i could do the same for table_2 and union them, but there can be N possibilities with regards to the table_N placeholder. I've looked at doing LATERAL FLATTEN multiple times: SELECT v.value:position::NUMBER POSITION , v.value:team_name::STRING TEAM_NAME , v.value:games_played::NUMBER GAMES_PLAYED , ... FROM JSON_TABLE a1, LATERAL FLATTEN(JSON_DATA:table_1) v, LATERAL FLATTEN(JSON_DATA:table_2) v2 But this results in duplication of data, and does not allow me to put each tables columns all in a single relational structure. I'm sure there is something simple that i am missing here, but i've reached a point where i think i've been staring at this too long, and just can';t see it. Thanks in advance, S
If you are trying to create a single, flattened view of the table_n data, as well as the attributes of at the first level, then something like this would work. WITH x AS ( SELECT '{ "dom_url": "https://www.soccertables.com/european_tables", "event_id": "01b2722a-d8e6-4f67-95d0-8dd7ba088a4a", "event_utc_time": "2020-05-11 09:01:14.821", "ip_address": "125.238.134.96", "table_1": [ { "position": "1", "team_name": "Liverpool", "games_played": "29", "games_won": "26", "games_drawn": "2", "games_lost": "1", "goals_for": "75", "goals_against": "35", "points": "80" }, { "position": "2", "team_name": "Man. City", "games_played": "29", "games_won": "20", "games_drawn": "5", "games_lost": "4", "goals_for": "60", "goals_against": "45", "points": "65" }, { "position": "...", "team_name": "...", "games_played": "...", "games_won": "...", "games_drawn": "...", "games_lost": "...", "goals_for": "...", "goals_against": "...", "points": "..." } ], "table_2": [ { "position": "1", "team_name": "Bayern Munich", "games_played": "29", "games_won": "26", "games_drawn": "2", "games_lost": "1", "goals_for": "75", "goals_against": "35", "points": "80" }, { "position": "2", "team_name": "Bayer Leverkussen", "games_played": "29", "games_won": "20", "games_drawn": "5", "games_lost": "4", "goals_for": "60", "goals_against": "45", "points": "65" }, { "position": "...", "team_name": "...", "games_played": "...", "games_won": "...", "games_drawn": "...", "games_lost": "...", "goals_for": "...", "goals_against": "...", "points": "..." } ], "referrer_url": "https://www.soccertables.com", }' as var) SELECT parse_json(x.var):dom_url::string, parse_json(x.var):event_id::string, parse_json(x.var):event_utc_time::string, parse_json(x.var):ip_address::string, x3.value:games_drawn::string, x3.value:games_lost::string, x3.value:games_played::string, x3.value:games_won::string, x3.value:goals_against::string, x3.value:goals_for::string, x3.value:points::string, x3.value:position::string, x3.value:team_name::string FROM x ,LATERAL FLATTEN(parse_json(x.var)) x2 ,LATERAL FLATTEN(X2.VALUE) x3; The CTE is obviously just to show the example with the sample JSON you provided. If you care about which records came from which table, you can also include x2.key as an element in your SELECT.
Postgres GROUP BY, SUBSTRING and SUM Query Issue
I am trying to write a GROUP BY query but I am struggling to achieve the desired result. I am including A JSON object that represent the DB table with some data. SELECT * FROM tb_transaction "tb_transaction": [ { "id": "121", "profile_id": "57", "event_id": "45", "activity_id": "67", "payment_type": "EFT", "transaction_type": "activity_registration", "gl_code": "1234-56-102-020", "description": "Golf", "amount": "1500", "paid": "f", "invoice_number": "0006" }, { "id": "117", "profile_id": "57", "event_id": "45", "activity_id": "65", "payment_type": "EFT", "transaction_type": "activity_registration", "gl_code": "1234-56-102-056", "description": "Cuppa", "amount": "100", "paid": "f", "invoice_number": "0006" }, { "id": "120", "profile_id": "57", "event_id": "45", "activity_id": "70", "payment_type": "EFT", "transaction_type": "activity_registration", "gl_code": "1234-13-102-064", "description": "Nutrition & Lifestyle", "amount": "510", "paid": "f", "invoice_number": "0006" }, { "id": "125", "profile_id": "207", "event_id": "45", "activity_id": "65", "payment_type": "Cash", "transaction_type": "activity_registration", "gl_code": "1234-56-102-056", "description": "Cuppa", "amount": "100", "paid": "f", "invoice_number": "0007" }, { "id": "126", "profile_id": "207", "event_id": "45", "activity_id": "65", "payment_type": "Cash", "transaction_type": "merchandise", "gl_code": "3400-56-102-056", "description": "Cap", "amount": "20", "paid": "f", "invoice_number": "0007" }, { "id": "128", "profile_id": "193", "event_id": "45", "activity_id": "70", "payment_type": "SnapScan", "transaction_type": "activity_registration", "gl_code": "1234-13-102-064", "description": "Nutrition & Lifestyle", "amount": "510", "paid": "f", "invoice_number": "0008" }, { "id": "131", "profile_id": "193", "event_id": "45", "activity_id": "65", "payment_type": "SnapScan", "transaction_type": "merchandise", "gl_code": "3400-56-102-056", "description": "Water Bottle", "amount": "10", "paid": "f", "invoice_number": "0008" }, { "id": "130", "profile_id": "193", "event_id": "45", "activity_id": "65", "payment_type": "SnapScan", "transaction_type": "activity_registration", "gl_code": "1234-56-102-056", "description": "Cuppa", "amount": "100", "paid": "f", "invoice_number": "0008" } ] My current query and its result. SELECT gl_code, transaction_type, activity_id, payment_type, description, SUM(amount) AS amount FROM tb_transaction WHERE event_id = 45 AND paid = false GROUP BY gl_code, transaction_type, activity_id, payment_type, description ORDER BY gl_code; "RECORDS": [ { "gl_code": "1234-13-102-064", "transaction_type": "activity_registration", "activity_id": "70", "payment_type": "EFT", "description": "Nutrition & Lifestyle", "amount": "510" }, { "gl_code": "1234-13-102-064", "transaction_type": "activity_registration", "activity_id": "70", "payment_type": "SnapScan", "description": "Nutrition & Lifestyle", "amount": "510" }, { "gl_code": "1234-56-102-056", "transaction_type": "activity_registration", "activity_id": "65", "payment_type": "Cash", "description": "Cuppa", "amount": "100" }, { "gl_code": "1234-56-102-056", "transaction_type": "activity_registration", "activity_id": "65", "payment_type": "EFT", "description": "Cuppa", "amount": "100" }, { "gl_code": "1234-56-102-056", "transaction_type": "activity_registration", "activity_id": "65", "payment_type": "SnapScan", "description": "Cuppa", "amount": "100" }, { "gl_code": "1234-56-102-020", "transaction_type": "activity_registration", "activity_id": "67", "payment_type": "EFT", "description": "Golf", "amount": "1500" }, { "gl_code": "3400-56-102-056", "transaction_type": "merchandise", "activity_id": "65", "payment_type": "Cash", "description": "Cap", "amount": "20" }, { "gl_code": "3400-56-102-056", "transaction_type": "merchandise", "activity_id": "65", "payment_type": "SnapScan", "description": "Water Bottle", "amount": "10" } ] The desired result. `"RECORDS": [ { "gl_code": "1234-13-102-064", "transaction_type": "activity_registration", "activity_id": "70", "payment_type": "EFT", "description": "Nutrition & Lifestyle", "amount": "510" }, { "gl_code": "1234-13-102-064", "transaction_type": "activity_registration", "activity_id": "70", "payment_type": "SnapScan", "description": "Nutrition & Lifestyle", "amount": "510" }, { "gl_code": "1234-56-102-056", "transaction_type": "activity_registration", "activity_id": "65", "payment_type": "Cash", "description": "Cuppa", "amount": "120" }, { "gl_code": "1234-56-102-056", "transaction_type": "activity_registration", "activity_id": "65", "payment_type": "EFT", "description": "Cuppa", "amount": "100" }, { "gl_code": "1234-56-102-056", "transaction_type": "activity_registration", "activity_id": "65", "payment_type": "SnapScan", "description": "Cuppa", "amount": "110" }, { "gl_code": "1234-56-102-020", "transaction_type": "activity_registration", "activity_id": "67", "payment_type": "EFT", "description": "Golf", "amount": "1500" } ]' The difference is very subtle. But you will see that I basically want to sum the records who's "payment_type" and last 3 digits of the "gl_code" are the same. For example "payment_type": "Cash" and "gl_code": "1234-56-102-056", Any help will be immensely appreciated.
If you want to group by payment_type and last 3 digits of gl_code (and apparently some other columns), you can do SELECT substring(gl_code, length(gl_code) - 3), transaction_type, activity_id, payment_type, description, SUM(amount) AS amount FROM tb_transaction WHERE event_id = 45 AND paid = false GROUP BY substring(gl_code, length(gl_code) - 3), transaction_type, activity_id, payment_type, description ORDER BY gl_code; Note however that this will only select the last 3 digits, and not an (arbitrary) gl_code from all those that share the same last 3 digits.
Add slider to line chart fusion chart
I am using Fusion Chart library for building line chart. I want a slider at the bottom of the chart so values can change when slider is moved back and forth. How can we achieve this in fusion charts ?
Are you looking for a solution like this ? http://jsfiddle.net/subramaniashiva/anrsydf7/ I have used the getJSONData and setJSONData of FusionCharts and updated the line chart based on the value from slider. FusionCharts.ready(function() { var chartConfig = { "caption": "Total footfall in Bakersfield Central - Admin View", "subCaption": "Year 2014", "xAxisName": "Month", "yAxisName": "No. of Visitors", //Cosmetics "lineThickness": "2", "paletteColors": "#0075c2", "baseFontColor": "#333333", "baseFont": "Helvetica Neue,Arial", "captionFontSize": "14", "subcaptionFontSize": "14", "subcaptionFontBold": "0", "showBorder": "0", "bgColor": "#ffffff", "showShadow": "0", "canvasBgColor": "#ffffff", "canvasBorderAlpha": "0", "divlineAlpha": "100", "divlineColor": "#999999", "divlineThickness": "1", "divLineIsDashed": "1", "divLineDashLen": "1", "divLineGapLen": "1", "showXAxisLine": "1", "xAxisLineThickness": "1", "xAxisLineColor": "#999999", "showAlternateHGridColor": "0", "yAxisMinValue": "0", "yAxisMaxValue": "100", "animation": "0" }, chartData = [{ "label": "Jan", "value": "42" }, { "label": "Feb", "value": "81" }, { "label": "Mar", "value": "36" }], revenueChart = new FusionCharts({ type: 'line', renderAt: 'chart-container', width: '550', height: '350', dataFormat: 'json', dataSource: { "chart": chartConfig, "data": chartData } }); revenueChart.render(); document.getElementById('slider').oninput = function() { var currentData = revenueChart.getJSONData(), selectedMonth = document.getElementById("monthSelector").selectedIndex; currentData.data[selectedMonth].value = this.value.toString(); revenueChart.setJSONData(currentData); }; });
Docusign List Population with Rest Endpoint (Modify Existing Recipient Tabs)
We are trying to populate an existing empty list on a DocuSign Template with some contact methods. The list needs to be populated on the fly since the number and default selected contact method varies with each recipient. Here is our JSON request we PUT to https://demo.docusign.net/restapi/v2/accounts/:accountId/envelopes/:envelopeId/recipients/:recipientId/tabs (we have confirmed at the necessary variables in the URL have been filled in). { "accountId":"163051", "checkboxTabs":[], "companyTabs":[], "dateTabs":[], "emailTabs":[], "envelopeId":"048f9ee2-df6e-482d-9e04-abb5e630bf83", "fullNameTabs":[], "initialHereTabs":[], "listTabs":[{ "documentId":"1", "locked":"False", "name":"Preferred Contact Method", "pageNumber":"1", "tabId":"661499f2-4dda-419d-82ad-f943871407e9", "tabLabel":"Preferred Contact Method", "value":"Any", "listItems":[{ "selected":"True", "text":"Any", "value":"1"},{ "selected":"False", "text":"E-mail", "value":"2"},{ "selected":"False", "text":"Phone", "value":"3"},{ "selected":"False", "text":"Fax", "value":"4"},{ "selected":"False", "text":"Mail", "value":"5"},{ "selected":"False", "text":"Home Phone", "value":"6"},{ "selected":"False", "text":"Mobile Phone", "value":"7"},{ "selected":"False", "text":"Text", "value":"8"},{ "selected":"False", "text":"Facebook", "value":"9"}] }], "noteTabs":[], "radioGroupTabs":[], "recipientId":"1", "signHereTabs":[], "textTabs":[], "titleTabs":[], "zipTabs":[] } And the response we are getting back: The remote server returned an error: (500) Internal Server Error. { "errorCode": "INVALID_TAB_OPERATION", "message": "The Tab specified is not valid for the requested operation. Attempt to create 'text' tab from invalid tab type. } There are no text tabs in our request. There is a tab with ID 661499f2-4dda-419d-82ad-f943871407e9 of type List on the template. We were able to get this working a few months ago but fear a new version may have broken this functionality. In case it is needed here is the "Get Recipient Tabs" response for the same envelope we are trying to modify. The list tab in question is at the bottom. { "signHereTabs": [ { "name": "Sign Here", "tabLabel": "Signature 12", "scaleValue": 1, "optional": "false", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "106", "yPosition": "270", "tabId": "00de6704-729d-4726-b102-829f914fda56" } ], "dateSignedTabs": [ { "name": "Date Signed", "value": "", "tabLabel": "Date Signed", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "385", "yPosition": "303", "tabId": "6236a6cc-2d13-452e-af9b-6fe9706ff500" } ], "textTabs": [ { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Last Name", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "36", "yPosition": "146", "tabId": "5aaee6db-a26a-4102-b77e-2eb4fb6e0c5b" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "First Name", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "224", "yPosition": "147", "tabId": "999d3f04-99b5-4fae-b69f-bd3e6b27e30d" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "false", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "maxLength": 1, "tabLabel": "Middle Initial", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "368", "yPosition": "145", "tabId": "fdb77bb3-bbe0-4a0c-bf66-ac9fbaa4bb26" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "false", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Maiden Name", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "427", "yPosition": "145", "tabId": "ae99f579-0016-4839-b179-444fae166f71" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Address Street", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "36", "yPosition": "175", "tabId": "506abe87-b144-4d93-8576-b33a2abc4d85" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "false", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Apt", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "367", "yPosition": "173", "tabId": "7eaa32ef-b9b3-40e5-a5d3-5975134fb90d" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "DOB", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "429", "yPosition": "175", "tabId": "8f895bec-4f7a-4040-be77-f17374b30765" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Address City", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "36", "yPosition": "202", "tabId": "af6cbd27-072f-494d-8cb0-f60578b5e6c9" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Address State", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "212", "yPosition": "202", "tabId": "1ecc4a85-5252-4f4f-97d8-22238f46aae5" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Address Zip", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "368", "yPosition": "202", "tabId": "0dfb3731-7ce4-4c10-81f2-784428427ee7" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "false", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Data Field 17", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "446", "yPosition": "256", "tabId": "cb9a86c5-6ecf-4593-8c54-4b7e7d08ffb8" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "false", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Data Field 18", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "497", "yPosition": "270", "tabId": "0fc2dc21-7916-431f-aa38-a3b4df6c7bcf" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "", "width": 42, "required": "false", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Data Field 19", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "498", "yPosition": "283", "tabId": "e0f8676f-6f98-43ee-81db-63734bfe3155" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "I am willing to travel.", "width": 162, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Data Field 49", "documentId": "1", "recipientId": "1", "pageNumber": "5", "xPosition": "55", "yPosition": "15", "tabId": "5c3ddd45-c36c-4214-8b80-d800e0fa5b61" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "I am NOT willing to travel.", "width": 162, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Data Field 50", "documentId": "1", "recipientId": "1", "pageNumber": "5", "xPosition": "56", "yPosition": "41", "tabId": "47d7d2ff-2a4f-4de7-9f67-311cd0b172c8" }, { "height": 11, "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "Text", "value": "Preferred Contact Method", "width": 138, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "Data Field 52", "documentId": "1", "recipientId": "1", "pageNumber": "1", "xPosition": "81", "yPosition": "21", "tabId": "75b83aa1-c906-4827-9fc2-6cc4177843c6" } ], "ssnTabs": [ { "validationPattern": "", "validationMessage": "", "shared": "false", "requireInitialOnSharedChange": "false", "name": "SSNTOOLTIP", "value": "", "width": 48, "required": "true", "locked": "false", "concealValueOnDocument": "false", "disableAutoSize": "false", "tabLabel": "SSN", "documentId": "1", "recipientId": "1", "pageNumber": "4", "xPosition": "429", "yPosition": "204", "tabId": "11b62284-7613-48df-8498-fa019f3a42a3" } ], "radioGroupTabs": [ { "documentId": "1", "recipientId": "1", "groupName": "Radio Button 13", "radios": [ { "pageNumber": "4", "xPosition": "297", "yPosition": "229", "value": "Radio", "selected": "false", "tabId": "2b2312d2-3ed6-469e-8aeb-8de588ae16d3" }, { "pageNumber": "4", "xPosition": "297", "yPosition": "243", "value": "Radio", "selected": "false", "tabId": "1a997301-f5d8-4e86-8ead-9d706490faf2" }, { "pageNumber": "4", "xPosition": "297", "yPosition": "256", "value": "Radio", "selected": "false", "tabId": "705df9df-9e1d-478b-b991-9b31e919c85c" }, { "pageNumber": "4", "xPosition": "297", "yPosition": "271", "value": "Radio", "selected": "false", "tabId": "d74742c2-742e-43d5-b1c5-04854ec8a7c5" } ] }, { "groupName": "Radio Button Group Test", "radios": [ { "pageNumber": "5", "xPosition": "28", "yPosition": "15", "value": "TravelYes", "selected": "false", "tabId": "30962105-0337-4d98-b4dd-058ae736d6fb" }, { "pageNumber": "5", "xPosition": "27", "yPosition": "40", "value": "TravelNo", "selected": "false", "tabId": "351ba656-80dd-43ea-936a-fd322d63c0c0" } ] } ], "listTabs": [ { "listItems": [ { "text": "", "value": "", "selected": "true" }, { "text": "", "value": "", "selected": "true" } ], "value": "", "width": 77, "shared": "false", "requireInitialOnSharedChange": "false", "tabLabel": "Preferred Contact Method", "documentId": "1", "recipientId": "1", "pageNumber": "1", "xPosition": "220", "yPosition": "20", "tabId": "661499f2-4dda-419d-82ad-f943871407e9" } ] }
This is a confirmed bug with DocuSign. I'm hoping this will get fixed in the next release but can't confirm yet. Once fixed I will update this answer to include the elements of a proper api call to modify an existing listTab, which I believe you're currently doing.