cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to identify matching values to create sequence numbers?

acesario
Contributor II

Looking for a function to help add sequence numbers to a json array. End goal is to apply a sequence to matching values, starting with 01, subsequent values get a sequence of 02โ€ฆ03โ€ฆ 04 etc. I could do this in a mapper, or in apache velocity as part of a soap execute if possible to loop through, and apply therein.

What I have now:
[
{
โ€œRecordsโ€: [
{
โ€œAwardโ€: [
โ€œAward_Aโ€,
โ€œAward_Cโ€,
โ€œAward_Aโ€,
โ€œAward_Bโ€,
โ€œAward_Cโ€
]
}
]
}
]

Desired output:
[
{
โ€œRecordsโ€: [
{
โ€œAwardโ€: [
โ€œAward_Aโ€,
โ€œAward_Cโ€,
โ€œAward_Aโ€,
โ€œAward_Bโ€,
โ€œAward_Cโ€
],
โ€œSequenceโ€: [
โ€œ01โ€,
โ€œ01โ€,
โ€œ02โ€,
โ€œ01โ€,
โ€œ02โ€
]
}
]
}
]

1 ACCEPTED SOLUTION

j_angelevski
Contributor III

@acesario , you can also just add [0] after @viktor_nโ€™s expression.

$Records.map(record => record.Award.map((x, index) => record.Award.slice(0, index + 1).filter(y => y == x).length))[0]

And if you really need the โ€œ0โ€ you can try and add .map(val => "0" + val)

So full expression is: $Records.map(record => record.Award.map((x, index) => record.Award.slice(0, index + 1).filter(y => y == x).length).map(val => "0" + val))[0]

View solution in original post

15 REPLIES 15

My recommendation is to learn as much as you can of them, but I think most of the times are used Arrays, Strings, Objects, Dates.

The Expression Language is loosely based off of JavaScript expressions, so you could use JavaScript resources to try and learn some of them better. The official documentation for the language is here and we try to give some examples, although maybe they could be flushed out more. There is also a section of this community dedicated to learning it, but there isnโ€™t a whole lot of content yet.

Hereโ€™s another great resource related to learning the Expression Language, where @koryknick goes over his starter pack in a video tutorial.

j_angelevski
Contributor III

@acesario , I am not sure I understood what you mean by that ? Maybe you want something like this ? image

acesario
Contributor II

No, more like :

โ€œRecordsโ€: [
{
โ€œAwardโ€: [โ€œAward_Aโ€,โ€œAward_Bโ€,โ€œAward_Cโ€,โ€œAward_A,โ€œAward_Bโ€,โ€œAward_Cโ€],
โ€œSequenceโ€: [โ€œ01โ€,โ€œ01โ€,โ€œ01โ€,โ€œ02โ€,โ€œ02โ€,โ€œ02โ€]

โ€œAwardโ€: [โ€œAward_Aโ€,โ€œAward_Cโ€,โ€œAward_Aโ€,โ€œAward_Bโ€,โ€œAward_Cโ€],
โ€œSequenceโ€: [โ€œ01โ€,โ€œ01โ€,โ€œ02โ€,โ€œ01โ€,โ€œ02โ€]

โ€œAwardโ€: [โ€œAward_Zโ€,โ€œAward_Cโ€,โ€œAward_Aโ€],
โ€œSequenceโ€: [โ€œ01โ€,โ€œ01โ€,โ€œ02โ€]

โ€œAwardโ€: [โ€œAward_Bโ€,โ€œAward_Cโ€,โ€œAward_Bโ€],
โ€œSequenceโ€: [โ€œ01โ€,โ€œ01โ€,โ€œ02โ€]

โ€œAwardโ€: [โ€œAward_Aโ€,โ€œAward_Bโ€,],
โ€œSequenceโ€: [โ€œ01โ€,โ€œ01โ€]
โ€ฆ