Jim Coyne
Kilo Patron

It may not happen very often, but now and then you can get yourself into trouble if you are not careful with the Catalog Client Scripts form.

If you want to reuse code that you have created for a catalog item or a variable set, just go into the Catalog Client Scripts form and change the "Catalog item" or "Variable set" field and choose Insert or Insert and Stay to create a copy of the script. Pretty simple, everyone does it. However, there is a problem when you change the "Applies to" field - there is a UI Policy that displays either the "Catalog item" or "Variable set" field based on the "Applies to" selection, but the previously display field is not cleared and no message is displayed to tell you there may be a problem.

For instance, let's say you have a script setup on the "common_comments" variable set that you want to use on a new catalog item you have just created. You find the script, open the form and select "A Catalog Item" in the "Applies to" choice list and then fill in the catalog item you want it to run on and select Insert and Stay. You make a couple changes to the script, test it with the new catalog item and you are done. Works like a charm so you move it to production. All of a sudden you start getting emails and phone calls to say that there are a bunch of catalog items that are acting weird. You did not touch any of them so how can that be? Well, turns out that the modified script for that new catalog item is actually running on catalog items that have the "common_comments" variable set as well because the "Variable set" field was not cleared when you copied the script.

To resolve the problem, I have created a "Before Insert/Update" Business Rule on the Catalog Client Scripts (catalog_script_client) table that will abort the saving of a record that has both fields populated:



u_verifyCatalogScript();
function u_verifyCatalogScript() {
gs.addErrorMessage('Both Catalog item (' + current.cat_item.name + ') and Variable set (' + current.variable_set.name + ') fields are populated, but only 1 should be.</br></br>Please populate only one of the two.');
current.setAbortAction(true);
}


The trick is the condition on the BR:

!current.cat_item.nil() &amp;&amp; !current.variable_set.nil()


I've also created a filter on the Catalog Client Scripts list to display any current problem scripts that you might have:

find_real_file.png

Attached are two XML exports (just remove the ".txt" extension). One has the Business Rule, and the other is the filter for the Catalog Client Scripts table.

4 Comments