Skip to main content

I have 2 SQL Tables where there is a common field between the two "COMPUTERNAME"

 

Table1)

  ID

  ComputerName

  SerialNo

  Brand

  Memory

  HDD

  etc...

 

Table2)

  ID

  ComputerName

  User

  Location

  Department

  etc....

 

I wonder if there is a way to pull both Smart Objects and run a loop trough both the idea will be to make sure all the ComputerNames from Table 1) Have a match in Table 2.  If after run trough all the items in Table2 there is nothing then return some action to take on that particular ComputerName. 

 

A similar Process can run later from Table2 over Table 1 and depending of the results if there is some inconsistencies then create a record in a third table for required changes.

 

I attempt to do this with Designer, the problem is that the For/Each method is placed in a block and aparently there is no way to have nested blocks within the Rules

 

13914i288CDCCBB4A45E05.jpg

 

I'm not sure if this would require perhaps K2Studio... or even to perform this expensive nested loop within a SQL View directly from the Database, perhaps a join between the two tables and create an SMO from the View, then can be processed based on the fields return on each item and compare those values to see if they match or not and go from there executing only 1 Loop within the K2 View.

 

Anyhow if somebody have some ideas or suggestions please feel free to drop a line.

 

THX Dino.

 

Dear ,

 

There is one idea that might help ur solution ,

u could create nested loop as a workarround in k2 ,

Create unbounded Event and call it "table2 loop" , and add condition for all items in table 2 -> execute "anything"

after that , on ur same first screen shot , when ur button is clicked , for all items in table 1 =>execute "anything" and to trigger the nested loop u go to actions and search for "another" , u will find a rule named "execute another rule" and u will find the unbounded rule u added before "the loop that goes through table 2",

In this way u will have table 1 loop and table 2 loop nested inside of it ,

 

Hope it helps!

Regards.


Thank you Ahmad U Rock that did the trick !!!

 

12760i464638BD2616A247.jpg

 

It worked perfect as expected !!!.

 

THX Again Dino.


Just to make sure leave the post with the correct solution here we go.

 

Fact:

So we have 2 SMO's. Each SMO have a list of computers. The idea is to match Table1 or SMO1 with Table2 or SMO2.

 

Requirement:

If some of the ComputerName listed on SMO1 does not exist in SMO2. need to be detected and inserted into SMO2. and some Message, Alert, conceivable workflow or something else could happen.

 

Challenges

With 2 SMO's is necesary to create a ForEach Loop trough the list. K2 is able to achieve this via Unbound Rule and call it from the first ForEach Loop.

Is necesary to identify once the second nested loop finish if it was a match with the ComputerName from first item from SMO1. S Wee need a counter !!! ]

 

Using Params as Temp Variables

I decided to use parameters as variables durin runtime and assign values while they are running in the loop.

The end result, is after the second loop complete if there was a match an incremental +1 counter will have a value if the counter is "0" then means there was no match on the SMO2 and something will be executed.

 

Here is how my Parameters look like:

15034i6ABD73ED8F51B855.jpg

 

The first Rule of Transfer Data basically initilize the myparam with the name of the ComputerName p This was just for testing really not required for this example ]

Later execute mysccmcount transfer with an Expression called mysscmAddOne, which basically is an expresion to increment the value of this parameter, since originally was setup default to "0" will turn into 1 at first and everytime the loop goes trough this, will increment and we will have the value of the loop cycle.

 

11459i7A002F6BAF1552E5.jpg

 

So basically the expression takes the same variable and increment on 1 and that is the execution on transfer data within the loop.

 

So once we start the main loop transfer data to myparams and continue starting the nested loop 2. if we look the rules for the second Loop:

 

11572iF6882F2C5A435FF1.jpg

 

Since we just really care if there is a missing field... the condition check for mycounter=0 that meand there was no match trough the nested loop. something needs to happen:

 

A popup message display what is missing

A create method to SMO2 is performed to normalize the data between the two tables

An email is trigered.

s NOTE: Potentially here you could start a workflow or something else ]

 

This concept work fine. I have not perform any stress testing, because what happen if I have 50,000 entries within SMO1. How long will it take to loop trough all of those.

I'm loading 2 views at once... could not find a way to execute the loop directly from the SMO. potentially could be an expensive process if there are to many records in the SMO1 and SMO2. not sure if this could be put in the background in case takes hours to run, this to avoid to much stress within the K2 Server or kind of put in the background with low priority to be resourceful.

 

But again for a few records should be fine. just wanted to update this post, because regarding my first question yes is possible to create a nested loop with K2 and find some matching records.

 

Have Fun Dino.


Reply