December 10, 201213 yr I need to create records from two lists of IDs. Every Line in $Types needs to create a record from first line in $Categories then another record for same $types and second line in Categories. After finishing first type, go to second and repeat. I can loop first list but get mixed up on how to loop second. I tried another loop but fail. Can someone give me script to create records from two lists like this?
December 10, 201213 yr I want to clear something up here: you have 2 lists - $Types and $Categories - lets say type1 type2 type3 and category1 category2 category3 And I didn't understand how you want your result to look like. Something like this? 1st record: "type1 category1" 2nd record: "type2 category2" 3rd record: "type3 category3"
December 10, 201213 yr Author I want Record 1 Type 1 Category 1 Record 2 Type 1 Category 2 Record 3 Type 1 Category 3 Record 4 Type 2 Category 1 Record 5 Type 2 Category 2 ... etc Thank you for considering my need.
December 10, 201213 yr You need to do a nested loop. For each outer loop record, process the inner loop record set then proceed to the next outer loop record or variable. Loop Do things with outer loop record Loop Do things with inner loop records End loop Go to next outer loop record, exit after last End loop
December 10, 201213 yr Author Hi Bruce, thank you for helping. I have that much figured out. But I cannot exit and it gets all mixed up. I know I need to use variables and count. I was hoping someone would help me a bit more on the counters for each of the loops and how that might work.
December 10, 201213 yr Solution Hi David, You might try this concept, assuming your multiline variables are named $types and $categories: Loop Exit Loop If [ Let ( $countTypes = $countTypes + 1 ; $countTypes > ValueCount ( $types ) ) ] Loop Exit Loop If [ Let ( $countCategories = $countCategories + 1 ; $countCategories > ValueCount ( $categories ))] New Record/Request Set Field [ table::Types; GetValue ( $types ; $countTypes ) ] Set Field [ table::Categories; GetValue ( $categories ; $countCategories ) ] End Loop Set Variable [ $countCategories; Value:"" ] End Loop
December 10, 201213 yr Author Hi LaRetta, That script was perfect. I was missing the idea of resetting the inner loop's count when I exited the inner loop. And my script was quite a bit longer. I'm going to keep this one handy since it is pretty basic and will help me many times over. Thank you very much.
December 10, 201213 yr Actually, it can be tweaked yet; my bad. I was testing for the value count of the lists within each loop. If instead you set a variable with number of lines of both types and categories before entering the loop and then just reference these variables where I have ValueCount ( $types) and ValueCount ( $categories) it will be more optimized. You probably wouldn't even notice the difference unless you were looping at least 10,000 lines but I couldn't NOT mention it.
March 24, 201312 yr assuming your multiline variables are named $types and $categories: Loop Exit Loop If [ Let ( $countTypes = $countTypes + 1 ; $countTypes > ValueCount ( $types ) ) ] Loop Exit Loop If [ Let ( $countCategories = $countCategories + 1 ; $countCategories > ValueCount ( $categories ))] New Record/Request Set Field [ table::Types; GetValue ( $types ; $countTypes ) ] Set Field [ table::Categories; GetValue ( $categories ; $countCategories ) ] End Loop Set Variable [ $countCategories; Value:"" ] End Loop I have hunted for example of looping two checkboxes and creating multiple 'and' from all the combinations and here it is. Thank you.
Create an account or sign in to comment