How to sort in alphabetic order
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 04:08 AM
In my catalog item i have 5 fields, User 1, User 2, User 3, User 4 and User 5.
I need these values in my Workflow, sort them in A to Z format. How to achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 04:44 AM
may be we can try that sumanth but i am wondering what could be wrong in that script as i tried with simple example
var arr=["M","D"];
var sorted = arr.sort();
and output is D,M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 04:46 AM
var arr =[];
var fd1 = current.variables.FND_RecLastName.toString();
var fd2 = current.variables.last_name_2.toString();
var fd3 = current.variables.last_name_3.toString();
var fd4 = current.variables.last_name_4.toString();
var fd5 = current.variables.last_name_5.toString();
arr.push(fd1);
arr.push(fd2);
arr.push(fd3);
arr.push(fd4);
arr.push(fd5);
var sortedArr = arr.sort();
gs.log("sortedArr"+sortedArr);
Can you please try this script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 07:06 AM
This worked!!
How to access each array object so that i can write code based of ech value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 07:10 AM
Hello,
you can write like below
var sortedArr = arr.sort();
var firstElement = sortedArr[0];
var secondElement = sortedArr[1];
var thirdElement = sortedArr[2];
var fourthElement = sortedArr[3];
var fifthElement = sortedArr[4];
OR
for(var i=0;i<sortedArr.length;i++)
{
var elements = sortedArr[i];
}
Please mark the answer correct if it helped you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 08:33 AM
Hello,
Did my answer help you ?
Please mark it correct if it helps you