VUGen with SAPGUI protocol - vugen

This is first time I have used SAPGUI protocol with VUGen. I have recorded a script in VUGen using SAPGUI protocol. The process I have recorded is VA01 "creating sales order". While replaying the script I am getting below errors directly without opening sap logon:
Error: line 2 contains 8 columns instead of 6 Error: Table
'C:\Users\Administrator\Documents\VuGen\Scripts\VA01\data_1.dat'
cannot be opened. Error code is '-4'. Warning: Extension parameng.dll
reports error -4 on call to function ExtPerProcessInitialize Error:
Thread Context: Call to service of the driver failed, reason - thread
context wasn't initialized on this thread.

I have tried myself recording the "VA01 - Create Sales Order" process and was able to replay it successfully.
I am using SAP 7.40 and VuGen 12.55.
Could you post the script you've recorded?
Also, you can view the script I've recorded here: https://pastebin.com/DkFD8W5J
Action()
{
sapgui_open_connection_ex(connection_string1,
"",
"con[0]");
sapgui_select_active_connection("con[0]");
sapgui_select_active_session("ses[0]");
sapgui_select_active_window("wnd[0]");
sapgui_window_resize("149",
"25",
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui104",
END_OPTIONAL);
/*Before running script, enter password in place of asterisks in logon function*/
lr_think_time(4);
sapgui_logon("NWBCUSER",
"mercury",
"800",
"EN",
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1012",
END_OPTIONAL);
sapgui_tree_set_selected_node("VA01 - Create Sales Order",
shell1,
"F00003",
BEGIN_OPTIONAL,
"AdditionalNodeInfo=Favorites;VA01 - Create Sales Order",
"AdditionalInfo=sapgui1013",
END_OPTIONAL);
sapgui_tree_double_click_node("VA01 - Create Sales Order",
shell1,
"F00003",
BEGIN_OPTIONAL,
"AdditionalNodeInfo=Favorites;VA01 - Create Sales Order",
"AdditionalInfo=sapgui1014",
END_OPTIONAL);
lr_think_time(4);
sapgui_set_text("VBAK-AUART",
"12",
ctxtVBAK1,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1017",
END_OPTIONAL);
sapgui_set_text("Sales Organization",
"ss",
ctxtVBAK2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1018",
END_OPTIONAL);
sapgui_set_focus(ctxtVBAK2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1019",
END_OPTIONAL);
sapgui_send_vkey(F4,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1021",
END_OPTIONAL);
sapgui_select_active_window("wnd[1]");
sapgui_window_scroll_to_row("0",
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1025",
END_OPTIONAL);
sapgui_set_focus(lbl1,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1024",
END_OPTIONAL);
sapgui_send_vkey(F2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1028",
END_OPTIONAL);
sapgui_select_active_window("wnd[0]");
sapgui_set_focus(ctxtVBAK3,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1031",
END_OPTIONAL);
sapgui_send_vkey(F4,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1033",
END_OPTIONAL);
sapgui_select_active_window("wnd[1]");
sapgui_window_scroll_to_row("0",
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1037",
END_OPTIONAL);
sapgui_set_focus(lbl2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1036",
END_OPTIONAL);
sapgui_send_vkey(F2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1040",
END_OPTIONAL);
sapgui_select_active_window("wnd[0]");
sapgui_set_focus(ctxtVBAK4,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1043",
END_OPTIONAL);
sapgui_send_vkey(F4,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1045",
END_OPTIONAL);
sapgui_select_active_window("wnd[1]");
sapgui_window_scroll_to_row("0",
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1049",
END_OPTIONAL);
sapgui_set_focus(lbl3,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1048",
END_OPTIONAL);
sapgui_send_vkey(F2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1052",
END_OPTIONAL);
sapgui_select_active_window("wnd[0]");
sapgui_set_focus(ctxtVBAK5,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1055",
END_OPTIONAL);
sapgui_send_vkey(F4,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1057",
END_OPTIONAL);
sapgui_select_active_window("wnd[1]");
sapgui_press_button("Continue (Enter)",
btn1,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1060",
END_OPTIONAL);
sapgui_press_button("Continue (Enter)",
btn1,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1063",
END_OPTIONAL);
sapgui_set_focus(ctxtG_SELFLD_TAB1,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1066",
END_OPTIONAL);
sapgui_send_vkey(F2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1068",
END_OPTIONAL);
sapgui_select_active_window("wnd[2]");
sapgui_window_close(
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1071",
END_OPTIONAL);
sapgui_select_active_window("wnd[1]");
sapgui_set_focus(txtG_SELFLD_TAB1,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1074",
END_OPTIONAL);
sapgui_send_vkey(F2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1076",
END_OPTIONAL);
sapgui_select_active_window("wnd[2]");
sapgui_grid_select_cell("'Sales Office' (2, Description)",
shell2,
"2",
"TEXT",
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1079",
END_OPTIONAL);
sapgui_grid_select_rows("'Sales Office', 2",
shell2,
"2",
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1080",
END_OPTIONAL);
sapgui_grid_double_click_current_cell("'Sales Office' (2, Description)",
shell2,
BEGIN_OPTIONAL,
"CurrentRow=2",
"CurrentCell=TEXT",
"AdditionalInfo=sapgui1081",
END_OPTIONAL);
sapgui_select_active_window("wnd[1]");
sapgui_set_focus(txtG_SELFLD_TAB1,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1084",
END_OPTIONAL);
sapgui_press_button("Cancel (F12)",
btn2,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1086",
END_OPTIONAL);
sapgui_select_active_window("wnd[0]");
sapgui_send_vkey(F4,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1089",
END_OPTIONAL);
sapgui_select_active_window("wnd[1]");
sapgui_window_close(
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1092",
END_OPTIONAL);
sapgui_select_active_window("wnd[0]");
sapgui_status_bar_get_text("paramStatusBarText",
BEGIN_OPTIONAL,
"Recorded status bar text: Choose a valid function",
"AdditionalInfo=sapgui1097",
END_OPTIONAL);
lr_think_time(6);
sapgui_set_text("Sales Office",
"1",
ctxtVBAK5,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1098",
END_OPTIONAL);
sapgui_set_text("Sales Group",
"2",
ctxtVBAK6,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui1099",
END_OPTIONAL);
sapgui_set_focus(ctxtVBAK6,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui10100",
END_OPTIONAL);
sapgui_press_button("Back (F3)",
btn3,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui10102",
END_OPTIONAL);
sapgui_press_button("Log off (Shift+F3)",
btn4,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui10105",
END_OPTIONAL);
sapgui_select_active_window("wnd[1]");
sapgui_press_button("Yes",
btnSPOP1,
BEGIN_OPTIONAL,
"AdditionalInfo=sapgui10108",
END_OPTIONAL);
return 0;
}

Related

how to use sortBy in 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 }))

Not Showing nested Json Data from Custom Api in FlatList in ReactNative

i tried several times to fetch data, but it is not showing anything in the app,
here is the code base for the fetching Api data.
it is console logging.
the data is console logging in the metro
but while trying to render in the flat List it is not showing anything,instead a blank page is displayed.
the data is a nested objects.
import React, {useEffect, useState} from 'react';
import {FlatList, SafeAreaView, Text, View} from 'react-native';
export default FoodProductsApi = () => {
const [data, setData] = useState([]);
const getFoodApi = () => {
fetch(
'url',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
countryName: 'India',
deliveryPincode: '5600100',
categoryType: 'Food',
}),
},
)
.then(response => response.json())
.then(json => {
setData(json.foodProducts);
console.log(json.foodProducts.categories);
})
.catch(error => {
console.error(error);
});
};
useEffect(() => {
getFoodApi();
}, []);
const keyExtractor = () => item => item.id;
return (
<SafeAreaView>
<Text>Name</Text>
<FlatList
data={data.foodProducts}
keyExtractor={keyExtractor}
renderItem={index => (
<View style={{flex: 1}}>
{index.data.foodProducts.map((i, v) => {
<Text>{i.categoryName}</Text>;
})}
</View>
)}
/>
</SafeAreaView>
);
};
this is the json Data
{
"responseCode": "200",
"responseMessage": "Successfull",
"foodProducts": {
"hubId": "610299e303be56ca3924971e",
"categories": [
{
"id": "61028aff294f460012c9101e",
"categoryName": "Kalyani Biryani",
"rankOrder": 6,
"status": "ACTIVE",
"createDate": "2021-07-29T11:03:27.345+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:17:55.270+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019627",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6f03be56ca3924b8f9",
"zohoItemId": "594850000000022886",
"productName": "Kalyani Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B035",
"mrp": 500,
"discountedPrice": 400,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.059+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.059+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "58.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b900",
"zohoItemId": "594850000000022946",
"productName": "Kalyani Egg Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B037",
"mrp": 300,
"discountedPrice": 290,
"rankOrder": 6,
"description": null,
"hsnCode": "5006097",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.348+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.348+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "56.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b907",
"zohoItemId": "594850000000022915",
"productName": "Kalyani Mutton Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B036",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.652+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.652+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Mutton",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "52.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b910",
"zohoItemId": "594850000000022977",
"productName": "Kalyani Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Veg",
"sku": "B038",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 12,
"description": null,
"hsnCode": "5006978",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.938+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.938+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "1",
"categoryType": "Food",
"availableStock": "51.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7603be56ca3924b992",
"zohoItemId": "594850000000022762",
"productName": "Thalassery Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B031",
"mrp": 400,
"discountedPrice": 320,
"rankOrder": 17,
"description": null,
"hsnCode": "5006990",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:18.173+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:18.173+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "128.000000",
"isFavorite": null,
"hubId": null
}
]
},
{
"id": "61028aa8294f460012c9101b",
"categoryName": "Bombay Biryani",
"rankOrder": 23,
"status": "ACTIVE",
"createDate": "2021-07-29T11:02:00.541+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:18:27.081+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019605",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6803be56ca3924b846",
"zohoItemId": "594850000000022576",
"productName": "Bombay Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Veg",
"sku": "B024",
"mrp": 400,
"discountedPrice": 360,
"rankOrder": 10,
"description": null,
"hsnCode": "50090994",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:03.459+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:03.459+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "130.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6703be56ca3924b832",
"zohoItemId": "594850000000022607",
"productName": "Bomaby Fish Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B025",
"mrp": 250,
"discountedPrice": 170,
"rankOrder": 11,
"description": null,
"hsnCode": "50090995",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.305+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.305+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Sea Food",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "145.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6803be56ca3924b83d",
"zohoItemId": "594850000000022638",
"productName": "Bombay Egg Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B026",
"mrp": 240,
"discountedPrice": 210,
"rankOrder": 16,
"description": null,
"hsnCode": "5009099",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.885+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.885+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "-141.000000",
"isFavorite": null,
"hubId": null
}
]
},
Hope this Solves your Problem,
import React from 'react';
import {
SafeAreaView,
StyleSheet,
View,
Text,
FlatList
} from 'react-native';
const App = () => {
const [data, setData] = useState([]);
useEffect(() => {
getFoodApi();
}, []);
function getFoodApi()
{
setData({
"foodProducts": {
"hubId": "610299e303be56ca3924971e",
"categories": [
{
"id": "61028aff294f460012c9101e",
"categoryName": "Kalyani Biryani",
"rankOrder": 6,
"status": "ACTIVE",
"createDate": "2021-07-29T11:03:27.345+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:17:55.270+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019627",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6f03be56ca3924b8f9",
"zohoItemId": "594850000000022886",
"productName": "Kalyani Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B035",
"mrp": 500,
"discountedPrice": 400,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.059+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.059+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "58.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b900",
"zohoItemId": "594850000000022946",
"productName": "Kalyani Egg Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B037",
"mrp": 300,
"discountedPrice": 290,
"rankOrder": 6,
"description": null,
"hsnCode": "5006097",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.348+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.348+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "56.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b907",
"zohoItemId": "594850000000022915",
"productName": "Kalyani Mutton Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B036",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.652+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.652+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Mutton",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "52.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b910",
"zohoItemId": "594850000000022977",
"productName": "Kalyani Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Veg",
"sku": "B038",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 12,
"description": null,
"hsnCode": "5006978",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.938+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.938+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "1",
"categoryType": "Food",
"availableStock": "51.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7603be56ca3924b992",
"zohoItemId": "594850000000022762",
"productName": "Thalassery Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B031",
"mrp": 400,
"discountedPrice": 320,
"rankOrder": 17,
"description": null,
"hsnCode": "5006990",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:18.173+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:18.173+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "128.000000",
"isFavorite": null,
"hubId": null
}
]//food products[0]
}, //categories[0]
{
"id": "61028aa8294f460012c9101b",
"categoryName": "Bombay Biryani",
"rankOrder": 23,
"status": "ACTIVE",
"createDate": "2021-07-29T11:02:00.541+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:18:27.081+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019605",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6803be56ca3924b846",
"zohoItemId": "594850000000022576",
"productName": "Bombay Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Veg",
"sku": "B024",
"mrp": 400,
"discountedPrice": 360,
"rankOrder": 10,
"description": null,
"hsnCode": "50090994",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:03.459+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:03.459+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "130.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6703be56ca3924b832",
"zohoItemId": "594850000000022607",
"productName": "Bomaby Fish Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B025",
"mrp": 250,
"discountedPrice": 170,
"rankOrder": 11,
"description": null,
"hsnCode": "50090995",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.305+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.305+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Sea Food",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "145.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6803be56ca3924b83d",
"zohoItemId": "594850000000022638",
"productName": "Bombay Egg Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B026",
"mrp": 240,
"discountedPrice": 210,
"rankOrder": 16,
"description": null,
"hsnCode": "5009099",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.885+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.885+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "-141.000000",
"isFavorite": null,
"hubId": null
}
]
}
]//categories
}//foodApi
})
}
return (
<SafeAreaView style={{flex:1}}>
<Text>Name</Text>
<FlatList
style={{flex:1}}
data={data.foodProducts.categories}
keyExtractor={(item,index)=>index.toString()}
renderItem={({ item, index }) => {
return (
<View style={{flex: 1}}>
<Text> categoreyname {item.categoryName}</Text>
{item.foodProducts.map(ele => {
return (
<Text style={{ paddingLeft: 5 }}> productName { ele.productName}</Text>
)
})}
</View>
)
}}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
});
export default App;
Flatlist will loop only array of object . in your code you have tried to loop objects (data.foodProducts).
Replace data={data.foodProducts} to data={data.foodproducts.categories}. Now it will loop, because its an array of objects.
Array of objects will be similar to this [{name:"React",age:5}]. This will be looped by flatlist
Objects will be similar to this {name:"react",age:5}. This will not looped by flatlist.
You can check whether data is an array or object using console.log(typeof data.foodproducts).

Example of using operator for filter in dataweave 2

I am using dataweave 2 for transformation. I need to use filter operator to filter payload depending upon the value in the request body. The reason for using 'using' is because the value is optional and in that scenario I do not want to filter the payload. My transformation -
%dw 2.0
output application/json skipNullOn="everywhere"
fun toDate(v) = (v as String{format:'yyyy-MM-dd'} as Date) default null
---
if (payload is Array)
flatten (
payload **//need to put 2 filters here on $.CloudAccountDetail.status and $.CloudAccountDetail.clouAccountId //** map (item, order) -> (
flatten ( [
item.NamedSubscriptions map {
key: $.SubscriptionId,
expiryDate: toDate($.ExpiryDate)
//nextPaymentDate: toDate($.NextPaymentDueDate)
}
,
item.UnnamedSubscriptions map {
key: $.SubscriptionId,
expiryDate: toDate($.ExpiryDate),
cloudPublicName: item.CloudAccountDetail.CloudAccountPublicName,
cloudAccountId: $.EskoCloudAccount
}
] )
)
)
else []
Input -
[
{
"CloudAccountDetail": {
"CompanyCode": "B_B001",
"CloudAccountId": "a-t-1000-5001-0687-0024",
"CloudAccountPublicName": "dodp-testcloud",
"Status": "SUBSCRIBED",
"ClusterName": "ci.dev.cloudi.city"
},
"NamedSubscriptions": [
{
"SubscriptionId": "8f724cc9-bb21-43bc-8911-94d267eb7917",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:19.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": "eskododp03#yahoo.be",
"AssignedBy": "LicenseService",
"AssignedDate": "2020-01-07T11:16:52.723",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "5c06112a-90a4-4e76-b2f4-bd19a1ce92b3",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:19.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "a258a7fc-cff6-4b53-b19d-4e25a8dbcee6",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:19.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "e30f16af-de60-4b84-bdae-aa7b6523c316",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:19.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "5ee9eeb6-9d65-42b8-b594-68c9528ff25b",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:20.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "818b38f1-0a10-45dc-ae16-f7d804b31cbc",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:20.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "cf5fc421-8ee0-4f1f-a1ca-e64daef2e0c6",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T12:13:20.507",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
}
],
"UnnamedSubscriptions": [
{
"SubscriptionId": "c56c5d21-83dd-4df5-851c-52fd5686240b",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:02.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "1d5bf54c-e812-4c17-830d-d3a1104d66a5",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:02.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "fbe0bbef-3cc2-451a-9866-0bb31a829850",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:02.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "368fa144-5a94-4ead-ba69-502ca6419de4",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:02.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "3404fb6e-d234-4dac-a5a1-96c7534ccf21",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:03.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "71d88ad6-3108-499e-8be9-3638c7298770",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:03.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "992b551e-1499-4971-bc9b-34075820faa7",
"OrderNumber": "TEST708259",
"StartDate": "2020-01-07T13:23:03.593",
"ExpiryDate": "2021-01-16T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
}
],
"StorageSubscriptions": [
{
"EntitlementId": "5ceae026-5c3e-40df-a9f8-2de4f4570566",
"OrderNumber": "TEST708259",
"StorageInGb": 50,
"ExpiryDate": "2021-01-07T00:00:00",
"StartDate": "2020-01-07T12:37:12.697",
"CanceledDate": null,
"ProductCode": "ECL-ECL-ST-ST50",
"ProductName": "Storage Tier 1 (50GB)",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
}
],
"TransactionSubscriptions": [
{
"EntitlementId": "6eaf4b93-8fef-4423-88fd-7e83d790f6f7",
"OrderNumber": "TEST708259",
"NumberOfTransactions": 12000,
"ExpiryDate": "2021-01-07T00:00:00",
"StartDate": "2020-01-07T12:17:56.257",
"CanceledDate": null,
"ProductCode": "ECL-ECL-BTR-BTR1000",
"ProductName": "Basic Transactions Tier 2 (1000/m)",
"EskoCloudAccount": "a-t-1000-5001-0687-0024",
"Status": "ACTIVE"
}
]
},
{
"CloudAccountDetail": {
"CompanyCode": "B_B001",
"CloudAccountId": "a-t-1001-0001-0039-0024",
"CloudAccountPublicName": "Test-Tom-Desmet",
"Status": "TRIAL",
"ClusterName": "ci.dev.cloudi.city"
},
"NamedSubscriptions": [
{
"SubscriptionId": "3dc289af-d469-4dba-875e-354c75d2a31a",
"OrderNumber": "TEST709894",
"StartDate": "2020-06-30T14:21:34.773",
"ExpiryDate": "2021-07-09T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": "eskododp03#yahoo.be",
"AssignedBy": "LicenseService",
"AssignedDate": "2020-06-30T13:31:01.777",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "3e6818fb-1c4f-4046-9783-5b76d3050eec",
"OrderNumber": "TEST709894",
"StartDate": "2020-06-30T14:21:35.773",
"ExpiryDate": "2021-07-09T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-PUSR",
"ProductName": "Esko Cloud Power User",
"Assignee": null,
"AssignedBy": null,
"AssignedDate": null,
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
}
],
"UnnamedSubscriptions": [
{
"SubscriptionId": "baf3d5c7-b53e-460e-93a5-311b95924fca",
"OrderNumber": "TEST709894",
"StartDate": "2020-06-30T15:18:15.593",
"ExpiryDate": "2021-07-09T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
},
{
"SubscriptionId": "69071fd1-59b5-44ef-a594-95141d68ef4c",
"OrderNumber": "TEST709894",
"StartDate": "2020-06-30T15:18:16.593",
"ExpiryDate": "2021-07-09T00:00:00",
"CanceledDate": null,
"ProductCode": "ECL-SA-SITE",
"ProductName": "Share & Approve Site",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
}
],
"StorageSubscriptions": [
{
"EntitlementId": "f6f444e3-4dea-43d9-afc0-19d24200cf46",
"OrderNumber": "TEST709894",
"StorageInGb": 50,
"ExpiryDate": "2021-06-30T00:00:00",
"StartDate": "2020-06-30T14:57:54.05",
"CanceledDate": null,
"ProductCode": "ECL-ECL-ST-ST50",
"ProductName": "Storage Tier 1 (50GB)",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
}
],
"TransactionSubscriptions": [
{
"EntitlementId": "22d25390-4183-4c89-8461-38ebf048812f",
"OrderNumber": "TEST709894",
"NumberOfTransactions": 12000,
"ExpiryDate": "2021-06-30T00:00:00",
"StartDate": "2020-06-30T14:24:10.017",
"CanceledDate": null,
"ProductCode": "ECL-ECL-BTR-BTR1000",
"ProductName": "Basic Transactions Tier 2 (1000/m)",
"EskoCloudAccount": "a-t-1001-0001-0039-0024",
"Status": "ACTIVE"
}
]
}
]
Output I need after transformation. Just take note I have not considered filtering in the ouput. -
[
{
"key": "8f724cc9-bb21-43bc-8911-94d267eb7917",
"expiryDate": "2021-01-16"
},
{
"key": "5c06112a-90a4-4e76-b2f4-bd19a1ce92b3",
"expiryDate": "2021-01-16"
},
{
"key": "a258a7fc-cff6-4b53-b19d-4e25a8dbcee6",
"expiryDate": "2021-01-16"
},
{
"key": "e30f16af-de60-4b84-bdae-aa7b6523c316",
"expiryDate": "2021-01-16"
},
{
"key": "5ee9eeb6-9d65-42b8-b594-68c9528ff25b",
"expiryDate": "2021-01-16"
},
{
"key": "818b38f1-0a10-45dc-ae16-f7d804b31cbc",
"expiryDate": "2021-01-16"
},
{
"key": "cf5fc421-8ee0-4f1f-a1ca-e64daef2e0c6",
"expiryDate": "2021-01-16"
},
{
"key": "c56c5d21-83dd-4df5-851c-52fd5686240b",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "1d5bf54c-e812-4c17-830d-d3a1104d66a5",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "fbe0bbef-3cc2-451a-9866-0bb31a829850",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "368fa144-5a94-4ead-ba69-502ca6419de4",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "3404fb6e-d234-4dac-a5a1-96c7534ccf21",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "71d88ad6-3108-499e-8be9-3638c7298770",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "992b551e-1499-4971-bc9b-34075820faa7",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "3dc289af-d469-4dba-875e-354c75d2a31a",
"expiryDate": "2021-07-09"
},
{
"key": "3e6818fb-1c4f-4046-9783-5b76d3050eec",
"expiryDate": "2021-07-09"
},
{
"key": "baf3d5c7-b53e-460e-93a5-311b95924fca",
"expiryDate": "2021-07-09",
"cloudPublicName": "Test-Tom-Desmet",
"cloudAccountId": "a-t-1001-0001-0039-0024"
},
{
"key": "69071fd1-59b5-44ef-a594-95141d68ef4c",
"expiryDate": "2021-07-09",
"cloudPublicName": "Test-Tom-Desmet",
"cloudAccountId": "a-t-1001-0001-0039-0024"
}
]
You should first apply the filter on the whole array, and then do the rest of the transformation:
%dw 2.0
output application/json skipNullOn="everywhere"
fun toDate(v) = (v as String{format:'yyyy-MM-dd'} as Date) default null
var status = 'SUBSCRIBED'
var accountId = 'a-t-1000-5001-0687-0024'
---
if (payload is Array)
flatten(payload filter ($.CloudAccountDetail.CloudAccountId == accountId and $.CloudAccountDetail.Status == status) map(item, value) ->
flatten ( [
item.NamedSubscriptions map {
key: $.SubscriptionId,
expiryDate: toDate($.ExpiryDate)
//nextPaymentDate: toDate($.NextPaymentDueDate)
}
,
item.UnnamedSubscriptions map {
key: $.SubscriptionId,
expiryDate: toDate($.ExpiryDate),
cloudPublicName: item.CloudAccountDetail.CloudAccountPublicName,
cloudAccountId: $.EskoCloudAccount
}
] ))
else []
The above dataweave expression applied to the provided input results in:
[
{
"key": "8f724cc9-bb21-43bc-8911-94d267eb7917",
"expiryDate": "2021-01-16"
},
{
"key": "5c06112a-90a4-4e76-b2f4-bd19a1ce92b3",
"expiryDate": "2021-01-16"
},
{
"key": "a258a7fc-cff6-4b53-b19d-4e25a8dbcee6",
"expiryDate": "2021-01-16"
},
{
"key": "e30f16af-de60-4b84-bdae-aa7b6523c316",
"expiryDate": "2021-01-16"
},
{
"key": "5ee9eeb6-9d65-42b8-b594-68c9528ff25b",
"expiryDate": "2021-01-16"
},
{
"key": "818b38f1-0a10-45dc-ae16-f7d804b31cbc",
"expiryDate": "2021-01-16"
},
{
"key": "cf5fc421-8ee0-4f1f-a1ca-e64daef2e0c6",
"expiryDate": "2021-01-16"
},
{
"key": "c56c5d21-83dd-4df5-851c-52fd5686240b",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "1d5bf54c-e812-4c17-830d-d3a1104d66a5",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "fbe0bbef-3cc2-451a-9866-0bb31a829850",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "368fa144-5a94-4ead-ba69-502ca6419de4",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "3404fb6e-d234-4dac-a5a1-96c7534ccf21",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "71d88ad6-3108-499e-8be9-3638c7298770",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
},
{
"key": "992b551e-1499-4971-bc9b-34075820faa7",
"expiryDate": "2021-01-16",
"cloudPublicName": "dodp-testcloud",
"cloudAccountId": "a-t-1000-5001-0687-0024"
}
]
Much cleaner example. Instead of using flatten, try using a function to populate the values.
Example:
%dw 2.0
var accountStatus=["SUBSCRIBED"]
var accountId=["a-t-1000-5001-0687-0024"]
fun getData(items, account, isUnnamedSubscriptions) =
(items default []) map {
"key": $.SubscriptionId,
"expiryDate": $.ExpiryDate as Date,
("cloudPublicName": account.CloudAccountPublicName) if (isUnnamedSubscriptions),
("cloudAccountId": account.CloudAccountId) if (isUnnamedSubscriptions)
}
output application/json
---
(payload[?((accountId contains $.CloudAccountDetail.CloudAccountId)
and (accountStatus contains $.CloudAccountDetail.Status) )] map (
getData($.NamedSubscriptions, $.CloudAccountDetail, false)
++
getData($.UnnamedSubscriptions, $.CloudAccountDetail, true)
) flatMap () -> $) default []
accountId variable is an Array and you can replace that as a string as well and similar to status in line 2 and line 3.
If you have multiple accountId to filter, just add another string in the accountId, same as the status.
If you want to exclude filter if the CloudAccountDetail.Status is Null and CloudAccountDetail.CloudAccountId is Null
You can create a function to return boolean. the funciton should be like this
fun isValidFilter(id, stat) =
if ( id !=null and stat != null)
((accountId contains id) and (accountStatus contains stat))
else (true)
and the pass the value to the function isValidFilter
Example:
payload[?( (isValidFilter($.CloudAccountDetail.CloudAccountId,
$.CloudAccountDetail.Status)) )] map ...

Is there a fast way of getting rid of the language labels in shopify liquid templates?

All the templates i've downloaded come like this on every .liquid file.. It lists out the language labels. How do i clean this up? It cant be necessary to have to look at these lists when developing? Is there a setting within my shopify admin dashboard that can remove these for me? Or do i have to remove myself or deal with?
% schema %}
{
"name": {
"da": "Overskrift",
"de": "Titel",
"en": "Header",
"es": "Encabezado",
"fi": "Ylätunniste",
"fr": "En-tête",
"hi": "हैडर",
"it": "Header",
"ja": "ヘッダー",
"ko": "머리글",
"ms": "Pengepala",
"nb": "Header",
"nl": "Koptekst",
"pt-BR": "Cabeçalho",
"pt-PT": "Cabeçalho",
"sv": "Rubrik",
"th": "ส่วนหัว",
"zh-CN": "标头",
"zh-TW": "標頭"
},
"settings": [
{
"type": "radio",
"id": "align_logo",
"label": {
"da": "Logojustering",
"de": "Logo-Ausrichtung",
"en": "Logo alignment",
"es": "Alineación de logotipo",
"fi": "Logon tasaus",
"fr": "Alignement du logo",
"hi": "लोगो संरेखण",
"it": "Allineamento logo",
"ja": "ロゴアラインメント",
"ko": "로고 정렬",
"ms": "Penjajaran logo",
"nb": "Logojustering",
"nl": "Logo-uitlijning",
"pt-BR": "Alinhamento do logotipo",
"pt-PT": "Alinhamento do logótipo",
"sv": "Logojustering",
"th": "การจัดวางโลโก้",
"zh-CN": "logo 对齐方式",
"zh-TW": "商標對齊"
},
"default": "left",
"options": [
{
"value": "left",
"label": {
"da": "Venstre",
"de": "Links",
"en": "Left",
"es": "Izquierda",
"fi": "Vasen",
"fr": "Gauche",
"hi": "बाएँ",
"it": "Sinistra",
"ja": "左",
"ko": "왼쪽",
"ms": "Kiri",
"nb": "Venstre",
"nl": "Links",
"pt-BR": "Esquerda",
"pt-PT": "Esquerda",
"sv": "Vänster",
"th": "ด้านซ้าย",
"zh-CN": "左侧",
"zh-TW": "左方"
}
},
{
"value": "center",
"label": {
"da": "Centreret",
"de": "Mittig",
"en": "Centered",
"es": "Centrada",
"fi": "Keskitetty",
"fr": "Centré",
"hi": "केंद्र",
"it": "Centrato",
"ja": "中央揃え",
"ko": "센터 맞추기",
"ms": "Ditengah",
"nb": "Sentrert",
"nl": "Gecentreerd",
"pt-BR": "Centralizado",
"pt-PT": "Centrado",
"sv": "Centrera",
"th": "ตรงกลาง",
"zh-CN": "居中",
"zh-TW": "置中"
}
}
]
},
....
}
]
}
{% endschema %}
This is used to display labels and texts in the user language in theme administration panel. This is common and a good practice for themes used by multiple users.
If you or your client doesn't need it, all you have to do is to clean your json.

How to get the spotify id of a specific song with echonest api

I am trying to query echonest with both an Artist name and Song name and have it return the spotify ID of the song. Currently I can only get the artist to be returned.
I am reading the documentation but it makes no sense at all I think it might be out dated and was wondering if someone could help me.
Here is the link to the doc I am using (http://developer.echonest.com/sandbox/spotify.html) the API example is the 2nd from the last which is:
http://developer.echonest.com/api/v4/song/search?api_key=FILDTEOIK2HBORODV&format=json&results=1&artist=radiohead&title=karma%20police&bucket=id:spotify&bucket=tracks&limit=true
Artists: Radiohead
Song title: Karma Police
What is returned as the example in the document is
songs: [
{
title: "Karma Police"
artist_name: "Radiohead"
id: "SOHJOLH12A6310DFE5"
tracks: [
{
"catalog": "spotify",
"foreign_id": "spotify:track:3L7BcXHCG8uT92viO6Tikl",
"id": "TRAVAWH13386461C1A"
}
]
}
]
And I am trying to get the spotify:track:NUMBER_HERE
But when I actually run the api in my browser I get something totally different.
I get
{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"}, "songs": [{"title": "Karma Police", "artist_name": "Radiohead", "artist_foreign_ids": [{"catalog": "spotify", "foreign_id": "spotify:artist:4Z8W4fKeB5YxbusRsdQVPb"}], "tracks": [{"album_type": "album", "album_date": "1997-07", "foreign_release_id": "spotify:album:4ofIyjnuLMspKVVEM5k7KA", "catalog": "spotify", "foreign_id": "spotify:track:0CheWtm72bDFyuqxxJm7Jl", "album_name": "Karma Police", "id": "TRMKRIH144D09912F7"}, {"album_type": "album", "album_date": "1997-07", "foreign_release_id": "spotify:album:3Y0KfwfHGnuuSqVQAxODb9", "catalog": "spotify", "foreign_id": "spotify:track:4MBMrG8UypQfADJTg3cfPl", "album_name": "Karma Police", "id": "TRTEKIH144D14B88AB"}, {"album_type": "unknown", "album_date": "1997-05-21", "foreign_release_id": "spotify:album:2fGCAYUMssLKiUAoNdxGLx", "catalog": "spotify", "foreign_id": "spotify:track:4toSP60xmDNCFuXly8ywNZ", "album_name": "OK Computer", "id": "TREZAIC144D16517CA"}, {"album_type": "other", "album_date": "1999-02-16", "foreign_release_id": "spotify:album:2xYrPRSUPI1Q33xbyFhEN2", "catalog": "spotify", "foreign_id": "spotify:track:5YtKNQRPr4WE4EW1q2KJ8y", "album_name": "Ka-Boom: 16 Rippin' Tunes!", "id": "TRJIACH144D1845ABD"}, {"album_type": "other", "album_date": "2006", "foreign_release_id": "spotify:album:2ravCeM1o3ZoDZkMbRA2Df", "catalog": "spotify", "foreign_id": "spotify:track:3L7BcXHCG8uT92viO6Tikl", "album_name": "Essential Bands", "id": "TRGUGNY144D11B4378"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:1ouYZxiEjRSlUdoldMJyNF", "catalog": "spotify", "foreign_id": "spotify:track:4NGagGvZxVZ1ox7NsOSMDU", "album_name": "The Best Of", "id": "TRITWZK144D147AB62"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:58ukFMtQgwjVD9vMlfnSi9", "catalog": "spotify", "foreign_id": "spotify:track:116R91XyWtWQUHw1VZD3pu", "album_name": "The Best Of", "id": "TRQZPLJ144D0B965CE"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:3hWomTJKGucGKv6EPpiHK9", "catalog": "spotify", "foreign_id": "spotify:track:36OTdTMwBC0SQvc0TMxqgf", "album_name": "The Best Of", "id": "TRMJVDN144D114268C"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:0YbEgKS7zN6HkDW8bATFn3", "catalog": "spotify", "foreign_id": "spotify:track:3FWvP216t2YLltarju8fIt", "album_name": "The Best Of", "id": "TRVHZKK144D1175CDB"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:30bTqpK0cUWDD4VxHVjv0f", "catalog": "spotify", "foreign_id": "spotify:track:57GM3IdxqmCX15rGBw7C0Q", "album_name": "The Best Of", "id": "TRUBASC144D1704E37"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:4ZbRrwQyYPoYLg689BLOdG", "catalog": "spotify", "foreign_id": "spotify:track:7afVhhphp8iwwb5c6zDD4M", "album_name": "The Best Of", "id": "TRHDXVW144D1D82BF6"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:40i2i4LZN75liVKAjbMKP5", "catalog": "spotify", "foreign_id": "spotify:track:4rl2PAW1pb9uvn5BrjCUPd", "album_name": "The Best Of", "id": "TRCOWWN144D1635B08"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:1WsOWlFxZ3u7bW2GigFhoS", "catalog": "spotify", "foreign_id": "spotify:track:0REhU4YzXin94yj5VIhfXR", "album_name": "The Best Of", "id": "TRVGGHY144D0A2A56F"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:4wciNwfgbL74SJG9BFlf2R", "catalog": "spotify", "foreign_id": "spotify:track:0hCW6LbmFCYwM1uGmnjjNe", "album_name": "The Best Of", "id": "TRFHBAP144D0AC7509"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:5lEQ9RF9W2jBIKT369b6XA", "catalog": "spotify", "foreign_id": "spotify:track:0w13hCzWc9x2ODo0lhW3AT", "album_name": "The Best Of", "id": "TRIJWLD144D0B70EB1"}, {"album_type": "other", "album_date": "2008-06-02", "foreign_release_id": "spotify:album:0kiElBKf2UH2AL51cSnjFs", "catalog": "spotify", "foreign_id": "spotify:track:7jglhg35UU1rHKo3TMMlhs", "album_name": "The Best Of", "id": "TRDAANY144D1DDC1B0"}, {"album_type": "other", "album_date": "2009-11-16", "foreign_release_id": "spotify:album:2ARSMRIAl1RrPIYODKpSvn", "catalog": "spotify", "foreign_id": "spotify:track:7IGdoYPZjwkFZObVrnhQwB", "album_name": "101 Indie Classics", "id": "TRATJQY144D1D34F86"}, {"album_type": "other", "foreign_release_id": "spotify:album:4VaGdGXKBYsDSOZpZb33YH", "catalog": "spotify", "foreign_id": "spotify:track:4TDPAhRJvIIxC2iOj3tfnJ", "album_name": "Personal Effects", "id": "TRODNEI144D15055F1"}, {"album_type": "other", "foreign_release_id": "spotify:album:3JVhCJ0KrRNNyqAbDtuUlR", "catalog": "spotify", "foreign_id": "spotify:track:7bm4xECd4E5BagR8tzshXR", "album_name": "L'album pop rock 1980-1999, Volume 2", "id": "TRIAUMZ144D1CE6B92"}, {"foreign_release_id": "spotify:album:37bbqRNY7TYPMVchZAkant", "catalog": "spotify", "foreign_id": "spotify:track:1H9Fdn0ufWXoaOZhaA3XhW", "id": "TRUOSTZ144D0C565DA"}, {"foreign_release_id": "spotify:album:2QlyISc2f7wPcwdggl8k6x", "catalog": "spotify", "foreign_id": "spotify:track:1Y6Nw0Xfh2hCBpu27F0Xce", "id": "TRLULHG144D0D0E0A8"}, {"foreign_release_id": "spotify:album:7vHLtDbWD2N2PUdWorYvL6", "catalog": "spotify", "foreign_id": "spotify:track:31VtM8plvEaBKEkwmJ5iVx", "id": "TRSAUZY144D110B9F0"}, {"foreign_release_id": "spotify:album:5VHphzoQ5AmAUv1NTXTgeA", "catalog": "spotify", "foreign_id": "spotify:track:4722k1npcMc5e1kBiWWIYI", "id": "TRBVBET144D1423032"}, {"foreign_release_id": "spotify:album:2bKod32TblM1nReRDi9gTG", "catalog": "spotify", "foreign_id": "spotify:track:6MRtrRQVOwyk6cMZY3Smnl", "id": "TRSEEQW144D1A7817C"}, {"foreign_release_id": "spotify:album:1ssRgLbh4dOEpu57bImChh", "catalog": "spotify", "foreign_id": "spotify:track:01puceOqImrzSfKDAcd1Ia", "id": "TRBHSFP144D0923CC6"}, {"foreign_release_id": "spotify:album:1EAJOr9xA3rHzhS5rWpziG", "catalog": "spotify", "foreign_id": "spotify:track:2Mvy2Ob0m1MIaOwjieDSdD", "id": "TRWBMXG144D0F402E2"}, {"foreign_release_id": "spotify:album:5bNn3KPcrlgLmhRXj4d2EX", "catalog": "spotify", "foreign_id": "spotify:track:4BFAWLRycYNSbhUgZFijc9", "id": "TRSXGVY144D1438433"}, {"foreign_release_id": "spotify:album:4195NRmc5jxkCw9jcmd4rt", "catalog": "spotify", "foreign_id": "spotify:track:5MIblG9hLxBnQcrDwdWF98", "id": "TRBLQPB144D17B11CC"}, {"foreign_release_id": "spotify:album:6vjzhxwIgTtDVW34bteGyG", "catalog": "spotify", "foreign_id": "spotify:track:10u0TOqp3bd1DAPNskHvK8", "id": "TRPIDKB144D0BA6CBC"}, {"foreign_release_id": "spotify:album:6uhBsv0PbcwolrbhgCDqDR", "catalog": "spotify", "foreign_id": "spotify:track:6XPGNyB95TZwYiqe2t964T", "id": "TRGUQDL144D1B040D8"}, {"foreign_release_id": "spotify:album:45wvzRUVtoEPsXsiNtO2TX", "catalog": "spotify", "foreign_id": "spotify:track:3u7TUfV1fjAvxJtqvtUbGO", "id": "TRNPOOC147B6E30B68"}, {"foreign_release_id": "spotify:album:3Hl5wRTlE9vNuXdZ54okbn", "catalog": "spotify", "foreign_id": "spotify:track:1vDio38orbAGqrXAR13RD3", "id": "TRHKSFX144D0E0D5DC"}, {"foreign_release_id": "spotify:album:3fjD2coxF2SQwLRcjm0ctg", "catalog": "spotify", "foreign_id": "spotify:track:6IJW8YFpoJ5DQ0YiBITqfq", "id": "TRTHCOU144D1A55B13"}, {"foreign_release_id": "spotify:album:4VYcoe0QDAGJmZA5zpgvgq", "catalog": "spotify", "foreign_id": "spotify:track:6oeIc0gfmKLlYe5gkJ3cJP", "id": "TRDVZZZ144D1B59768"}, {"foreign_release_id": "spotify:album:7eQtS9KqZmqCGkbieox4fV", "catalog": "spotify", "foreign_id": "spotify:track:6ZGOmPtSvx1hxwjwqpdKQ7", "id": "TRIBYGA144D1A9AF3B"}, {"foreign_release_id": "spotify:album:6Bjl48Ev6V97G6Uc37IRTw", "catalog": "spotify", "foreign_id": "spotify:track:6eomr7dBfWTGdRHuPwJFU6", "id": "TROCBGU14735BF0753"}, {"foreign_release_id": "spotify:album:1AAI2vNGAwA7DhCmEyYAwU", "catalog": "spotify", "foreign_id": "spotify:track:2NBB9erm0zzcM6i41Nrbux", "id": "TRDMBVL144D0F3D96F"}], "artist_id": "ARH6W4X1187B99274F", "id": "SOHJOLH12A6310DFE5"}]}}
Can someone point me in the right direction as to what I am overlooking please.
Any help guidance and suggestions is appreciated. My end state is that I can get the spotify track id so I can build my own playlist programmaticly. If there is a better way I am open to suggestions
Looking at the response you've got from The Echo Nest's API, the track URI is located in
response.songs[0].tracks[0].foreign_id. So the documentation is correct, it's just that it didn't cover the response object that the songs array lives inside.
Hope this helps!