Hi Everyone,
I am working on service action which Create or update a multiple records at one's.the list structure name is "Country".attributes are
1)city Name
2)city code
3)State Name
and there are some more attributes. where City code is unique the server action is working fine but at initial i need to raise expectations when there is a duplicate code in the list.
I have already achieved my requirements with loop and list filter but i am looking for better solution because loop increases the time of service action.
If there are better solutions form outsystems or any forge component please let me know.
thank you.
If you share your data model we can perhaps assist you better. For now I would think that either the ListIndex or an filter in an aggregate would solve you issue.
Are you aware that there are a lot of components in the Forge that already contain information about Country, State, City and more?
Examples of these are ;
Hope this helps,
Vincent
Hi vincent
Country is just a example.
I am getting list records to action by input parameter . Inside a action i need to check any one attribute in the list weather are there any duplicate values. There is no aggregate, complete list data is in variable (Input parameter) for better understanding i just give the country as a example.
Thank you for your time.
Hi Nani ,Are you aware about ListDistinct, this action remove the duplicate records.Thanks
It work for complete record in list. i need to check only one attribute in the list where i can specify which attribute i need to check.
Then you can use either ListFilter (check if the returned list is Empty for match) or ListIndex (check for value (-1 is not found) for match).
If you have a more complex record, list a List in a List then you have no other choice then to loop through at least one list to find all matching records.
Thank you,
I have already implemented that logic list in a list and its working too. i am Looking for better solution because when inserting a bulk records its increase the time.
How many records are you matching? This should be done in milliseconds for a normal sized list since you do this all in memory and do not have any database interaction.
At present i am testing with 10 records where service action have 5 loops for checking i am using 3 loops for insertion i am using 2 loops.
Can you share your data model? I really wonder what you are working with. You can use ObjGen (Json generator) for this. It's real easy to use :) https://objgen.com/json/local/design
A mockup with fake name is ok. It's just about the structure.
Sure, Vincent
structure name is "CountryData" and input variable data type is "CountryData List"
[
{
"country": {
"Code": "",
"Name": "",
"DisplayName": "",
"Description": ""
},
"state": [
}
]
If you want to check for properties in the State list then you have no other option then to iterate over the main list. Make sure to use RegEx for text matching as this is by far the fastest way to do this.
You could (or better, should) make a complex regex by first building a list of unique names that can't be used separating them with the pipe symbol ("|"). So lets say you have the following list of unique names; StateA, StateB and StateC. You can now check each name in one pass via regex by creating the following regex statement "StateA|StateB|StateC" (or "State(A|B|C)").
If you create the regex statement via the StringBuilder then you again will save a lot of CPU time to create the string.
Hi @nani ,
I understand you are using multiple loops inside a loop to achieve the logic.
But try this method if its feasible. And lets us know if it works.
Step 1 : Create a local variable of text list.Step 2 : Use Append all Action to append the country code alone to the variable.
Step 3: Apply List Distinct.
Step 4: Compare the count of the original local variable and List Distinct Count. The non-equality denotes that there were duplicates.
Thank you, Jerome
I Already know this solution, what if there are more then 2 list attributes in the variable.
Hi nani,
Is attribute fixed?
I mean if list has 4 attribute but we need to check duplicate against one attribute only
This is what you are looking?
Regards,
Arun
Yes, Attribute are Fixed and data is present all attributes but one attribute values should be checked.
I have already implemented a logic for that, it's completely working fine but i was trying to refractor the code.
Have look on forge component "Check Duplicate Values Inside List" created by me to find duplicate values inside list . For more details and documentation check below link.
https://www.outsystems.com/forge/component-overview/16841/check-duplicate-values-inside-list
I would be happy to hear feedback from you so in future I can improve this asset according to user need.
Thanks,
Thank you, arun for your time.
I have checked your Forge component it working but the code which you have developed will work on client side, i need to run it on server side.