cancel
Showing results for 
Search instead for 
Did you mean: 

Agentry development - validation rules

Former Member
0 Kudos

Hi experts,

I have a question for the validation rules in Transactions. I have the following hypothetical scenario:

1. I have an activity object, which has a collection of orders and the orders have a collection of products.

2. In the product fields, there is a specific field - e.g. notes that has to be filled by the user

3. I want to create a validation rule in transaction which changes the status of an activity (for example, from open to closed), which checks if all fields for notes (on product object level) are filled in or empty - if they are empty - to display a warning message.

The problem is that when I try to create such rule, I can access only the properties of the Activity object. Am I not doing something right or it is not possible to validate a field, which is a collection of the collection of the object change that needs to be validate?

Hope I explained it clearly

Regards,
Denis

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I think I found how add as property the collection of a collection for the current object. For example, in the Northwind sample project:

Am I on the right track?

jason_latko
Advisor
Advisor
0 Kudos

Denis,

Can you please clarify your object/collection structure?  Specifically, Current Object -> Orders -> Products -> Quantity.  If I understood your structure better, I could give you a better example on how to do this.  You can't use the Rule Properties section to accomplish your task.  Those are used to automatically put focus back to a certain field if the rule fails (I believe?).  We don't use that feature for our products.  You should be able to reference your target path the way you have tried in your screen shot directly in the rule iteself to get at other properties of the current object, using the object browser.  I would not use "Cureent Object" syntax though, instead right click on the current object line in the object browser and change the context to use the fully qualified object name.  This helps to make the rule more readable and to cut down on potential problems with Agentry getting confused.  Keep in mind that validation rules are evaluated as a Boolean, and must return True for the rule to pass.  If your rule logic returns False, then the rule's warning or error text will pop up.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason,

Thanks for the hint of selecting the property directly in the rule!

My object collection structure would be as follows:

- Activity (Orders property collection)

* Field "Status"

     - Order (Products property collection)

          - Product

          * Field "Notes"

So, when I want to change the status of the activity (e.g. from "open" to "closed"), I want to do a check if for all products in the orders for this activity, I have entries in the field "Notes". If for some products in some orders this field is empty,  I want to display a warning message.

Cheers

Denis

Former Member
0 Kudos

Is this close to I want to achieve? (don't mind the difference in the objects naming, as I'm experimenting with the Northwind, but the objects will be different in the real project)

p.s. I'm sure the property is not a good example, but it is just for illustration

Cheers

Denis

jason_latko
Advisor
Advisor
0 Kudos

Denis,

Yes something similar to that.  The problem is that you are hard-coding First and Last objects so this will not search though all Products in all Orders like you desire.  I am checking to see if it is even possible to write a single validation rule to handle this scenario where you want to search a collection that is two deep.  You could easily do this in a straight child collection, but I'm not sure about a grand-child collection two deep.  Off the top of my head, doing two deep would require a seperate sub-action loop outside of this transaction to loop over the Orders and check the Products collection of each order in the loop, then setting a flag that you would reference after the loop to see if you then need to pop a warning/error.  Not difficult, but more involved than a single validation rule.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason,

And how the property will look like with straight child collection Orders--Products and a specific field to be checked?

Regards,

Denis

jason_latko
Advisor
Advisor
0 Kudos

Denis,

That is an easy one:

EQNUM

     COUNT

          Order Object -> Products Collection

               EQSTR

                    Product Object -> Notes Property

                    Global.EmptyString

0

The above rule says: For the current Order object, the count of rows in the Products collection having a notes property = emptystring is zero.  This is a boolean statement that will return either True or False.  So if there are no empty notes, True will be returned and the rule will pass validation.  If one or more Notes = emptystring, then the rule returns False and the error/warning message will trigger.  The EmptyString global is just a blank (empty) string.  You could also use an empty constant.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Thanks for this, Jason!

So, you think that two-deep check of a collection is not possible?

Regards,
Denis

jason_latko
Advisor
Advisor
0 Kudos

Denis,

Speaking to a colleague, neither of us can think of a way to do that in a single validation rule.  Start with a new mainobject boolean variable to indicate an error condition.  Set this to False at the start.  Create a looping action over the child collection with an execute rule on the loop.  Create the execute rule to be similar to the one I gave you above, but wrap everything in a NOT, so it returns True if there are empty notes.  Then in the sub-action that will execute if the rule returns true, set the mainobject variable to true to indicate that you need to pop an error/warning later.  The loop will run and afterwards, check the state of the mainobject boolean to see if you need to pop an error/warning.  Do so in another sub-action.  You get the idea.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason,

I will try to summarize to see if I got the idea..

1. I'm creating an action "Close activity", which will have a transaction "Close activity" for the Activity object

2. I'm creating a boolean variable for activity object. Here, I'm not sure if you mean to create a property in the activity object or a boolean property in the transaction?

3. In the action "close activity", I'm creating a sub-action with execution type "loop over collection", collection "orders" and execution rule (the one you described) to loop over the child collection of products

4. Change the state of the variable to "true" if the sub-action returns "true" - is this done with the "Action" field in the sub-action?

5. Create another sub-action with execution type "Execute once if rule is true" and the execution rule should be a validation rule in the transaction that displays a warning pop-up?

I'm pretty sure it's not exactly what you mean but I hope that I'm getting close

Cheers

Denis

jason_latko
Advisor
Advisor
0 Kudos

Denis,

You are on the right track.  In CloseActivity action, run your transaction as normal and Apply to change the status.

Add a new Boolean WarningNeeded to the Activity or to Main Object.  Main Object probably easier to target later.

Create a Transaction that sets this to False.  Run and Apply the transaction in CloseActivity.

Add a sub-action to CloseActivity to do the looping.  You described it correctly in #3 above.

Change state of the variable to True if the execute rule returns true for any of the products using a Transaction you will add to the sub-action's target action.  Action could be called SetWarningNeeded, Transaction could be called same.  You don't need to do any special handling here.  The execution rule will handle it and run the sub-action automatically if needed for any of the Products.  It may run multiple times, but this is OK.

Add an Apply after the sub-action in CloseActivity, rather than in SetWarningNeeded.  This will make things quicker.  Applys are slow.  Do them as little as possible.  Transactions will queue up if not applied, and the single Apply will save them all.

For your #5, add another sub-action with an execute rule on it that checks your WarningNeeded variable.  It is sufficient to just put that property in the rule and that is all.  The rule will check the Boolean state and return either True or False.  In the new sub-action called DisplayWarning, add an action message step to pop your warning message.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Hi Jason,

A colleague of mine came up with the following suggestion for doing this check with a validation rule. He performed it on a transaction in the WM configuration, and he said that it worked fine for him:

What do you think?

Cheers

Denis

jason_latko
Advisor
Advisor
0 Kudos

Denis,

I had that new "All" syntax in mind but had never tried it that way as a validation rule.  When I ran it by my colleague here, he didn't think it would work the way you were hoping.  Looking at the rule you provided, it looks like it will do what you want.  Modify it to fit your objects and let us know.  Sorry I sent you down that other path.  This looks promising.

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

Thanks for the input, Jason!

This new "All" syntax should really do the job.

Cheers

Denis

jason_latko
Advisor
Advisor
0 Kudos

Denis,

Please let me know if that rule works for you.  If I could, I would give you some points here!

Jason Latko - Senior Product Developer at SAP

Former Member
0 Kudos

The credit should go to a colleague of mine We are still not there with the design of the app to check it for real but the test on WM went fine.

Regards,
Denis

Answers (0)