InferInstanceFor Debug Screen Final

Back to Basics : InferInstanceFor

It’s one of those functions that people often ask questions about. At first glance InferInstanceFor appears to be “just another one of those Instance functions”. But it actually hides something very interesting. The ability to create copies, to a certain degree.

So copies of instances, huh? Why would I want to do that? Well there are many reasons. But before we look at reasons, let’s look at how it works. Starting with a simple data model – consider the credit card as an entity. And the visa card as well. Let’s say that (logically enough) the visa card will be hosting instances of the credit card that are Visa cards.

So if we wanted to actually infer the existence of these Visa cards (as opposed to inferring membership of a relationship) then InferInstanceFor is going to come in very handy.

What we need, in order to be able to do this, is to establish an inferred associative relationship. We need to connect the credit and Visa cards with a relationship, so that we can use that in our upcoming rules.

InferInstanceFor 1

Suppose we enter into the Debugger 3 credit cards. Note that the Visa card is an inferred entity – you are about to add the rules to infer them. Here is the rule to begin the Word document:

InferInstanceFor Rule

And so, let’s tidy up the Interview and make a nice Screen layout with the two entities on the Screen – the credit card as a New Input and the Visa card as a new Control > Entity Container. I’ve added some labelling and put it into Tabbed layout for clarity:

InerInstanceFor Screen Layout

So now let’s run the Debugger and see the result, with 3 cards entered:

InferInstanceFor Debug 1

Hmm, that’s seriously underwhelming – what’s with the unknown?! The reason is, InferInstanceFor simply creates the “copy” instance. It does not in any way clone the attribute values. So right now you have a Visa card, but there is no information at all in the instance.

That’s why, whenever you see an InferInstanceFor, you are highly likely to see another rule right after it, making sure that some of the data is actually populated. A useful function in this context would be For(), since it is designed for cross-entity reasoning – which you are now doing since you have two entities. A sample rule might look like this:

InferInstanceFor Rule For

Note that this rule assumes that your credit card entity has an attribute called the credit card number. I renamed the attribute the credit card to the credit card number in my project. And of course, the separator “,” might be different in your region.

After a bit more tidying up it looks like this. Nice!

Debug Screen Final

Job done. So InferInstanceFor is useful for creating mirror copies of instances, but you will need to leverage other functions and rules to actually populate the instances you create.

If anyone wants the Zip File, just leave a comment!