Conditionally limit records | Community
Skip to main content
Level 2
March 20, 2024
Question

Conditionally limit records

  • March 20, 2024
  • 2 replies
  • 1127 views

Hi,

 

I've got a split in my workflow and from this split I've got 5 subsets which are linked to the deliveries. Now i want to limit the records in the subsets with 20%, but only if the amount of records is higher than 100. Otherwise if there are only 5 records it will still take 20% from it and then no one will get an email. 

 

I tried doing this per subset with a test acitivity but that didn't work. So I'm starting to think that JavaScript is the only solution for this. Only my JavaScript skills are not adept enough to fix this. 

 

Is JavaScript the only way this will work or are there other ways to make this work? Please help me out :)!

 

Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Level 3
March 20, 2024

Hi @j2021 ,

You can use test activity before your split activity, and only pass it through if recCount is more than 100

In condition put vars.reccount >100

False condition, you can route to another flow. Hope this helps

 

Regards,

J2021Author
Level 2
March 20, 2024

Hey! @inmo

 

Thank you for your answer. Sadly it doesn't help me. Because into the split the records will always be greater than 100. I need the check to be on the subsets of the split. And if it is yes than it needs to take 20%.

 

Kind regards, 

Adobe Employee
August 19, 2024

Hello J2021, 

 

Is this the approach you have tried? If so, what issues did you encounter?

 

 

 

Best regards

 

J2021Author
Level 2
August 21, 2024

Yes this was the approach I tried. My problem with this approach was that the split sometimes lost the connection with the temporary table so it failed the workflow. Also I have 3 different deliveries per line. So the segmentation split was indeed 5 lines and then after the test for >100 yes or no there would have to be 3 deliveries on each line. And that would result in 30 deliveries. Which is why i chose in the end for using Javascript;

 


This is the JS code:

 

//Check if recCount > 20 if (vars.recCount > 20) { var query = xtk.queryDef.create( <queryDef schema={vars.targetSchema} operation="select" distinct="true"> <select> <node expr="@RecipientId"/> </select> </queryDef> ); var resultSet = query.ExecuteQuery(); // Convert resultSet to an array var results = []; for each (var row in resultSet) { results.push(row); } // Calculate the number of rows to return (20% of total rows) var twentyPercent = Math.ceil(results.length * 0.2); // Shuffle the array randomly results.sort(function() { return Math.random() - 0.5; }); // Select the first 20% of the shuffled array var selectedRows = results.slice(0, twentyPercent); var primaryKeys = []; for (var i = 0; i < selectedRows.length; i++) { primaryKeys.push("'" + selectedRows[i].@RecipientId + "'"); } vars.array = primaryKeys.join(","); logInfo( vars.array); } else { // If false, do nothing var query = xtk.queryDef.create( <queryDef schema={vars.targetSchema} operation="select" distinct="true"> <select> <node expr="@RecipientId"/> </select> </queryDef>); var results = query.ExecuteQuery(); primarykeys = [] for each (var row in results){ primarykeys.push("'+row.@RecipientId+'").toString(); } vars.array = primarykeys.join(","); logInfo("No extra action needed.:"+ vars.array); }