Hi all, I am setting this field value with the hel...
# suitescript
v
Hi all, I am setting this field value with the help of for loop and the '\n' to appear line by line. Now i want it to display in a correct order like 1,2,3... how can i do this? Could anyone please help me? Is there anything like ascending or descending function?
n
You would need to sort those date values as dates or numeric values ordered CCYYMMDD otherwise you'll run into alsorts of issues. If you have created the string from dates sort them first, then create your string.
If you have each of those values in an array, this should work to order it reliably before you join with '/n' (you can try this in the console):
const dateArray = ["01.03.2022 8h","04.03.2022 8h","03.03.2022 8h","02.03.2022 8h"];
dateArray.sort((a, b) => {
const dateA = new Date(a.split(' ')[0]);
const dateB = new Date(b.split(' ')[0]);
return dateA - dateB;
});
console.log(dateArray);
v
Thank you sir. I will try this.