Tib Cim Rulebaseguide

192
TIBCO Collaborative Information Manager™ Rulebase Guide Software Release 8.1.0 January 2011

Transcript of Tib Cim Rulebaseguide

Page 1: Tib Cim Rulebaseguide

TIBCO Collaborative Information Manager™

Rulebase GuideSoftware Release 8.1.0January 2011

Page 2: Tib Cim Rulebaseguide

Important Information

SOME TIBCO SOFTWARE EMBEDS OR BUNDLES OTHER TIBCO SOFTWARE. USE OF SUCH EMBEDDED OR BUNDLED TIBCO SOFTWARE IS SOLELY TO ENABLE THE FUNCTIONALITY (OR PROVIDE LIMITED ADD-ON FUNCTIONALITY) OF THE LICENSED TIBCO SOFTWARE. THE EMBEDDED OR BUNDLED SOFTWARE IS NOT LICENSED TO BE USED OR ACCESSED BY ANY OTHER TIBCO SOFTWARE OR FOR ANY OTHER PURPOSE.USE OF TIBCO SOFTWARE AND THIS DOCUMENT IS SUBJECT TO THE TERMS AND CONDITIONS OF A LICENSE AGREEMENT FOUND IN EITHER A SEPARATELY EXECUTED SOFTWARE LICENSE AGREEMENT, OR, IF THERE IS NO SUCH SEPARATE AGREEMENT, THE CLICKWRAP END USER LICENSE AGREEMENT WHICH IS DISPLAYED DURING DOWNLOAD OR INSTALLATION OF THE SOFTWARE (AND WHICH IS DUPLICATED IN THE LICENSE FILE) OR IF THERE IS NO SUCH SOFTWARE LICENSE AGREEMENT OR CLICKWRAP END USER LICENSE AGREEMENT, THE LICENSE(S) LOCATED IN THE “LICENSE” FILE(S) OF THE SOFTWARE. USE OF THIS DOCUMENT IS SUBJECT TO THOSE TERMS AND CONDITIONS, AND YOUR USE HEREOF SHALL CONSTITUTE ACCEPTANCE OF AND AN AGREEMENT TO BE BOUND BY THE SAME.This document contains confidential information that is subject to U.S. and international copyright laws and treaties. No part of this document may be reproduced in any form without the written authorization of TIBCO Software Inc.TIBCO, The Power of Now, TIBCO BusinessConnect, TIBCO ActiveMatrix BusinessWorks, TIBCO Enterprise Message Service are either registered trademarks or trademarks of TIBCO Software Inc. in the United States and/or other countries.EJB, Java EE, J2EE, and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.All other product and company names and marks mentioned in this document are the property of their respective owners and are mentioned for identification purposes only.THIS SOFTWARE MAY BE AVAILABLE ON MULTIPLE OPERATING SYSTEMS. HOWEVER, NOT ALL OPERATING SYSTEM PLATFORMS FOR A SPECIFIC SOFTWARE VERSION ARE RELEASED AT THE SAME TIME. SEE THE README FILE FOR THE AVAILABILITY OF THIS SOFTWARE VERSION ON A SPECIFIC OPERATING SYSTEM PLATFORM.THIS DOCUMENT IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.THIS DOCUMENT COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW EDITIONS OF THIS DOCUMENT. TIBCO SOFTWARE INC. MAY MAKE IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED IN THIS DOCUMENT AT ANY TIME.THE CONTENTS OF THIS DOCUMENT MAY BE MODIFIED AND/OR QUALIFIED, DIRECTLY OR INDIRECTLY, BY OTHER DOCUMENTATION WHICH ACCOMPANIES THIS SOFTWARE, INCLUDING BUT NOT LIMITED TO ANY RELEASE NOTES AND "READ ME" FILES.This Product is covered by U.S. Patent No. 7,472,101.Copyright © 1999-2011 TIBCO Software Inc. ALL RIGHTS RESERVED.TIBCO Software Inc. Confidential Information

Page 3: Tib Cim Rulebaseguide

| iii

Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Changes from the Previous Release of this Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x

Related Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiTIBCO Collaborative Information Manager Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiOther TIBCO Product Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiii

How to Contact TIBCO Support. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiv

Chapter 1 Getting Started with Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Establishing an XML Rules File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3New Record File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Validation File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Search Control Rules File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Structure of a Rulebase File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Variable Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9declare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9var. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10datatype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18assign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25connect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28disconnect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30duplicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31enum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32propagate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34refresh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35select . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38slice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41softlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

TIBCO Collaborative Information Manager Rulebase Guide

Page 4: Tib Cim Rulebaseguide

iv | Contents

usefor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Access Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Global Property Settings for Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56LogFlag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Checking Attribute Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

Chapter 2 Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

SQL Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Locations of datasource and classifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Selecting Columns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64where . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Placeholders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65sql Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Debugging Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Context Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69SESSION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69WORKITEM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70PREVIOUS_VERSION, PREVIOUS_CONFIRMED_VERSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71CONTEXT_RELATIONSHIP/NAME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72RECORD_ACTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73RECORD_SUB_ACTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75RECORD_IS_TOPMOST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76RECORD_IS_BOTTOMMOST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76PARENT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77CHILD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

Chapter 3 Operator and Character Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Overview of Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Logical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Math. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Other . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83and — compute logical and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83not — compute logical not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85or — compute logical or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87changed — test an attribute to see if it has changed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87defined — determine if value is defined. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

TIBCO Collaborative Information Manager Rulebase Guide

Page 5: Tib Cim Rulebaseguide

Contents | v

eq — equals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88geq — greater than or equal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90gt — greater than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90in — check if argument contained in a list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90leq — less than or equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91lt — less than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91match — regular expression match . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91neq — not equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92undefined — determine if value is undefined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

String Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94concat — concatenate string values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94length — compute length of string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94pad — pads a string on left or right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95substring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96trim — trims leading and trailing spaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97uppercase — returns uppercase of input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

Math Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98div — divides values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98minus — calculates subtraction of values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99mult — multiplies values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100percent — computes percentage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101plus — calculates addition of values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102round — rounds to a defined set of decimal places . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

Other Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106checkdigit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106count — count number of (non-null, non-false) entries in array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107distinct — returns distinct values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107filter — filter a list of records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108lookup — lookup value in database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109max— maximum value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110min — minimum value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110nvl — substitute non-NULL value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111sequence — returns a database sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112strip — removes all null values from an array. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113synchstatus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113SyncOperationAttribute — used to find the operation date (GDSN Only) . . . . . . . . . . . . . . . . . . . . . . . . . . 114validate_checkdigit - validates checkdigit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

Syntax for Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116const . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116var. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Undefined (Null) Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118Literal Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

TIBCO Collaborative Information Manager Rulebase Guide

Page 6: Tib Cim Rulebaseguide

vi | Contents

Character Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119Position Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119Repetition Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120Alternation, Grouping, Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

Built-in Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

Custom Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Creating a Custom Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

Chapter 4 Rulebase Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

Non-Negative Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Dependent Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Dependent Drop-Down Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

Specify Data Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

Checking Child Records for Value. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

Chapter 5 Rulebase Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

Rulebase Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

Specify Mandatory Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

Access Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

Check for a Value (GTIN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

CATALOG_NAME Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

Specify Valid Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

Assign TRUE or FALSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

Check Values of Related Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

Check Values of Attributes Related to MINIMUM_SHIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

Check Code Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

Validate Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

Validate Temperature Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

Skip First Pass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

Specify Valid Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

Check for DIMENSIONUOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

Specify Types For a Drop-Down Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

Check Length of UPC Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

Validate Against First Order Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

Validate Against First Ship Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

Validate Net Weight. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

Calculate Volume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

TIBCO Collaborative Information Manager Rulebase Guide

Page 7: Tib Cim Rulebaseguide

Contents | vii

Specify New Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

Propagate Attribute Value to Children . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

Chapter 6 Embedding Rulebases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

Error Handling and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

Appendix A Synch_History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169

SYNCH_HISTORY. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

Appendix B System Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .175

System Implicit Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .177

TIBCO Collaborative Information Manager Rulebase Guide

Page 8: Tib Cim Rulebaseguide

viii | Contents

TIBCO Collaborative Information Manager Rulebase Guide

Page 9: Tib Cim Rulebaseguide

| ix

Preface

The TIBCO Collaborative Information Manager™ delivers functionality to administer processes for management and governance of master data.

This ensures accuracy and efficiency both inside the enterprise as well as throughout the value chain so that multiple processes are optimally coordinated. TIBCO Collaborative Information Manager delivers a horizontal platform to manage all types of information including products, customers, vendors, reference data, trading partners, and so on.

Topics

• Changes from the Previous Release of this Guide, page x

• Related Documentation, page xi

• Typographical Conventions, page xiii

• How to Contact TIBCO Support, page xiv

TIBCO Collaborative Information Manager Rulebase Guide

Page 10: Tib Cim Rulebaseguide

x | Changes from the Previous Release of this Guide

Changes from the Previous Release of this Guide

This release does not include any changes to this Guide.

TIBCO Collaborative Information Manager Rulebase Guide

Page 11: Tib Cim Rulebaseguide

Preface | xi

Related Documentation

This section lists documentation resources you may find useful.

TIBCO Collaborative Information Manager DocumentationThe following documents form the TIBCO Collaborative Information Manager documentation set:

• TIBCO Collaborative Information Manager Installation and Configuration Guide: Read this manual for instructions on site preparation, installation, and configuration.

• TIBCO Collaborative Information Manager User’s Guide: This manual explains features and benefits of TIBCO Collaborative Information Manager from the business user’s viewpoint. It describes the features and functionality as well as all the screens.

• TIBCO Collaborative Information Manager System Administrator’s Guide: This manual explains features relevant to the system administrator.

• TIBCO Collaborative Information Manager Customization Guide: Read this manual to understand how the application can be customized to your enterprise needs.

• TIBCO Collaborative Information Manager Catalog Rulebase Guide: This manual is a language guide and reference for rulebase. It describes the underlying structure and also provides rulebase examples for definition of rulebase.

• TIBCO Collaborative Information Manager Workflow Reference: This manual is a reference for automation of business processes.

• TIBCO Collaborative Information Manager Web Services Guide: This manual is a reference for using web services in the application.

• TIBCO Collaborative Information Manager Release Notes: Read the release notes for a list of new and changed features. This document also contains lists of known issues and closed issues for this release.

Other TIBCO Product DocumentationYou may find it useful to read the documentation for the following TIBCO products:

• TIBCO Collaborative Information Manager Process Designer User’s Guide: This guide is a reference for designing workflows using the TIBCO Collaborative Information Manager Process Designer graphical user interface.

TIBCO Collaborative Information Manager Rulebase Guide

Page 12: Tib Cim Rulebaseguide

xii | Related Documentation

• TIBCO Collaborative Information Manager Process Designer Tutorial: This guide is a tutorial for designing workflows using the TIBCO Collaborative Information Manager Process Designer graphical user interface.

• TIBCO Collaborative Information Manager Repository Designer User’s Guide: This guide is a reference for designing repositories using the TIBCO Collaborative Information Manager Repository Designer graphical user interface.

• TIBCO Collaborative Information Manager Repository Designer Tutorial: This guide is a tutorial for designing repositories using the TIBCO Collaborative Information Manager Repository Designer graphical user interface.

• TIBCO Enterprise Message Service™ software: This software allows the application to send and receive messages using the Java Message Service (JMS) protocol. It also integrates with TIBCO Rendezvous and TIBCO SmartSockets™ messaging products.

• TIBCO BusinessWorks software™: This is a scalable, extensible and easy to use integration platform that allows you to develop and test integration projects. It includes a graphical user interface (GUI) for defining business processes and an engine that executes the process.

• TIBCO BusinessConnect™ software: This software allows your company to send and receive XML or non-XML business documents over the Internet. Based on a mutually agreed process flow and common document format, you and your trading partners can conduct secure and verifiable business transactions online.

TIBCO Collaborative Information Manager Rulebase Guide

Page 13: Tib Cim Rulebaseguide

Preface | xiii

Typographical Conventions

The following typographical conventions are used in this manual.

Table 1 General Typographical Conventions

Convention Use

code font Code font identifies commands, code examples, filenames, pathnames, and output displayed in a command window. For example:

Use MyCommand to start the foo process.

bold code

font Bold code font is used in the following ways:

• In procedures, to indicate what a user types. For example: Type admin .

• In large code samples, to indicate the parts of the sample that are of particular interest.

• In command syntax, to indicate the default parameter for a command. For example, if no parameter is specified, MyCommand is enabled: MyCommand [enable | disable]

italic font Italic font is used in the following ways:

• To indicate a document title. For example: See TIBCO BusinessWorks Concepts.

• To introduce new terms For example: A portal page may contain several portlets. Portlets are mini-applications that run in a portal.

• To indicate a variable in a command or code syntax that you must replace. For example: MyCommand pathname

Key combinations

Key name separated by a plus sign indicate keys pressed simultaneously. For example: Ctrl+C.

Key names separated by a comma and space indicate keys pressed one after the other. For example: Esc, Ctrl+Q.

The note icon indicates information that is of special interest or importance, for example, an additional action required only in certain circumstances.

The tip icon indicates an idea that could be useful, for example, a way to apply the information provided in the current section to achieve a specific result.

The warning icon indicates the potential for a damaging situation, for example, data loss or corruption if certain steps are taken or not taken.

TIBCO Collaborative Information Manager Rulebase Guide

Page 14: Tib Cim Rulebaseguide

xiv | How to Contact TIBCO Support

How to Contact TIBCO Support

For comments or problems with this manual or the software it addresses, please contact TIBCO Support as follows.

• For an overview of TIBCO Support, and information about getting started with TIBCO Support, visit this site:

http://www.tibco.com/services/support

• If you already have a valid maintenance or support contract, visit this site:

https://support.tibco.com

Entry to this site requires a user name and password. If you do not have a user name, you can request one.

TIBCO Collaborative Information Manager Rulebase Guide

Page 15: Tib Cim Rulebaseguide

| 1

Chapter 1 Getting Started with Rules

This chapter provides in-depth information for getting started with the TIBCO Collaborative Information Manager Rulebase.

Topics

• Overview, page 2

• Establishing an XML Rules File, page 3

• Structure of a Rulebase File, page 5

• Header, page 7

• Variable Declarations, page 9

• Actions, page 18

• Global Property Settings for Rules, page 56

TIBCO Collaborative Information Manager Rulebase Guide

Page 16: Tib Cim Rulebaseguide

2 | Chapter 1 Getting Started with Rules

Overview

A repository consists of a list of records, each with its own set of attributes. Each attribute is defined as being of a particular type and having a certain length.

A repository rule allows you to specify more complex constraints on attributes. For example, a repository defines Price as a Number. Using a repository rule, you can specify that this number must be between 0 and 100. You can also specify that, if Price is not zero, another attribute (Currency) must have a specified value.

A repository rule is an encapsulated piece of business logic that specifies validations, transformations, and access controls for a record. Some examples are:

• The storage temperature must be between –20F and 80F.

• The product effective date must be before the product first ship date.

• The subclass code must be Chicken, Beef, or Vegetable when the product class code is Soup.

• Volume is calculated by multiplying height x depth x length.

• Only Supervisors can access records with Product Code equal to ‘HS’.

Repository rules are specified in XML files. Two files can be defined for a repository:

• New record file — called to initialize a new record

• Validation file — called for existing records

• Search control rules file — called from record search.

For detailed information on the XML files, refer to the section , Establishing an XML Rules File, page 3.

The XML file of a repository rule consists of a header, variable declarations, and a constraint. The header gives the name and description of the rule. The constraint contains a condition and an action. The condition describes when the rule needs to be applied. The action describes what the rule actually does and controls which attributes the rule is applicable to. For detailed information, refer to the section, Structure of a Rulebase File, page 5.

TIBCO Collaborative Information Manager Rulebase Guide

Page 17: Tib Cim Rulebaseguide

Establishing an XML Rules File | 3

Establishing an XML Rules File

Following rulebase files can be defined for a repository:

• New record file — called to initialize a new record

• Validation file — called for existing records

• Search control rules file — called from record search.

The new record file is called when adding a new record. Subsequently, the validation file is called when modifying the record. The names of these files are defined using the Configurator. The default names are as follows:

• InitialConfig > Rule Base > New Record Data Population Rulebase File Name = newrecord.xml

• InitialConfig > Rule Base > Record Save Validation File Name = catalogvalidation.xml

• InitialConfig > Rule Base > Record Search Rules File Name = searchcontrolrules.xml

When a repository is created, these files are created in folder $MQ_COMMON_DIR/<enterprise-internal-name>/catalog/master/<reposito

ry id> .

The <repository id> can be obtained from the Repository List page.

These validation files are also supported for a relationship catalog. This catalog is created when any relationship attribute is defined for the relationship. The initialization or validation for relationship attributes can be defined in these files. The ID of relationship catalog can be obtained from the database by executing the following SQL:

select relationshipcatalogid from relationshipdefinition where ownerid=<repository id> and name=<relationship name> and active='Y

Note: Upload or download of rulebase files through UI is not supported for relationship catalog.

For a list of supported actions for a relationship catalog, refer to the Relationship and Multi-value Attributes Vs Regular Attributes section of the TIBCO Collaborative Information Manager User’s Guide.

The system looks for these files in the following order:

Do not rename the default rulebase file, catalogvalidation.xml , generated by the system.

TIBCO Collaborative Information Manager Rulebase Guide

Page 18: Tib Cim Rulebaseguide

4 | Chapter 1 Getting Started with Rules

1. $MQ_COMMON_DIR/<enterprise-internal-name>/catalog/master/<repository id>

2. $MQ_COMMON_DIR/standard/rulebase

Refer to Chapter 1 of the TIBCO Installation and Configuration Guide for details on MQ_HOME and MQ_COMMON_DIR, under the environment variables section.

New Record FileA new record file is used to assign default values to the attributes of a new record. Assigned values must come from constants or function calls.

This file is also used for propagation of attribute values to child records.

Some rules from the Validation File also come into play for new records.

Validation FileThe validation file usually contains the bulk of the rules. All kinds of rules are applicable:

• assignments

• validations

• propagations

• access controls

Search Control Rules FileThe search control rules file is used to configure dropdown for attributes on the Record Search screen.

The second location is checked only when no file is specified in the first location.

Drop downs can be filled up only through a constraint in the catalogvalidation.xml file.

Upload or download of this rulebase file through UI is not supported.

TIBCO Collaborative Information Manager Rulebase Guide

Page 19: Tib Cim Rulebaseguide

Structure of a Rulebase File | 5

Structure of a Rulebase File

A rulebase file is composed of a header, variable declarations, and a constraint.

• Header: A rule begins with a header consisting of name, description, error_severity, and threshold. It controls which attributes the rule is applicable to. For more information on the header, refer to the section, Header, page 7.

• Variable declarations: A list of variable declarations follows the header section. Each declaration section can have the following parts:

— declare : starts a declaration.

— var : names the variable.

— datatype : contains the data type stored as a type attribute.

— link : defines a relationship by pointing to data.

For more information on the variable declarations, refer to the section, Variable Declarations, page 9.

• Constraint: A constraint consists of the following sections.

— condition section: the condition when the rule needs to be applied.

— action section: the action that the rule actually takes. For more information on the actions, refer to the section, Actions, page 18.

Rules are executed in the order in which they are defined in the rulebase.

Sample

Here is a sample rulebase that shows the syntax of a rulebase:

<?xml version="1.0" encoding="UTF-8"?><rulebase metaversion="0.1"><name>Sample Rulebase</name><description>Rulebase that defines all basic constructs</description><declare>

<var>CONTAINSREL</var><link type="relationship_record">

<literal>contains</literal></link>

</declare><constraint>

<name>UseCase1</name><description>This constraint makes Quantity Field of Contains Relationship view only</description>

<action><access mode="view">CONTAINSQUANTITY</access>

TIBCO Collaborative Information Manager Rulebase Guide

Page 20: Tib Cim Rulebaseguide

6 | Chapter 1 Getting Started with Rules

</action></constraint>

<constraint><name>UseCase2</name><description>This constraint provides view only access to records with UOM as EA</description><usefor>

<var>UOM</var></usefor>

<condition><eq>

<var>UOM</var><const type="string">EA</const>

</eq></condition>

<action><access mode="view_record"/>

</action></constraint></rulebase>

TIBCO Collaborative Information Manager Rulebase Guide

Page 21: Tib Cim Rulebaseguide

Header | 7

Header

The header of a rulebase consists of a name, description, error severity, and threshold settings. The header is followed by explicit variable declarations.

name, and description

The name tag identifies the constraint and the description tag provides a short description of the constraint, as shown in the following example:

<name>FirstArrivalDate</name> <description>Validations against First Arrival Date.</description>.........

The name tag is mandatory and should not contain spaces. The name should be unique across the rulebase.

The description tag can contain spaces.

severity and threshold

Each validation has a “severity” assigned to it. Each assignment has a “level” assigned to it. You can set various parameters to control the behavior of the rules depending on these values.

The defaults for these values can be set in the header, but they can also be assigned values dynamically in the assignment rules. See, assigns to error severity, warning and information threshold, page 22.

element Default Description

<error_severity> 9 All validations with severity <= error_severity are considered errors.

All validations with severity > error_severity are considered warnings.

Note: This parameter was previously called <severity>. <severity> will still work, but it should be renamed to <error_severity> when file is updated.

<warning_threshold> 99 All warnings with severity <= warning_threshold are displayed on the UI.

TIBCO Collaborative Information Manager Rulebase Guide

Page 22: Tib Cim Rulebaseguide

8 | Chapter 1 Getting Started with Rules

The error_severity tag can be used to define the default severity for the rulebase, as shown in the following example:

<name>StandardCatalogValidationst</name> <description>Implements Standard Validations</description> <error_severity>4</error_severity><warning_threshold>8</warning_threshold><information_threshold>6</information_threshold>

Skipping First Pass

When saving records, a rulebase is executed twice. The first time the rulebase handles propagations and the second time the actual assignment or validations are done. If a rulebase is triggered based on a condition and if the condition is always true, the rulebase is executed.

The value of the variable in the rulebase is incremented when the rulebase is executed based on a condition and the condition is met. This multi-pass approach is useful when some constraints are dependent on the attribute value changed in the propagate actions.

You can set the execution_directive first_pass flag to skip the first pass if there are no propagations defined in the rulebase. By default, the first pass is skipped. This improves the performance of record save.

On the other hand, if the parent record needs to propagate values to a child, you need the first pass processing. In that case, set the execution_directive first_pass to required .

See, Skip First Pass, page 152 for an example.

<information_threshold>

1 All assignments with level <= information_threshold are displayed on the UI.

element Default Description

TIBCO Collaborative Information Manager Rulebase Guide

Page 23: Tib Cim Rulebaseguide

Variable Declarations | 9

Variable Declarations

A list of variable declarations follows the header section. Each declare section can have the following parts:

• declare — starts a declaration.

• var — names the variable.

• datatype — contains the data type stored as a type attribute.

• link — defines relationship by pointing to another record in the same repository or a record in a different repository (cross-repository relationship).

declareThe declare tag starts a declaration. A usage attribute describes the type of variable.

You need to declare only regular variables associated with a link. Since a specified repository is being used, all other variables are implicitly declared.

<declare><var>EFFECTIVEDATE</var><datatype type="date"/>

</declare>

In the above example, the declaration is redundant since it is already known (from the repository definition) that EFFECTIVEDATE is a DATE variable.

Local and input variables should have type declarations, if the correct type is known. Otherwise, the data type of the assigned value is adopted. Input variables are used during mass-updates and ApplyRulebase activity from workflow. The following is an example of a local variable declaration.

<declare usage="local"> <var>SUPERID</var>

Usage Default Description

input No The variable is input from outside (that is, by the user.)

local No Value has to be assigned in rulebase.

output No Local variable that is exported to caller.

regular Yes Comes from repository or session.

TIBCO Collaborative Information Manager Rulebase Guide

Page 24: Tib Cim Rulebaseguide

10 | Chapter 1 Getting Started with Rules

<datatype type="string"/></declare>

The following is an example of an input variable declaration:

<declare usage="input"><var>SENDER_ORGANIZATION_TYPE</var>

</declare>

Output variables are used to pass information to the caller of the rulebase. Other components in TIBCO Collaborative Information Manager define configurations specified by setting a variable in the rulebase. These variables should be declared as output so their value is visible outside the rulebase.

The following is an example of output variable declaration:

<declare usage="output"><var>RELATIONSHIP_LIST</var>

</declare>

varThe var tag is mandatory, and contains the name of the variable. Variable names are not case sensitive.

datatypeThe datatype tag contains the data type of the variable. Only variables with usage equal to local, input, or output require a datatype. The actual data type is stored in an attribute called type. The type attribute has the following valid variables:

If you are not sure what type of data a variable will hold, it is best not to declare a type:

Data Type Repository Type Description

array Array An array of values. See, Exception for null assign to array variables, page 20.

boolean Boolean True or False.

date Date Date.

number Decimal, Amount, Integer

Any number format.

string String Declaration is optional if the variable has a string type.

TIBCO Collaborative Information Manager Rulebase Guide

Page 25: Tib Cim Rulebaseguide

Variable Declarations | 11

<declare usage="input"><var>SENDER_ORGANIZATION_TYPE</var>

</declare>

In this case, the variable will adopt the type of the object assigned to it.

There is an important difference for variables that are declared as “array”. If you assign a null value to an array variable, a null entry will be made into the array. This will result in an array of length 1 with the first entry being “null”. For all other types, the assignment would be ignored because it is null.

Refer to, assign and null values, page 19 for more details.

linkYou can use link declarations to access related objects during the execution of a rule. Links can be of the following types. The type is specified as an attribute to the link tag.

type Description

catalog Used to write SQL statements accessing repository tables.

classification Used to access classification codes and descriptions. Currently maps to a datasource which holds classification data.

datasource Used to write SQL statements accessing Data Source Values.

multi_relationship_record Records pointed at by following a chain of relationships.

record Points to a list of record objects.

relationship The relationship itself (to access relationship specific attributes).

relationship_record Record pointed at by a relationship.

TIBCO Collaborative Information Manager Rulebase Guide

Page 26: Tib Cim Rulebaseguide

12 | Chapter 1 Getting Started with Rules

relationship_record

The relationship_record link follows the relationship to the target record and retrieves an attribute value. If no attribute is specified, the whole record is returned, and the attribute can subsequently be accessed using the "/" notation. You can declare links in the rulebase header, so they are applied during execution.

The following are examples of relationship_record links.

<var>CHILDWEIGHT</var> will return an array of the netweights from all the records pointed at by CONTAINS relationships emanating from the current record.

<declare> <var>CHILDWEIGHT</var> <link type="relationship_record">

<literal>CONTAINS</literal><literal>NETWEIGHT</literal>

</link> </declare>

<var>CHILDSTATUS</var> will return an array of the status from all the records pointed at by relationships emanating from the current record.

<declare> <var>CHILDSTATUS</var> <link type="relationship_record">

<literal>CONTAINS</literal><literal>STATUS</literal>

</link> </declare>

If you declare a link without the second attribute, you can use the "/" notation to access the attribute, as shown in the following example:

<declare> <var>CONTAINSREL</var> <link type="relationship_record"> <literal>CONTAINS</literal></link>

</declare> ...<eq><var>CONTAINSREL/STATUS</var><const type="string">400</const></eq>

Argument Explanation

1 Relationship name.

2 Attribute name at target record (optional).

TIBCO Collaborative Information Manager Rulebase Guide

Page 27: Tib Cim Rulebaseguide

Variable Declarations | 13

multi_relationship_record

The multi_relationship_record link follows a chain of relationships and retrieves all the target records. For example, if you have a three level hierarchy of records (product->sku->component), with two relationships (product_sku and sku_component), you can directly retrieve all components for a product by specifying the two relationships in a multi_relationship_record.

The following is an example of how to use multi_relationship_record links:

<declare> <var>PRODUCT_COMPONENT</var><link type="multi_relationship_record">

<literal>PRODUCT_TO_SKU_REL</literal><literal>SKU_TO_COMPONENT_REL</literal>

</link></declare><constraint>

<name>ProductFlammableFlag</name><description>If any component has a flammable flag set, then set the flammable flag of the product</description><condition><and><eq> <var>RECORD_TYPE</var>

<const type="string">PRODUCT</const></eq>

<!-- the count function will count all non-FALSE entries --><op func="count"><eq><const type="string">Y</const><var>PRODUCT_COMPONENT/COMPONENT_FLAMMABLE_FLAG</var></eq></op></and></condition><action><assign><var>PRODUCT_FLAMMABLE_FLAG</var><const type="string">Y</const></assign></action><!-- clear flag is not true. --><action><assign><var>PRODUCT_FLAMMABLE_FLAG</var><const type="string">N</const></assign></action></constraint>

Argument Explanation

1..n Relationship names

TIBCO Collaborative Information Manager Rulebase Guide

Page 28: Tib Cim Rulebaseguide

14 | Chapter 1 Getting Started with Rules

</rulebase>

Another use of the multi_relationship_record is to access all siblings of a particular child record. For example, when writing a constraint for a SKU, you might want to check that the UOM for the SKU is unique. To retrieve all other SKUs in the product, we first traverse the relationship from the SKU to the PRODUCT and then back down to all the SKUs.

<?xml version="1.0" encoding="UTF-8"?><rulebase metaversion="0.1"><declare>

<var>SKU_SIBLING</var><link type="multi_relationship_record">

<literal>SKU_TO_PRODUCT_REL</literal><literal>PRODUCT_TO_SKU_REL</literal>

</link></declare><constraint><name>SKUDistinctUOM</name><description>UOM of SKUs must be unique.</description><usefor>

<var>UOM</var></usefor><condition>

<eq><var>RECORD_TYPE</var><const type="string">SKU</const>

</eq></condition><action>

<check><explanation>Uom of SKU must not be the same.</explanation><eq><op func="count">

<var>SKU_SIBLING/UOM</var></op><op func="count">

<op func="distinct"><var>SKU_SIBLING/UOM</var></op>

</op></eq></check>

</action></constraint></rulebase>

TIBCO Collaborative Information Manager Rulebase Guide

Page 29: Tib Cim Rulebaseguide

Variable Declarations | 15

relationship

A relationship link retrieves relationship specific attributes from a target. If no attribute is specified, a relationship object is returned. Relationship attributes can be retrieved using "/" notation.

The following example returns a relationship object and quantity:

<declare><var>RelationshipQuantity</var><link type="relationship">

<literal>CONTAINS</literal><literal>QUANTITY</literal>

</link></declare>

CONTAINSREL will be an array of all the Contains relationships emanating from the current record.

<declare><var>CONTAINSREL</var><link type="relationship">

<literal>Contains</literal></link></declare>

You can then access the Quantity for those relationships as in:

<declare><var>CONTAINSLINK</var><link type="relationship_record">

<literal>Contains</literal></link></declare><constraint><name>RollUpGrossWeight</name><description>Roll-up GrossWeight times Quantity.</description><action><assign><var>GROSSWEIGHT</var><op func="plus">

<op func="mult"><var>CONTAINSREL/QUANTITY</var><var>CONTAINSLINK/GROSSWEIGHT</var>

</op></op>

</assign></action></constraint>

Argument Explanation

1 Relationship name

2 Relationship specific attribute (optional)

TIBCO Collaborative Information Manager Rulebase Guide

Page 30: Tib Cim Rulebaseguide

16 | Chapter 1 Getting Started with Rules

To count the relationships, use the array directly:

<constraint><name>ContainsCount</name><description>Count relationships.</description><action>

<assign><var>ContainsCount</var><op func="count">

<var>CONTAINSREL</var></op>

</assign></action>

</constraint>

record

This link type points to a list of records. It can be populated by passing the variable name in the usefor clause of softlink action only. After evaluation, this variable points to a list of records.

Example: Using link type "record"

The following is an example where the variable is populated by passing the variable name in the usefor clause of the softlink action.

<?xml version="1.0" encoding="UTF-8"?><rulebase metaversion="0.1"><declare><var>RECORDS</var><link type="record"/></declare><constraint><name>Softlink recordlist</name><description>Softlink recordlist </description><usefor>RECORDS</usefor><!-- record link--><action><softlink mode="record"><table source="sql"><where><sql><eq><literal>MC1/ID</literal><var>ID</var></eq></sql></where></table></softlink></action>

TIBCO Collaborative Information Manager Rulebase Guide

Page 31: Tib Cim Rulebaseguide

Variable Declarations | 17

</constraint></rulebase>

After evaluation, RECORDS will point to a list containing records returned by softlink.

datasource, catalog and classification

Datasources can be stored in the current organization, or a shared copy can be stored in the TIBCOCIM enterprise. In other words, the rulebase will first look in the current organization, and only if the datasource is not found, it will look in the global TIBCOCIM enterprise.

NOTE: Currently, classification links point to a datasource, which has the same name as the classification scheme. Other than that, a classification variable can be treated just like a datasource.

For details on datasource, classification and catalog links, refer to section, SQL Expressions, page 60.

TIBCO Collaborative Information Manager Rulebase Guide

Page 32: Tib Cim Rulebaseguide

18 | Chapter 1 Getting Started with Rules

Actions

The action specifies what the rule actually does. The action that is executed depends on whether the condition evaluates to TRUE or FALSE. There can be two action tags. One action tag is mandatory, however, the second is optional. The following rules apply to action tag usage:

• If there is no condition or the condition is TRUE — then the first action tag executes.

• If the condition is FALSE and there is a second action tag — then the second action tag executes.

• If the condition is FALSE and no second action is present — then no action executes.

• If the condition cannot be evaluated because some of the variables are undefined — then no action executes.

The types of actions are listed in the following table:

Action Description

access Specifies whether an attribute is hidden, read-only, or variable.

assign Assigns a value to a variable.

check Checks whether the attribute meets a specified constraint.

clear Clears a variable.

condition Determines whether the action is executed or not.

connect Establishes a relationship between accessed records and the record that is being processed.

disconnect Removes a relationship between records.

duplicate Checks for record attributes having a duplicate value.

enum Lists values for a drop-down menu. Belongs inside the select tag.

propagate Rolls down action to another record.

refresh Specifies whether attributes should be refreshed when one of the variables it depends on is changed.

TIBCO Collaborative Information Manager Rulebase Guide

Page 33: Tib Cim Rulebaseguide

Actions | 19

You can combine multiple tags in one action. Only one select is allowed (since a value can only have one drop-down option).

assignYou can assign a value to a variable with the assign tag. If the variable is a catalog attribute or relationship attribute, that attribute is also assigned the value. The assignment occurs after the rulebase is executed. If you use the user interface to edit the product data, the post-assignment values dynamically update the screen display attributes. The following is an example of a post-assignment:

<assign><var>PRICE</var><const type="number">20.56</const>

</assign>

Although the first tag after the assign must be a variable, the second tag can be any tag that evaluates to a value. In other words, it can be a nested expression or a constant.

assign and null values

With one exception, assign will not assign a value if the value to be assigned is null.

<assign><var>DISCOUNT</var>

<op func="mult"><const type="number">0.20</const><var>PRICE</var>

</op></assign>

select Defines a list of values for the attribute in the usefor section.

slice Slices a table into columns.

softlink Indicates that a softlink is to be evaluated.

table References externally defined values.

usefor Specifies which attribute a select, softlink, check or access rule applies to, and serves two purposes:

• Defines which attribute is applicable for the rule

• Allows the use of the same rule for multiple attributes

Action Description

TIBCO Collaborative Information Manager Rulebase Guide

Page 34: Tib Cim Rulebaseguide

20 | Chapter 1 Getting Started with Rules

So if PRICE is null, the result of the “mult” operation will be null, and no assignment will be made to DISCOUNT.

For DISCOUNT to be null, use the following rule:

<constraint><name>ComputeDiscount</name><description>Compute Discount</description><condition><defined><var>PRICE</var></defined></condition><action>

<assign><var>DISCOUNT</var>

<op func="mult"><const type="number">0.20</const><var>PRICE</var>

</op></assign>

</action><action>

<clear><var>DISCOUNT</var>

</clear></action></constraint>

So if price is undefined, the condition is false, and the discount is cleared.

Exception for null assign to array variables

The exception for null inserts is for variables that are explicitly declared as array datatypes:

<declare usage="output"><var>RECEIVER_ORGANIZATION</var><datatype type="array"/>

</declare>

In this case even a null value will result in an entry being made into the array.

The exception is because arrays are often constructed in parallel to hold tabular data. For example, let’s say you want to pass the following values to the workflow:

Col1 Col2

A null

B D

TIBCO Collaborative Information Manager Rulebase Guide

Page 35: Tib Cim Rulebaseguide

Actions | 21

Since the best way to pass this data to other programs is by column, declare two variables “Col1” and “Col2”.

<declare usage="output"><var>Col1</var><datatype type="array"/>

</declare><declare usage="output">

<var>Col2</var><datatype type="array"/>

</declare>

If null assignments are ignored, this would result in:

Col1 = [A, B]Col2 = [D]

A recipient of this data would now not know how to reconstruct the data because Col1 and Col2 are no longer of equal length.

To achieve the above result, do not declare the variables as arrays.

<declare usage="output"><var>Col1</var>

</declare><declare usage="output">

<var>Col2</var></declare>

priority

Each assign action can have a priority. The value assigned to a variable is that of the highest priority assignment. One use of this is to define a "catch-all" default value at the end of the rulebase, which is assigned if no other value has been assigned to the variable.

Priority values can be between -9 and 9. If no value is specified, the priority is 1.

<constraint><name>LargeSizeDesignator</name><description>Size greater than 100 is Large.</description><condition>

<geq><var>SIZE</var><const type="number">100</const>

</geq></condition>

<action><assign priority="9">

<var>SIZE_DESIGNATOR</var><const type="string">LARGE</const>

</assign></action>

</constraint><constraint><name>SmallSizeDesignator</name>

TIBCO Collaborative Information Manager Rulebase Guide

Page 36: Tib Cim Rulebaseguide

22 | Chapter 1 Getting Started with Rules

<description>Size less than or equal to 10 is small.</description><condition>

<leq><var>SIZE</var><const type="number">10</const>

</leq></condition><action>

<assign priority="-9"><var>SIZE_DESIGNATOR</var><const type="string">SMALL</const>

</assign></action></constraint><constraint><name>MediumSizeDesignator</name><description>If not large/small, it must be medium.</description><action>

<!-- priority 0 is less than the priority of the small and large assignments, --><!-- so will only be used if as a default a value. --><assign priority="0"><var>SIZE_DESIGNATOR</var><const type="string">MEDIUM</const></assign></action></constraint>

level

Each assignment can have a level associated with it and can be used to control display of information messages on UI. All assignment messages with level less than or equal to information_threshold are displayed on the UI. The default value for level is 1.

<assign level="2"><var>PRICE</var><const type="number">20.56</const></assign>

assigns to error severity, warning and information threshold

It is possible to assign new values to severity levels and thresholds (for more details, see, severity and threshold, page 7). You can set thresholds based on user profiles or actions.

The following is a very basic example to check if "NEW_THRESHOLD" is defined (in actual usage, more specific and relevant conditions would be used).

<constraint><name>AssignNewInformationThreshold</name><description>Assign New Information Threshold</description><condition><defined>

TIBCO Collaborative Information Manager Rulebase Guide

Page 37: Tib Cim Rulebaseguide

Actions | 23

<var>NEW_THRESHOLD</var></defined></condition><action><assign>

<information_threshold/><var>NEW_THRESHOLD</var>

</assign></action></constraint>

Assigning values to multi-value attributes

For multi-value attributes, you can assign constant values using the <sep/> tag as follows:

<constraint><name>TestAssign</name><description>Test assign using sep tag</description><usefor><var>MTEST</var></usefor><action><assign> <var>MTEST</var> <const type="string">red<sep/>blue</const></assign></action></constraint>

You can also assign values using the input (or local) array variable:

<declare usage="input"><var>TEMP</var><datatype type="array"/>

</declare><constraint>

<name>TestAssign2</name><description>Assign using input variable</description>

<usefor><var>MTEST</var>

</usefor><action>

<assign><var>MTEST</var><var>TEMP</var>

</assign></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 38: Tib Cim Rulebaseguide

24 | Chapter 1 Getting Started with Rules

checkThe check action evaluates an expression as TRUE or FALSE. If the expression is true, the attribute is in compliance. If it is false, the check failed and an explanation is shown.

<constraint> <name>GTIN</name> <description>GTIN checks.</description> <usefor> <var>GTIN</var> <var>REPLACES_GTIN</var> </usefor> <action> <check> <explanation>GTIN cannot start with 0980, 0981, 0982, 0983, 0984, 0985, 0986,098, 0988, 0989, 099</explanation> <not> <or> <in> <op func="substring"> <var>GTIN</var> <const type="number">0</const> <const type="number">4</const> </op> <const type="string">0980</const> <const type="string">0981</const> <const type="string">0982</const> <const type="string">0983</const> <const type="string">0984</const> <const type="string">0985</const> <const type="string">0986</const> <const type="string">0988</const> <const type="string">0989</const> </in> <in> <op func="substring"> <var>GTIN</var> <const type="number">0</const> <const type="number">3</const> </op> <const type="string">098</const> <const type="string">099</const> </in> </or> </not> </check> </action> </constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 39: Tib Cim Rulebaseguide

Actions | 25

severity

Each validation can have a severity level. The lower the severity, the more serious the error. For example, a severity level of 2 is more serious than a severity of 4. The severity level interpretation can vary depending on when a rule is executed. It is up to the user to interpret the implication and act accordingly.

Severity levels can range from 1 (most critical) to 99 (least critical). Severity is specified as a severity attribute to the check and select tags, as shown in the following example.

<check severity="3"><gt><var>VOLUME</var><const type="number">0</const></gt></check>

You can specify the level of severity that must be reached for an operation to fail. For example, if you specify the error severity as 4, all validations with severities less than or equal to 4 cause the operation to fail. All other errors appear as warning or information messages.

clearAssign will NOT assign a null value to a variable. In other words, if the value of an assign evaluates to null, no assignment will be done. To clear a variable, use the clear action.

<clear><var>PRICE</var></clear>

Note: Priorities can also be used for clear. Refer to, Global Property Settings for Rules, page 56 for details on priority.

conditionThe condition determines whether the action is executed or not. The condition should evaluate to TRUE or FALSE or be “undefined” (evaluate to null). Note that if there is no condition, the action is always executed.

The following rules apply:

• When TRUE, the first action following the condition tag is executed.

Multi-value attributes can also be cleared using clear action.

TIBCO Collaborative Information Manager Rulebase Guide

Page 40: Tib Cim Rulebaseguide

26 | Chapter 1 Getting Started with Rules

• When FALSE, the second action is executed.

• When the condition cannot be evaluated, because the variables do not have a value, neither action is executed.

• If there is no condition, the first action is executed.

The following is an example of condition tag usage:

<constraint> <name>UPC12</name> <description>Check length of UPC code based on type.</description> <usefor> <var>UPC</var> </usefor> <condition> <or> <eq> <var>UPC_TYPE</var> <const type="string">UN</const> </eq> <eq> <var>UPC_TYPE</var> <const type="string">UP</const> </eq> <eq> <var>UPC_TYPE</var> <const type="string">UA</const> </eq> <eq> <var>UPC_TYPE</var> <const type="string">UD</const> </eq> <eq> <var>UPC_TYPE</var> <const type="string">UE</const> </eq> <eq> <var>UPC_TYPE</var> <const type="string">UG</const> </eq> </or> </condition> <action> <check> <explanation>For UPC Type UN,UP,UA,UD,UE,UG UPC must have length 12</explanation><eq> <op func="length"> <var/> </op> <const type="number">12</const></eq> </check> </action> <action> <check>

TIBCO Collaborative Information Manager Rulebase Guide

Page 41: Tib Cim Rulebaseguide

Actions | 27

<explanation>For UPC Type not equal to UN,UP,UA,UD,UE,UG UPC must have length 10</explanation> <eq> <op func="length"> <var/> </op> <const type="number">10</const> </eq> </check> </action> </constraint>

The condition code will also convert other values to TRUE or FALSE.

For example, when using the count operator, the two expressions will give the same result:

<condition><gt><op func="count"><var>CONTAINSREL</var></op><const type="number">0</const></gt></condition>

and

<condition><op func="count"><var>CONTAINSREL</var></op></condition>

In the second case, if count evaluates to 0, it will automatically be converted to FALSE.

If UPC_TYPE is not assigned a value, neither action executes because the condition will evaluate to null.

Datatype TRUE FALSE

string TRUE; YES; T, Y, 1 All other non-null values

number not 0 0

TIBCO Collaborative Information Manager Rulebase Guide

Page 42: Tib Cim Rulebaseguide

28 | Chapter 1 Getting Started with Rules

connectThis action establishes a relationship between accessed records and the record that is being processed. This action will access related records (argument 2) and establish the specified relationship (argument 1) with the specified quantity (argument 3).

To filter records based on any repository attribute and to create relationships using a rulebase, use the connect action in conjuction with the softlink action.

NOTE: To use connect action with the EvaluateRulebase activity, the name of the relationship specified in the connect constraint must be specified in the relationship name list of the ManageRecordCollection activity. Also, the ‘BundlingOption’ parameter of the ManageRecordCollection activity must be set to true.

Note: When specifying a relationship attribute, the Literal tag must be followed by the Var/Const tag. Multiple relationship attributes can be passed to the connect action.

Example: connect used in conjuction with softlink

Let us consider two repositories: CUSTOMER and ADDRESS. The records in these two repositories are related using the customer ID. Let us say, you want to find address records for a particular customer and then create a relationship using a rulebase.

To do this, you need to run a SQL query to find the address records which match a given customer ID and then issue a create relationship command.

<?xml version="1.0" encoding="UTF-8"?><rulebase metaversion="1.0"><name>Cconnect sample</name>

Table 2 connect

Argument Argument Type Required? Argument Description

1 Literal N Relationship type name using which relationship will be established

2 Var (link type = record) Y Variable pointing to a list of record objects.

See, record, page 16.

3 Literal N Name of the relationship attribute.

4 Var/Const N Value to be assigned to the relationship attribute.

TIBCO Collaborative Information Manager Rulebase Guide

Page 43: Tib Cim Rulebaseguide

Actions | 29

<description>Place this rulebase in catalogvalidattion.xml ofcatalog to automatically create "Shipping Address".</description><declare><var>ADDRESSCATALOG</var><link type="catalog"><literal>ADDRESS</literal><literal>STATE/CONFIRMED</literal><!-- consider only confirmed records --></link></declare><declare><var>ADDRESSRECORDS</var><link type="record"/></declare><constraint><name>AddressSoftlink</name><description>Returns ADDRESS records having same CUSTOMERID as thatthe record being processed.</description><usefor><var>ADDRESSRECORDS</var></usefor><!-- record link--><action><softlink mode="record"><!-- note the mode here --><table source="sql"><where><sql><eq><literal>ADDRESSCATALOG/CUSTOMERID</literal><var>CUSTOMERID</var></eq></sql></where></table></softlink></action></constraint><constraint><name>AddressConnect</name><description>Connect Address records using 'Shipping Address'</description><action><connect><literal>Shipping Address</literal><!-- relationship name--><var>ADDRESSRECORDS</var><literal>TYPE</literal><!-- name --><const type="string">MAILING</const><!-- value --><literal>PREFERRED </literal><const type="string">yes</const></connect></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 44: Tib Cim Rulebaseguide

30 | Chapter 1 Getting Started with Rules

</rulebase>

disconnectThis action allows you to remove relationships between records. If any relationship attributes are defined with the relationship, such attributes are also removed.

The action accepts a record list and a relationship name. The record list can be generated using:

• relationship_record link — The relationship_record link can be used to get the related records. The filter function can be applied to the relationship_link result to get the required records.

For more information on relationship_record link, refer to, relationship_record, on page 12.

• softlink action — The record list can also be populated using the softlink action. However, softlink does not allow you to filter out the related record, and may return unrelated records.

For more information on the softlink action, refer to, softlink, on page 42.

A sample rulebase is available in $MQ_COMMON_DIR/standard/samples/rulebase/disconnectsample.xml .

Example: Selecting records

The relationship_record link can be used to get the related records. The filter function can be applied to the relationship_link result to get the required records.

<declare><var>UPSELL_RELATIONSHIP</var>

<link type="relationship_record"><literal>Upsell</literal>

</link></declare><declare>

<var>RECORD_LIST</var> <datatype type="array"/>

Table 3 disconnect

Argument Argument Type Required? Argument Description

1 Literal Y Name of the relationship to be removed.

2 Var (link type = record) Y Variable pointing to a list of records.

See, record, page 16.

TIBCO Collaborative Information Manager Rulebase Guide

Page 45: Tib Cim Rulebaseguide

Actions | 31

</declare><constraint><name>SelectChildren</name><description>Obtain list of records for disconnect</description><action>

<assign><var>RECORD_LIST</var><op func="filter"><var>UPSELL_RELATIONSHIP</var><condition><eq>

<var>SHORTDESC</var><const type="string">test</const><!-- Select all records with short description as test --></eq>

</condition></op>

</assign></action></constraint>

Example: disconnect

The disconnect action accepts a list of records and relationship name as follows:

<constraint><name>testDisconnect</name><description>disconnect</description><condition>

<defined><var>RECORD_LIST</var>

</defined></condition><action>

<disconnect><literal>Contains</literal><var>RECORD_LIST</var>

</disconnect></action>

</constraint>

duplicateThe duplicate action checks for record attributes having a duplicate value. For example, if value of RECORD_TYPE attribute needs to be unique, apply a duplicate check on it.

A duplicate check is not supported for multi-value attributes.

TIBCO Collaborative Information Manager Rulebase Guide

Page 46: Tib Cim Rulebaseguide

32 | Chapter 1 Getting Started with Rules

Let us say, you now add record A with RECORD_TYPE = A. Then, you add record B with RECORD_TYPE = A. An error is displayed.

Here is an example of the syntax:

<name>duplicateCheck</name><description>Checking for duplicates.</description><error_severity>4</error_severity><constraint><name>DuplicateRECORDTYPECheck</name><description>DuplicateRECORDTYPECheck</description><usefor><var>RECORD_TYPE</var><var>UOM</var></usefor><action>

<check severity="1"><explanation>This record type already exists.</explanation>

<duplicate><var>RECORD_TYPE</var><var>UOM</var>

</duplicate></check></action></constraint></rulebase>

enumThe enum tag belongs inside the select tag, and explicitly lists values for a drop-down menu. Multiple values can be specified using the empty sep (separator). The enum tag has two attributes: header, which determines whether the first row of data is the column headers and col, which defines the number of columns in the table.

header

The header attribute specifies whether the first row of data is the description of the columns or column data. The default if no value is specified is <enum header="no">, that is, the first row contains data.

header Option Description

<enum header="no"> There are no column names in the data. The first row is a data column.

<enum header="yes"> The first row of data contains the column headers.

TIBCO Collaborative Information Manager Rulebase Guide

Page 47: Tib Cim Rulebaseguide

Actions | 33

col

When more than two columns are specified, the select tag interprets the first column as the value stored in the database. Each subsequent value is a display value. The following example creates a list of three items, under a header “Soup Styles”.

<select novalue="default"> <enum header=”yes”> <const type="string">Soup Styles</const><const type="string">Classic</const><const type="string">Chunky</const><const type="string">Light</const></enum> </select>

The next example creates a list of three items (because novalue is set to "no"). Since showoninput="2", only the second column is displayed in the drop-down: Classic, Chunky, and Light. However, the values stored in the database are CL,CH,LT. The use of col="2" indicates the two sets of values, otherwise the drop-down menu would display all six items.

<select showoninput="2"> <enum col="2"> <const type="string">CL<sep/>Classic</const> <const type="string">CH<sep/>Chunky</const> <const type="string">LT<sep/>Light</const> </enum> </select>

<enum> same as <enum header="no">

header Option Description

The number of columns is solely determined by the col attribute, not by the use of the sep tag.

TIBCO Collaborative Information Manager Rulebase Guide

Page 48: Tib Cim Rulebaseguide

34 | Chapter 1 Getting Started with Rules

propagateYou can propagate changes of the rulebase to other records with the propagate action.

The propagate tag can be of two types: rulebase or inline.

Type: rulebase

The following table lists the arguments for propagate of type="rulebase":

In the following example, the current record context is passed down as a record CONTAINSLINK variable.

<action><propagate type="rulebase"><var>CONTAINSLINK</var><literal>custom/rulebase/RollDownStatus</literal></propagate></action>

In case of cross repository relationships, for propagation to work during add and modify record place rules in the catalogvalidation.xml file of the parent repository. For example, if CUSTOMERID attribute of the CUSTOMER repository needs to be propagated to the ADDRESS repository, place the rules in the CUSTOMER repository’s catalogvalidation.xml .

Also, for propagation to work correctly, first pass must be set to required . To do this, add the following in the rulebase file:<execution_directive first_pass="required"/>

If you want propagation during add record only, place the rules in the newrecord.xml file of the child record.

Argument Explanation

1 Relationship variable

2 Rulebase

The rulebase is described by a file relative to the environment variable $MQ_COMMON_DIR.

TIBCO Collaborative Information Manager Rulebase Guide

Page 49: Tib Cim Rulebaseguide

Actions | 35

Type: inline

The following table lists the arguments for propagate of type="inline":

In the following example, the current record context is passed down as a record variable called CONTAINSLINK. The LINK/HAZMATFLAG refers to the HAZMATFLAG where the propagate tag was defined. This traverses the CONTAINS link to the child record, and then copies the parent HAZMATFLAG to the child. The end result is a child record with the same HAZMATFLAG value as its parent.

<action><propagate type="inline"><var>CONTAINSLINK</var><action><assign><var>HAZMATFLAG</var><var>LINK/HAZMATFLAG</var></assign></action></propagate></action>

refreshWhen the user enters a new value in a drop-down list, all attributes that use that value in their computation are refreshed. This refresh involves a trip to the server.

Sometimes, however, the benefit of having an updated value does not compensate for the delay incurred in having to wait for that value. If that is the case, the system allows you to set the “refresh” to “no”. This means that the attribute is not refreshed when one of the variables it depends on is changed.

The attribute can be added to the following tags:

• <assign>

• <select>

• <condition>

• <clear>

Argument Explanation

1 Relationship variable

2 Action

TIBCO Collaborative Information Manager Rulebase Guide

Page 50: Tib Cim Rulebaseguide

36 | Chapter 1 Getting Started with Rules

Select

In the following rule:

<constraint><name>SubCategorySoup</name><description>Sub Category for Soup</description><usefor><var>CLASSIFICATIONLEVEL5</var></usefor><condition><eq><var>CLASSIFICATIONLEVEL4</var><const type="string">Soup</const></eq></condition><action><select novalue="no"><enum><const type="string">Classic</const><const type="string">Chunky</const><const type="string">Light</const></enum></select></action></constraint>

The code checks variables that could affect the value of “CLASSIFICATIONLEVEL5”.

In this case, the analysis is:

CLASSIFICATIONLEVEL4 -> CLASSIFICATIONLEVEL5

which means that “when CLASSIFICATIONLEVEL4 changes, you need to refresh CLASSIFICATIONLEVEL5”.

With the refresh flag, this is suppressed:

<constraint><name>SubCategorySoup2</name><description>Sub Category for Soup</description><usefor><var>CLASSIFICATIONLEVEL9</var></usefor><condition><eq><var>CLASSIFICATIONLEVEL8</var><const type="string">Soup</const></eq></condition><action><select novalue="no" refresh="no"><enum><const type="string">Classic</const><const type="string">Chunky</const><const type="string">Light</const>

TIBCO Collaborative Information Manager Rulebase Guide

Page 51: Tib Cim Rulebaseguide

Actions | 37

</enum></select></action></constraint>

In this case, when CLASSIFICATIONLEVEL8 changes, there will be no refresh for CLASSIFICATIONLEVEL9.

Assignment

Assignments work in a similar manner:

<constraint><name>EnumLookup</name><description>Lookup based on enum values.</description><action><assign><var>TEMPDESCRIPTION</var><op func="lookup"><var>TEMPCODE</var><enum col="2"><const type="string">FA<sep/>Fahrenheit</const><const type="string">CE<sep/>Celsius</const><const type="string">KA<sep/>Kelvin</const><const type="string">EA<sep/>Each</const><const type="string">CS<sep/>Case</const><const type="string">PA<sep/>Pallet</const></enum></op></assign></action></constraint>

Without the refresh flag, any changes to TEMPCODE will refresh the screen.

With the refresh flag, this rule will not trigger a refresh.

In other words, even if only 1 rule out of 10 does not have refresh set to “no”, it will refresh if the variables in that rule change.

Condition

The refresh flag on assign and select suppresses the refresh for all variables, including those used in the <condition>.

However, you might sometimes want to ignore those variables in the <condition> but still refresh if a variable in the <action> changed. For this, you can selectively disable the trigger on the <condition>. For example:

A change to TEMPCODE could still trigger a refresh if some OTHER rule used it on the right hand side of the assign.

TIBCO Collaborative Information Manager Rulebase Guide

Page 52: Tib Cim Rulebaseguide

38 | Chapter 1 Getting Started with Rules

<constraint><name>EnumLookup</name><description>Lookup based on enum values.</description><action><condition refresh=”no”><or><eq><var>UOM</var><const type="string">EACH</const></eq><eq><var>UOM</var><const type="string">CASE</const></eq></or></condition><assign><var>ATTRIBUTE3</var><op func="lookup"><var>ATTRIBUTE3</var><enum col="2"><const type="string">FA<sep/>Fahrenheit</const><const type="string">CE<sep/>Celsius</const><const type="string">KA<sep/>Kelvin</const><const type="string">EA<sep/>Each</const><const type="string">CS<sep/>Case</const><const type="string">PA<sep/>Pallet</const></enum></op></assign></action></constraint>Will refresh if ATTRIBUTE3 changes, but NOT if UOM changes. Normally, it would refresh if any of the above variables changed.

selectThe select tag is of two types, and specifies a list of values allowed for an attribute:

• Uses the enum tag to explicitly list out the values that can appear.

• Uses the table tag to refer to an external source for the values.

In the user interface, the select action is used to construct a drop-down list. For non-interactive loading, it is used to check if an attribute is one of the values allowed in the list.

The select action expects a table of values. The first column in the table is assumed to be the value stored in the database. All subsequent values are display values.

Although the first column value is stored in the database, the user can choose the columns that are displayed using the showoninput tag.

TIBCO Collaborative Information Manager Rulebase Guide

Page 53: Tib Cim Rulebaseguide

Actions | 39

novalue

The novalue attribute for the select tag specifies whether an empty value appears in the drop-down menu. The attribute options are listed in the following table. The default is <select novalue="no">.

Note: The novalue attribute is not supported in case of multi-value attributes.

novalue and automatic attribute initialization

Depending on the “novalue” attribute, the behavior for automatically assigning values to the attribute is different.

novalue=”default”

The attribute is not initialized but remains null.

novalue=”option”

During new record creation only, the attribute is assigned the first value in the drop-down list. If the value is set to null after that, it remains null.

novalue=”no”

If the attribute value is null, it is always initialized to the first value in the drop-down. In other words, this attribute should never have a null value. This is true both for creation and modification of records.

novalue Option Description

<select novalue="default"> The empty value appears as the first value in the list.

<select novalue="option"> The empty value appears at the bottom of the list.

<select novalue="no"> The empty value does not appear in the list.

TIBCO Collaborative Information Manager Rulebase Guide

Page 54: Tib Cim Rulebaseguide

40 | Chapter 1 Getting Started with Rules

order

The order attribute of the select tag specifies the sort order of the dropdown in the rulebase. The sort order can be mentioned as ascending or descending for particular columns in the dropdown.

To get the expected results, the correct syntax is: <select order="1,-2" novalue="default">

and not:<select order="-2,1" novalue="default">

showoninput

The showoninput attribute for the select tag specifies the columns that appear in a multi column drop-down. For example, if your drop-down has 3 columns, you might decide to show only columns 2 and 3, since the first column is the database code, which is not relevant to the user. The default is to show all columns, with column numbers starting at 1.

Table 4 Syntax for order attribute

Syntax Sort Details

<select order="1,-2" novalue="default">

Dropdown is sorted in the ascending order of the first column and descending order of the second column.

<select order="-1,2" novalue="default">

Dropdown is sorted in the descending order of the first column and the ascending order of the second column.

<select order="-2,1" novalue="default">

Dropdown is sorted in the descending order of the second column. Option "1" is ignored.

The order attribute works only for select of type table.

novalue Option Description

<select> Show all columns.

<select showoninput="2"> Show only the second column.

<select showoninput="1,3"> Show the first column and the third column. Do not show the second column.

TIBCO Collaborative Information Manager Rulebase Guide

Page 55: Tib Cim Rulebaseguide

Actions | 41

sliceThis action allows you to slice a table into columns. Each column is assigned to a different variable. These variables are usually passed into the rulebase for further processing.

For example, let us say, a table contains the following rows:PRODUCTKEYID PRODUCTID UOM100 00009000000034 BASE_UNIT_OR_EACH101 00009000000126 CASE 102 00009000000560 PALLET

Use the slice action as follows:

<declare><var>MC1</var><link type="catalog"><literal>MC1</literal></link></declare><declare usage="output"><var>ARR_PROD_KEY_ID</var><datatype type="array"/></declare><declare usage="output"><var>ARR_PROD_ID</var><datatype type="array"/></declare><declare usage="output"><var>ARR_UOM</var><datatype type="array"/></declare><constraint><name>SliceTest</name><description>Get record keys</description><action><slice><var>ARR_PROD_KEY_ID</var><var>ARR_PROD_ID</var><var>ARR_UOM</var><table source="sql"><literal>MC1/PRODUCTKEYID</literal><literal>MC1/PRODUCTID</literal><literal>MC1/UOM</literal><where><sql><and><eq><literal>MC1/RECORD_TYPE</literal><const type="string">MIXES</const></eq><neq><literal>MC1/PRODUCTIDEXT</literal><const type="string">DNB</const></neq></and>

TIBCO Collaborative Information Manager Rulebase Guide

Page 56: Tib Cim Rulebaseguide

42 | Chapter 1 Getting Started with Rules

</sql></where></table></slice></action></constraint>

After the slice, you will have the following arrays:

ARR_PROD_KEY_ID = [100, 101,102]

ARR_PROD_ID = [00009000000034, 00009000000126, 00009000000560]

ARR_UOM = [BASE_UNIT_OR_EACH, CASE, PALLET]

softlinkRecords are typically stored in more than one repository. For example, vendors could be stored in one repository and customers in another. However, almost all the time, the records from one repository need to be linked to records in other repositories. The links can be made in two ways:

1. Soft links: That is, links are evaluated every time they are accessed. As data changes, each evaluation can result in different results. There is no permanent binding.

2. Hard links: This is supported for records within the same repository, that is, contains.

The softlink action indicates that a soft link is to be evaluated.

Modes

The softlink action supports two modes:

• view (display mode) — Creates a hyperlink. When the hyperlink is clicked, a query is executed and it returns a list of records matching the selection criteria.

• record (non-display mode) — Executes a query and returns a list of records matching the selection criteria. In addition, it populates a record link variable and the Usefor variable points to the record link variable.

Softlink definitions with mode=record should precede corresponding connect actions.

To use softlink action with connect action, set softlink action mode to 'record'.

TIBCO Collaborative Information Manager Rulebase Guide

Page 57: Tib Cim Rulebaseguide

Actions | 43

The following table lists the arguments for softlink:

ExampleIn the following example of softlink, the PRICETYPE attribute is linked to one or more records from MASTER3 repository that have the UOM=PACK.

<declare><var>MASTER3</var><link type="catalog"><literal>MASTER3</literal></link></declare><constraint><name>PRICETYPE</name><description>Select possible PriceTypes from Master3 whereUOM is PACK</description><usefor><var>PRICETYPE</var></usefor><action><softlink mode=”view”><table source="sql"><where><sql><eq><literal>MASTER3/UOM</literal><const type="string">PACK</const></eq></sql></where></table></softlink></action></constraint>

To fetch the latest records with state CONFIRMED or UNCONFIRMED, declare the catalog link as follows:

<declare><var>MASTER3</var>

Argument Explanation Required? Description

1 Link Attribute

Y The attribute hyperlink that should be shown. For non display operations, this input is ignored.

2 Table Y Define the criterion for selection of records. Only supported type will be SQL. Table must contain SQL element.

TIBCO Collaborative Information Manager Rulebase Guide

Page 58: Tib Cim Rulebaseguide

44 | Chapter 1 Getting Started with Rules

<link type="catalog"><literal>MASTER3</literal><literal>STATE/UNCONFIRMED</literal></link></declare>

tableThe table tag references externally defined values.

Example

The following example selects a distinct countrycode and countryname from the countrycodes datasource sorted by countrycodes:

<constraint><name>ConstraintToGetCountryCodes</name>

Option Description

source The source attribute defines the location of the source data. A valid value for source is:

• datasource - See, source="datasource", page 61.

• sql - See, sql Function, page 66.

distinct The distinct attribute allows you to filter duplicates and display only distinct or unique values from retrieved values.

For example, let us say, a city column has the following values:

San FranciscoPalo AltoSan JosePalo Alto

You can ensure that a result set displays only three entries and not four (since Palo Alto appears twice) by specifying the distinct="true" attribute.

order The order attribute allows you to sort the result set based on the columns specified. The value for order must be specified in the following format.order="[-]<columnpostion1>[,[-]<columnposition2>,..]"

Where:

- indicates descending order

<columnpositon> specifies column position based on the columns selected.

Multiple columns can be specified separated by comma.

TIBCO Collaborative Information Manager Rulebase Guide

Page 59: Tib Cim Rulebaseguide

Actions | 45

<description>Get country codes from COUNTRYCODES</description> <usefor><var>COUNTRY</var></usefor><action><select><table source="datasource" distinct="true" order="1"><literal>COUNTRYCODES</literal><literal>COUNTRYCODE</literal><literal>COUNTRYNAME</literal></table></select></action></constraint>

useforThe usefor tag specifies which attribute a <select>, <softlink>, <check> or <access> rule applies to, and serves two purposes:

• Defines which attribute is applicable for the rule

• Allows the use of the same rule for multiple attributes

If you use multiple var tags within a usefor tag, the rule applies to each attribute.

For example, you could define Boolean values to have a drop-down menu showing TRUE and FALSE (two values) as follows:

<?xml version="1.0" encoding="UTF-8"?><rulebase metaversion="0.1"><constraint> <name>TrueFalse</name> <description>True or False.</description> <usefor> <var>HAZMATFLAG</var><var>RECYCLEDMATERIALS</var> <var>FREIGHTINCFLAG</var> <var>CONSUMER_UNIT</var> <var>ORDERABLE</var> </usefor> <action> <select novalue="default"> <enum> <const type="string">TRUE</const> <const type="string">FALSE</const> </enum> </select> </action></constraint>

The <assign> actions do not require the use of a <usefor> tag.

TIBCO Collaborative Information Manager Rulebase Guide

Page 60: Tib Cim Rulebaseguide

46 | Chapter 1 Getting Started with Rules

</rulebase>

The previous rule applies to the following variables: HAZMATFLAG, RECYCLEDMATERIALS, FREIGHTINCFLAG, CONSUMER_UNIT, and ORDERABLE. These variables must be present in the repository.

In the following example, the var tag refers to the GTIN and then REPLACES_GTIN.

<constraint> <name>GTIN</name> <description>GTIN checks.</description> <usefor> <var>GTIN</var> <var>REPLACES_GTIN</var> </usefor> <action> <check> <explanation>GTIN has to be 14 numeric characters.</explanation> <match> <var/> <const type="string">/^\d{14}$/</const> </match> </check> </action> </constraint>

If you refer to usefor variables for which the rule is configured, you can abbreviate the notation using an empty var tag.

TIBCO Collaborative Information Manager Rulebase Guide

Page 61: Tib Cim Rulebaseguide

Access Modes | 47

Access Modes

The access tag controls viewing, modification, and visibility of the attribute group or an attribute. The access mode does not have a direct effect on the execution of the rule, other than being returned as a directive to the user interface to hide certain elements. Certain access modes apply to the complete record and take precedence over the access modes specified for the attributes and attributes groups of such records.

Access modes allow you to control the visibility and access to entire record, an attribute group or an attribute.

The following table lists the levels of access and their effects.

• For access mode specification to work correctly, the names of the attribute and the attribute group must not be the same.

• Access for multi-value attributes can also be controlled using the access tag.

• In case of rulebase evaluation with relationship attribute values, the access modifiers on records based on relationship attribute are not applied on the record list. For example, if you try to hide some records from a record list based on their relationship attribute value for a particular relationship, the records are not hidden.

Attribute Effect

<access mode="hide"> The attribute or attribute group will not be visible in the UI.

Note: Though a repository validation rulebase allows any attribute to be hidden, including required attributes, TIBCO recommends that you do not hide any of the required attributes (such as PRODUCTID) during create and/or modify as this will not allow you to create or modify a record.

<access mode="view"> The attribute or attribute group appears on the screen as read-only.

<access mode="modify"> The attribute or attribute group appears on the screen and can be modified by the user.

TIBCO Collaborative Information Manager Rulebase Guide

Page 62: Tib Cim Rulebaseguide

48 | Chapter 1 Getting Started with Rules

Rules are executed in the order in which they are defined in the rulebase. For this reason, exceptional cases should appear at the top of the file and general cases near the bottom. In other words, as soon as an “access mode” is assigned to a particular attribute, all subsequent ones will be ignored. Which one is first, of course, depends on the <condition> of that rule.

Since “record” level access actions are translated into SQL, some restrictions exist as to which operators can be used. Refer to, Restrictions on Record Access Conditions, page 54.

Order of Precedence for Attribute Group Permissions

It is recommended that you manage the attribute group permission through one method — either the user interface or the Rulebase. When the attribute group permissions are specified in both the places, permissions specified in the user interface take precedence. The order is:

1. Use the Administration > Resource Security menu decide a set of permissions on the attribute groups.

If you hide an attribute group using this menu, modifiers cannot be applied in the rulebase.

2. Apply rulebase modifiers on the attribute groups obtained from Administration > Resource Security.

Repository Attributes

In the following example, the shipping code is hidden (does not display on the screen), since it is only relevant to the Logistics department. This is an exceptional case and should be defined at the top of the rulebase with a rule defining the defaults following.

<access mode="hide_record">

This access mode applies to the entire record. The record does not appear in the record list or in relationships.

<access mode="view_record">

This access mode applies to the entire record. The record appears in the record list, but cannot be modified. Refer to, Restrictions on Record Access Conditions, page 54.

Attribute Effect

HIDE takes precedence irrespective of whether it is set using the Administration > Resource Security menu or the Rulebase.

TIBCO Collaborative Information Manager Rulebase Guide

Page 63: Tib Cim Rulebaseguide

Access Modes | 49

<constraint><name>LogisticsOp</name><description>Show fields for logistics Op</description><usefor><var>ShippingCode</var></usefor><condition><eq><var>ACTIVITY_NAME</var><const type="string">EnterLogisticInfo</const></eq></condition><action><access mode="modify"/></action></constraint><constraint><name>DefaultAttributeMode</name><description>Default attribute values</description><action><!--Only executed if first rule was not executed.The attribute name is explicitly mentioned here.--><access mode="hide">SHIPPING_CODE</access></action></constraint>

Restrictions on Attribute Access Conditions

When hiding attributes during Record List displays, the condition will not evaluate any attribute values. The only values that can be used are those based on the SESSION or repository. The reason is that it is not possible to evaluate the attribute access for each record in the list. The results might well be contradictory.

Relationship Attributes

Relationship attributes can also have their access mode controlled. To define the access mode on the relationship attribute, it is necessary to <declare> the relationship first.

Two styles of relationship definitions can be used:

• declaring the relationship attribute in the declaration

• using the “/” notation.

In most cases, the “/” style of the definition is more convenient, as the relationship will already be declared.

TIBCO Collaborative Information Manager Rulebase Guide

Page 64: Tib Cim Rulebaseguide

50 | Chapter 1 Getting Started with Rules

Example

The “Default” rule at the end will only be valid if UOM is undefined. It will provide access when a new record is added.

<declare><var>CONTAINSREL</var><link type="relationship"><literal>Contains</literal></link></declare><!-- the following declaration is only here for illustrationpurposes --><!-- it could be more convenient to use<var>CONTAISREL/QUANTITY</var> instead --><declare><var>CONTAINSQUANTITY</var><link type="relationship"><literal>Contains</literal><literal>Quantity</literal></link></declare><declare><var>CONTAINEDREL</var><link type="relationship"><literal>ContainedBy</literal></link></declare><!-- the following declaration is only here for illustrationpurposes --><!-- it could be more convenient to use<var>CONTAINEDREL/QUANTITY</var> instead --><declare><var>CONTAINEDQUANTITY</var><link type="relationship"><literal>ContainedBy</literal><literal>Quantity</literal></link></declare><!-- We assume the following 3 Level structureUOM = PLcontainsUOM = CScontainsUOM = EA--><declare usage="local"><var>IS_SUPERVISOR</var></declare><constraint><name>IsSupervisor</name><description>User is supervisor if role contains Admin orSupervisor.</description><action><assign><var>IS_SUPERVISOR</var>

TIBCO Collaborative Information Manager Rulebase Guide

Page 65: Tib Cim Rulebaseguide

Access Modes | 51

<or><in><const type="string">Work Supervisor</const><var>SESSION/USER_ROLES</var></in><in><const type="string">Admin</const><var>SESSION/USER_ROLES</var></in></or></assign></action></constraint><constraint><name>PalletAccess</name><description>If UOM is PL, access for contains Quantity is modify and access for containedby quantity is view.</description><condition><and><eq><var>UOM</var><const type="string">PL</const></eq><not><var>IS_SUPERVISOR</var></not></and></condition><action><access mode="modify">CONTAINSQUANTITY</access><access mode="view">CONTAINEDREL/QUANTITY</access></action></constraint><constraint><name>CaseAccess</name><description>If UOM is CS then access for contains Quantity is hide, containedby Quantity is view.</description><condition>

<and><eq><var>UOM</var><const type="string">CS</const></eq><not><var>IS_SUPERVISOR</var></not></and></condition><action><access mode="hide">CONTAINSREL/QUANTITY</access><access mode="view">CONTAINEDQUANTITY</access></action></constraint><constraint><name>EachAccess</name>

TIBCO Collaborative Information Manager Rulebase Guide

Page 66: Tib Cim Rulebaseguide

52 | Chapter 1 Getting Started with Rules

<description>If UOM is EA, access for contains quantity is view and access for containedby quantity is hide.</description><condition><and><eq><var>UOM</var><const type="string">EA</const></eq><not><var>IS_SUPERVISOR</var></not></and></condition><action><access mode="view">CONTAINSQUANTITY</access><access mode="hide">CONTAINEDREL/QUANTITY</access></action></constraint><constraint><name>Default</name><description>Default values (for ADD, for example): access for contains quantity is view and access for containedby quantity is modify.</description><condition><and><not><var>IS_SUPERVISOR</var></not></and></condition><action><access mode="view">CONTAINSREL/QUANTITY</access><access mode="modify">CONTAINEDREL/QUANTITY</access></action></constraint>

The following figure shows a pictorial representation of this example.

TIBCO Collaborative Information Manager Rulebase Guide

Page 67: Tib Cim Rulebaseguide

Access Modes | 53

Figure 1 Access modes based on UOM

Record Access

It is possible to completely hide a record from a user using “hide_record” access, or restrict a user’s edit access to a record by using “view_record”.

Take as example the following rulebase definition:

<rulebase metaversion="0.1"><!-- rulebase metaversion="0.1" --><name>rbrecordlistsecurity1</name><description>Rulebase to test view and hide record.</description><declare usage="local"><var>IS_SUPERVISOR</var></declare><constraint><name>IsSupervisor</name><description>User is supervisor if role contains Admin or Supervisor.</description><action><assign><var>IS_SUPERVISOR</var><or><in><const type="string">Work Supervisor</const><var>SESSION/USER_ROLES</var></in><in>

TIBCO Collaborative Information Manager Rulebase Guide

Page 68: Tib Cim Rulebaseguide

54 | Chapter 1 Getting Started with Rules

<const type="string">Admin</const><var>SESSION/USER_ROLES</var></in></or></assign></action></constraint><constraint><name>ViewRecordEACH</name><description>Make certain fields read only.</description><condition><and><eq><var>UOM</var><const type="string">EACH</const></eq><not><var>IS_SUPERVISOR</var></not></and></condition><action><access mode="view_record"/></action></constraint><constraint><name>HideRecordCASE</name><description>Make certain fields read only.</description><condition><and><eq><var>UOM</var><const type="string">CASE</const></eq><not><var>IS_SUPERVISOR</var></not></and></condition><action><access mode="hide_record"/></action></constraint></rulebase>

This rulebase sets the record access to “view only” if UOM is “EACH” and hides the record completely if UOM is “CASE”. Both rules are only active if the user is not a supervisor.

Restrictions on Record Access Conditions

For performance reasons, the <condition> of rules containing record level access actions are converted to SQL in some cases. This means only functions that are translatable into SQL can be used. These include:

TIBCO Collaborative Information Manager Rulebase Guide

Page 69: Tib Cim Rulebaseguide

Access Modes | 55

and, or, not, eq, neq, in, lt, leq, gt, geq, defined, undefined

Conditions containing expressions other than those listed above will fail.

Record Level Access and Composites

The child of a composite will take the most restrictive attribute based on its own and that of the root of the composite record. The exception to this is the “Record List” screen, which shows all child composites, unless they are explicitly hidden.

TIBCO Collaborative Information Manager Rulebase Guide

Page 70: Tib Cim Rulebaseguide

56 | Chapter 1 Getting Started with Rules

Global Property Settings for Rules

The TIBCO Collaborative Information Manager stores some system wide configuration parameters for rules in the ConfigValues.xml file. These properties are set using the Configurator.

LogFlagThis parameter produces rulebase execution logs in the $MQ_COMMON_DIR/Temp directory. It should be used for development or debugging only and should not be enabled in a production environment.

This parameter can be specified in System Debugging > RuleBase Debug Mode of the Configurator. Below is an example of how to set it to true so a detailed stack trace can be obtained for rule base execution.

Log files start with "rb" and end with ".xml". Several files can be produced in one go; browse to locate the right file.

Checking Attribute NamesSetting the Configurator > Miscellaneous > Check Attribute Names parameter to true halts the processing (throw an exception) if an attribute in the rulebase is not present in the repository.

If this parameter is set to false, an error is logged in error.log and a null value is returned for that attribute and normal processing continues.

This parameter is provided mainly for backward compatibility with previous versions. In past versions, attributes not found in the repository were ignored. Now, more stringent checking is present, which can cut down on "typo" type errors, but it also means a rulebase that references a deleted attribute will no longer work.

Table 5 Log Files

Prefix Description

rbb1*.xml First pass of rulebase. Computes propagations.

rbb2*.xml Propagations.

rbb3*.xml Second pass of rulebase. This is the file you need for debugging validations and assignments.

TIBCO Collaborative Information Manager Rulebase Guide

Page 71: Tib Cim Rulebaseguide

Global Property Settings for Rules | 57

The recommended approach is to set this flag to true in the system where you need to use the rulebase so that the system will alert you immediately if a rulebase contains an invalid attribute reference.

TIBCO Collaborative Information Manager Rulebase Guide

Page 72: Tib Cim Rulebaseguide

58 | Chapter 1 Getting Started with Rules

TIBCO Collaborative Information Manager Rulebase Guide

Page 73: Tib Cim Rulebaseguide

| 59

Chapter 2 Expressions

This chapter describes the Expression syntax.

Topics

• SQL Expressions, page 60

• Context Variables, page 69

TIBCO Collaborative Information Manager Rulebase Guide

Page 74: Tib Cim Rulebaseguide

60 | Chapter 2 Expressions

SQL Expressions

SQL expressions are used to access data in datasources and repositories. The result of these expressions can then be used in select functions, or even assigned to other variables.

Restrictions The following restrictions apply for the use of SQL expressions:

• The following logical expressions are supported: and, or, not, in, defined, undefined, like.

• The following operands are supported: eq, neq, leq, lt, geq, gt.

• You have to use a where clause if you have a table where source is sql.

• Multi-column results can only be used in select and slice actions. All other functions require a single column result (that is, a list of values).

• Built-in functions such as concat, count, and so on cannot be used within an SQL expression.

• The multi-value attribute can only be used in where clause and not supported in a select column list.

• Only supported operators for multi-value are eq, neq, in and like.

Locations of datasource and classificationsDatasources and classifications can be stored in the shared TibcoCim enterprise. Datasources and classifications stored here can be accessed by all other enterprises.

If the datasource exists in the current organization, it is used by the application. Otherwise, it is looked for in the global TibcoCim enterprise. If it cannot be found in either organization, the SQL expression throws an error.

tableAll SQL expressions start with the table tag. The table tag can be thought of as a function that returns a table of values.

TIBCO Collaborative Information Manager Rulebase Guide

Page 75: Tib Cim Rulebaseguide

SQL Expressions | 61

There are three forms of the table function that can be selected with the source attribute:

source="datasource"

source="datasource" data is assumed to come from a single datasource table. The first value is assumed to be the datasource name, and the following values are the column names in that datasource. For datasource tables the arguments are as follows:

The following example selects three columns from the COUNTRY3 datasource, and displays them in a drop-down menu.

<constraint><name>Country3</name><description>COUNTRY3 datasource.</description><usefor><var>COUNTRYOFORIGINCODE</var></usefor><action><select novalue="option"><table source="datasource"><literal>COUNTRY3</literal><literal>CODE</literal><literal>NAME</literal><literal>SCALE</literal></table></select></action></constraint>

The following example selects only specific language codes from the datasource.

<constraint>

source Description

datasource Optimized for datasource access

sql General SQL expression builder.

classification

Argument Default Value Description

1 Name of datasource.

2 First Column Name of database column.

3-n Second, Third, ... Column Name(s) of display columns.

TIBCO Collaborative Information Manager Rulebase Guide

Page 76: Tib Cim Rulebaseguide

62 | Chapter 2 Expressions

<name>Language2</name><description>LANGUAGE2 datasource with SQL query.</description><usefor><var>PRODUCTNAMELANG</var></usefor><action><select novalue="default"><table source="datasource"><literal>LANGUAGE2</literal><literal>CODE</literal><where><sql><or><eq><literal>CODE</literal><const type="string">EN</const></eq><eq><literal>CODE</literal><const type="string">ES</const></eq><eq><literal>CODE</literal><const type="string">DE</const></eq><eq><literal>CODE</literal><const type="string">FR</const></eq></or></sql></where></table></select></action></constraint>

source="sql"

For source="sql" tables, you have to declare the datasources, classifications and repositories to use. The columns in those repositories are then accessed with the "/" notation. For example, if you declare a repository called MC1, you can access its UOM MC1/UOM. Follow this procedure:

1. declare the datasource, classification and repositories in the expression.

2. List the columns to return as a result using table-name/column-name notation.

TIBCO Collaborative Information Manager Rulebase Guide

Page 77: Tib Cim Rulebaseguide

SQL Expressions | 63

3. Build the where clause.

The source of the SQL data is declared using the link mechanism, as used in relationship declarations. Valid link types are: datasource, classification and catalog. By restricting access to these entities, the system ensures that no unauthorized system table is accessed.

The following example declares the variable C3, which represents the datasource COUNTRY3. The available datasources can be viewed in the application using the Datasource menu.

<declare><var>C3</var><link type="datasource"><literal>COUNTRY3</literal></link></declare>

The following example declares a variable that points to a repository named MASTER3:

<declare><var>Master3</var><link type="catalog"><literal>MASTER3</literal></link></declare>

• An SQL expression is built in the background. The list of columns to be returned is the select portion, and the where tag is translated into the where clause of the SQL expression. The from portion of the SQL expression is built implicitly by the tables used in the expression. Currently, the where tag is mandatory.

• The table tag supports multi-value attributes in the where tag only. Supported operators are eq (or in) and neq.

link type Argument Description

datasource Datasource Name References a datasource. See, Locations of datasource and classifications, page 60.

classification Classification Scheme Currently references a Datasource with the same name as the Classification Scheme. Refer to, Locations of datasource and classifications, page 60.

catalog • Repository Name

• STATE/<input>

• References a repository.

• Specifies the state of the records to be selected. Legal values are CONFIRMED and UNCONFIRMED.

TIBCO Collaborative Information Manager Rulebase Guide

Page 78: Tib Cim Rulebaseguide

64 | Chapter 2 Expressions

The following example declares a variable that can be used to select the latest version of the records from Master3.

<declare><var>Master3</var><link type="catalog"><literal>MASTER3</literal><literal>STATE/UNCONFIRMED</literal></link></declare>

Selecting ColumnsTo select columns, combine the variable that points to the SQL source, and the column name. Use the literal tag. The literal tag is used rather than the <var> tag to point out the fact that we are referring to the column name, not it’s value.

The column name is the logical column name, meaning it is the same name that appears in the datasource and repository attribute screens. You do not need to know the actual column name in the database.

The following example, selects the Code from datasource COUNTRY3.

<literal>C3/CODE</literal>

The following example selects the UOM column from Master3.

<literal>Master3/UOM</literal>

whereThe where tag represents the where clause of a SQL expression. It has two parts: the text string representing the where clause, and any arguments substituted for placeholders.

The name of a variable can be the same or different from that of the repository. This allows for the possibility of self-joins and other options.

Argument Description

1 string representing where clause.

2-n Values to substitute in for expression placeholders:

<const type="string">?</const>

TIBCO Collaborative Information Manager Rulebase Guide

Page 79: Tib Cim Rulebaseguide

SQL Expressions | 65

The where clause is a string in the SQL expression. It is important that it is a string. You can enter in your own SQL expression directly, or use the sql function, as follows.

One difference between a table of source="datasource" and source="sql" is that for datasource the tablename is implied for all columns. In the following example, <literal>BUC</literal> is a column in the datasource RULE2. There is no need to declare the datasource explicitly.

<select novalue="no"><table source="datasource"><const type="string">RULE2</const><const type="string">BRANDCODE</const><const type="string">BRANDCODE</const><where type="SQL"><sql><eq><literal>BUC</literal><const type="string">?</const></eq></sql><var>BUC</var></where></table></select>

You can also present the previous example in the following way:

<select novalue="no"><table source="datasource"><const type="string">RULE2</const><const type="string">BRANDCODE</const><const type="string">BRANDCODE</const><where type="SQL"><const type="string">CBUC = '?'</const><var>BUC</var></where></table></select>

The advantage of using rulebase syntax is in not having to know exact column names. The general rule is that a column name is the same as the attribute, only prepended with C. This may not be the case for repository column names that have been renamed or deleted. Also, you can provide a column name for user-defined attributes. So it may not necessarily be the same as attribute name with "C" prepended.

PlaceholdersPlaceholders are the equivalent to the ? used in an SQL prepared statement. In the following example, the ? placeholder is replaced by the value of CLASSIFICATIONLEVEL1 .

TIBCO Collaborative Information Manager Rulebase Guide

Page 80: Tib Cim Rulebaseguide

66 | Chapter 2 Expressions

<constraint><name>ClassificationLevel2</name><description>Classification Level 2</description><usefor><var>CLASSIFICATIONLEVEL2</var></usefor><condition><defined><var>CLASSIFICATIONLEVEL1</var></defined></condition><action><select novalue="no"><table source="datasource"><literal>CATEGORY</literal><literal>CAT2</literal><literal>CAT2DESC</literal><where><sql><eq><literal>CAT1</literal><const type="string">?</const></eq></sql><var>CLASSIFICATIONLEVEL1</var></where></table></select></action></constraint>

sql FunctionThe sql function takes a rulebase expression and returns the equivalent SQL string. When using sql, you do not have to know the database table and column names, which are not the same as the names appearing in the application.

For example, the repository records could be stored in a table called MCT_12334. Even then, the table name changes in different installations (development, staging, production). The sql function makes sure that the correct table is always accessed.

There are some restrictions on which rulebase functions are translated into SQL equivalents. The following is an example of a join between two datasources:

<declare>

Argument Description

1-n rulebase expressions. One of:

and, or, not, eq, neq, geq, gt, leq, lt, like, defined, undefined.

TIBCO Collaborative Information Manager Rulebase Guide

Page 81: Tib Cim Rulebaseguide

SQL Expressions | 67

<var>C3</var><link type="datasource"><literal>COUNTRY3</literal></link></declare><declare><var>S2</var><link type="datasource"><literal>SCALE</literal></link></declare><constraint><name>Scale</name><description>Do a datasource join</description><usefor><var>HI</var></usefor><action><select novalue="option"><table source="sql"><literal>S2/SCALE</literal><literal>S2/SCALE</literal><literal>C3/CODE</literal><literal>C3/NAME</literal><literal>S2/DESCRIPTION</literal><where><sql><eq><literal>C3/SCALE</literal><literal>S2/SCALE</literal></eq></sql></where></table></select></action></constraint>

The following is an example using a repository:

<declare><var>Master3</var><link type="catalog"><literal>MASTER3</literal></link></declare><constraint><name>PRICETYPE</name><description>Select possible PriceTypes from Master3 where UOM is PACK</description><usefor><var>PRICETYPE</var></usefor><action><select><table source="sql"><literal>MASTER3/PRICEUOMCODE</literal>

TIBCO Collaborative Information Manager Rulebase Guide

Page 82: Tib Cim Rulebaseguide

68 | Chapter 2 Expressions

<where><sql><eq><literal>MASTER3/UOM</literal><const type="string">PACK</const></eq></sql></where></table></select></action></constraint>

Debugging StatementsWhen debugging SQL statements, look in elink.log for the following string:"execStatement:" and "execStatement:sql"

SQL generated by your expression is executed here.

Null Values

No special provisions are made for null values in the input values. Check if inputs to SQL can have null values in the condition, and do not execute the SQL if null values are not provided for.

For a multi-value attribute, eq/like/in would return the result if any of the value matches with the specified value. For example, when a COLOR attribute has RED, YELLOW, BLUE, the following expression would return true.

<eq><literal>COLOR</literal><const type="string">RED</const></eq>

TIBCO Collaborative Information Manager Rulebase Guide

Page 83: Tib Cim Rulebaseguide

Context Variables | 69

Context Variables

The followings special variables can be used in a rulebase:

• SESSION, page 69

• WORKITEM, page 70

• PREVIOUS_VERSION, PREVIOUS_CONFIRMED_VERSION, page 71

• RECORD_ACTION, page 73

• RECORD_SUB_ACTION, page 75

• RECORD_IS_TOPMOST, page 76

• RECORD_IS_BOTTOMMOST, page 76

• PARENT, page 77

• CHILD, page 78

SESSIONThe following table lists session variables that can be used without explicit declaration.

Variable Type Value

SESSION/DATE date Current date and time.

SESSION/USER_ID string User ID of current user.

SESSION/USER_ROLES array Roles this user belongs to.

SESSION/ORGANIZATION_NAME string Organization Name.

SESSION/ORGANIZATION_TYPE string Organization type.

SESSION/ENTERPRISE_NAME string Enterprise Name.

SESSION/ENTERPRISE_INTERNAL_NAME string Enterprise Internal Name.

TIBCO Collaborative Information Manager Rulebase Guide

Page 84: Tib Cim Rulebaseguide

70 | Chapter 2 Expressions

The following example shows an access rule which restricts access to the attribute “SENSITIVE_ATTRIBUTE” only to Admin users. Notice that “in” has to be used, because a user can belong to more than 1 role, and USER_ROLES therefore returns an array of values.

<constraint><name>HideSensitiveAttribute</name><description>Only Admin Role can see Sensitive Attribute</description><condition><in><const type="string">Admin</const><var>SESSION/USER_ROLES</var></in></condition><action><access mode="modify">SENSITIVE_ATTRIBUTE</access></action><action><access mode="hide">SENSITIVE_ATTRIBUTE</access></action></constraint>

WORKITEMEach step in the workflow has dependent criteria, and requires specific variables to be defined. The following table lists variables, their types, and values.

Variable Type Value

WORKITEM/ACTIVITY_NAME string Name of current activity.

WORKITEM/SEVERITY number Workitem Severity.

WORKITEM/STEP_SEVERITY number Workitem Step Severity.

WORKITEM/DOCTYPE string Document Type that created workitem.

WORKITEM/DOCSUBTYPE string Document Sub-Type that created workitem.

WORKITEM/ERRORS number Number of errors in the record bundle.

WORKITEM/WARNINGS number Number of warnings in the record bundle.

TIBCO Collaborative Information Manager Rulebase Guide

Page 85: Tib Cim Rulebaseguide

Context Variables | 71

PREVIOUS_VERSION, PREVIOUS_CONFIRMED_VERSIONYou can access previous unconfirmed and confirmed versions of the records with two explicitly defined contexts. The following table lists these contexts.

WORKITEM/REJECTIONS number Number of rejections in the record bundle.

WORKITEM/TRADING_PARTNER string Trading Partner Name.

WORKITEM/TRADING_PARTNER_TYPE string Trading Partner Organization Type.

WORKITEM/MARKETPLACE_NAME string Marketplace name.

WORKITEM/MASTER_CATALOG_NAME string Name of the repository of the record being processed.

WORKITEM/MASTER_CATALOG_VERSION

Number Repository Version.

WORKITEM/INTENT String Intent passed in to WorkItem activity.

WORKITEM/RECORD_COUNT Number Total number of records in the bundle.

WORKITEM/SUCCESS_COUNT Number Number of records with no errors.

Custom* String Any Parameter starting with “Custom” that is passed to Workitem Activity.

Variable Type Value

Context Description

PREVIOUS_VERSION Latest confirmed or unconfirmed version.

PREVIOUS_CONFIRMED_VERSION

Last confirmed version.

TIBCO Collaborative Information Manager Rulebase Guide

Page 86: Tib Cim Rulebaseguide

72 | Chapter 2 Expressions

The following example shows how to access the weight attribute value of the last confirmed version:

<var>PREVIOUS_CONFIRMED_VERSION/WEIGHT</var>

CONTEXT_RELATIONSHIP/NAMEWhile adding a new record and executing the “newrecord” rulebase, the CONTEXT_RELATIONSHIP variable contains the name of a relationship if the record is added by selecting the “add” action and then the relationship name on an existing record.

For example, if you are keeping a Vendor repository which has a relationship for multiple addresses, then you can automatically set the “RECORD_TYPE” to address if the user is adding a new address relationship.

<constraint><name>Vendor_Record_Type</name><condition><undefined><var>CONTEXT_RELATIONSHIP/NAME</var></undefined></condition><action><assign><var>RECORD_TYPE</var><const type="string">VENDOR</const></assign></action></constraint><constraint><name>Address_Record_Type</name><condition><eq><var>CONTEXT_RELATIONSHIP/NAME</var><const type="string">ADDRESS_REL</const></eq></condition><action><assign><var>RECORD_TYPE</var><const type="string">ADDRESS</const></assign></action></constraint>

The following is another example of assigning the RECORD_TYPE based on the Context Relationship.

<constraint><name>PRODUCT</name><condition><undefined><var>CONTEXT_RELATIONSHIP/NAME</var>

TIBCO Collaborative Information Manager Rulebase Guide

Page 87: Tib Cim Rulebaseguide

Context Variables | 73

</undefined></condition><action><assign><var>RECORD_TYPE</var><const type="string">PRODUCT</const></assign></action></constraint><constraint><name>SKU</name><condition><eq><var>CONTEXT_RELATIONSHIP/NAME</var><const type="string">PRODUCT_TO_SKU_REL</const></eq></condition><action><assign><var>RECORD_TYPE</var><const type="string">SKU</const></assign></action></constraint>

RECORD_ACTIONPossible values:

RECORD_ACTION Escaped Version

ADD New record is being added.

EDIT Existing record is being edited.

COPY New Record is being copied from another record.

VIEW Record is being viewed.

MASS_UPDATE Executes a constraint only when the mass update is in process, that is, the same validation file can be used for record edit and mass update.

Refer to, mass_update, page 74.

RECORD_SEARCH The record search is being executed. If a constraint is defined with this action, the same catalog validation file can be used for record search screen if the property com.tibco.cim.recordsearch.rulesfile is configured with catalog validation file name.

TIBCO Collaborative Information Manager Rulebase Guide

Page 88: Tib Cim Rulebaseguide

74 | Chapter 2 Expressions

The following example restricts view access to the BASE_UNIT, ITEM_BRAND_NAME , and BRAND_OWNER_ID attributes, if the record is being viewed or edited:

<constraint><name>ViewOnlyGeneralAttributesForViewAndChange</name><description>View only attributes for View and Change</description><condition><or><eq><var>RECORD_ACTION</var><const type="string">EDIT</const></eq><eq><var>RECORD_ACTION</var><const type="string">VIEW</const></eq></or></condition><action><access mode="view">BASE_UNIT</access><access mode="view">ITEM_BRAND_NAME</access><access mode="view">BRAND_OWNER_ID</access></action></constraint>

mass_update

This value allows you to execute a constraint only when the mass update is in process, that is, the same validation file can be used for record edit and mass update.

The RecordAction filter can be used for mass update as shown in the following example:

<constraint><name>Check-int</name><description>Check-int</description><usefor><var>TEST_INT</var></usefor><condition><eq><var>RECORD_ACTION</var><const type="string">MASS_UPDATE</const></eq></condition><action><check><explanation>TEST_INT should only be 1</explanation><and><defined><var>TEST_INT</var></defined><eq>

TIBCO Collaborative Information Manager Rulebase Guide

Page 89: Tib Cim Rulebaseguide

Context Variables | 75

<var/><const type="number">1</const></eq></and></check></action></constraint>

record_search

The following is an example of a constraint to be used when RECORD_ACTION=RECORD_SEARCH is used:<constraint><name>TestSQLIN</name><description>Test Get with SQL query using IN</description>

<usefor> <var>Installments</var></usefor>

<condition> <eq> <var>RECORD_ACTION</var> <const type="string">RECORD_SEARCH</const> </eq></condition> <action> <select> <table source="datasource"> <literal>CUSTDS1</literal> <literal>INSTALLMENT</literal> <where> <sql> <in> <literal>INSTALLMENT</literal> <const type="number">34000</const> <const type="number">23000</const> </in> </sql> </where> </table> </select> </action></constraint>

RECORD_SUB_ACTIONCurrently, the only possible value that can be assigned to this variable is RESTORE.

TIBCO Collaborative Information Manager Rulebase Guide

Page 90: Tib Cim Rulebaseguide

76 | Chapter 2 Expressions

When a record is restored, for all UI based rulebase validations for restored record, RECORD_SUB_ACTION is set to RESTORE.

RECORD_IS_TOPMOST This variable allows you to check whether the record is the topmost in the hierarchy.

Example

<constraint><name>Test for parent</name><description>To Check if this is the parent</description><usefor><var>SHORTDESC</var></usefor><condition><and><eq><var>RECORD_TYPE</var><const type="string">CUST</const></eq><var>RECORD_IS_TOPMOST</var></and></condition><action><assign><var>SHORTDESC</var><const type="string">Parent Record</const></assign></action></constraint>

RECORD_IS_BOTTOMMOSTThis variable allows to check whether the record is bottommost in the hierarchy.

Example

<constraint><name>Test for child/leaf node</name><description>To Check if this is the leaf node in a hierarchy of records</description><usefor><var>SHORTDESC</var></usefor>

RECORD_SUB_ACTION is bound to RESTORE only for UI based validations and not during workflow processing.

TIBCO Collaborative Information Manager Rulebase Guide

Page 91: Tib Cim Rulebaseguide

Context Variables | 77

<condition><and><eq><var>RECORD_TYPE</var><const type="string">CUST</const></eq><var>RECORD_IS_BOTTOMMOST</var></and></condition><action><assign><var>SHORTDESC</var><const type="string">Child Record</const></assign></action></constraint>

PARENTThis variable allows to access attribute values of a parent record during relationship catalog rulebase execution.

Example

<constraint><name>checkForAssetType</name><description>To Check if asset type is defined</description><usefor><var>ASSET_TYPE</var></usefor><condition><defined><var>PARENT/HAS_ASSETS</var></defined></condition><action><check><explanation>Asset type should be defined.</explanation><defined><var>ASSET_TYPE</var></defined></check></action></constraint>

This context variable is only available in relationship catalog rulebase execution. The parent/child record is always determined in context of forward relationship.

TIBCO Collaborative Information Manager Rulebase Guide

Page 92: Tib Cim Rulebaseguide

78 | Chapter 2 Expressions

CHILDThis variable allows to access attribute values of child record during relationship catalog rulebase execution.

Example

<constraint><name>checkForRegion</name><description>To Check if region is defined</description><usefor><var>REGION</var></usefor><condition><defined><var>CHILD/ZIPCODE</var></defined></condition><action><check><explanation>REGION type should be defined.</explanation><defined><var>REGION</var></defined></check></action></constraint>

This context variable is only available in relationship catalog rulebase execution. The parent/child record is always determined in context of forward relationship.

TIBCO Collaborative Information Manager Rulebase Guide

Page 93: Tib Cim Rulebaseguide

| 79

Chapter 3 Operator and Character Reference

This chapter details the operators and regular expressions.

Topics

• Overview of Operators, page 80

• Logical Operators, page 83

• Syntax for Expressions, page 116

• Regular Expressions, page 118

• Built-in Functions, page 122

• Custom Functions, page 123

TIBCO Collaborative Information Manager Rulebase Guide

Page 94: Tib Cim Rulebaseguide

80 | Chapter 3 Operator and Character Reference

Overview of Operators

This section provides detailed information for rulebase operators, and is organized alphabetically by operator name.

Logical

Comparison

and — page 83

not — page 95

or — page 85

changed — page 87

defined — page 107

eq — page 108

geq — page 90

gt — page 90

in — page 90

leq — page 91

lt — page 91

match — page 112

neq — page 95

undefined — page 93

TIBCO Collaborative Information Manager Rulebase Guide

Page 95: Tib Cim Rulebaseguide

Overview of Operators | 81

String

Math

Other

concat— page 94

length — page 94

pad — page 95

substring — page 113

trim — page 114

uppercase — page 114

div — page 108

minus — page 112

mult — page 100

percent — page 101

plus — page 102

round — page 103

checkdigit — page 106

count — page 107

distinct — page 107

TIBCO Collaborative Information Manager Rulebase Guide

Page 96: Tib Cim Rulebaseguide

82 | Chapter 3 Operator and Character Reference

This chapter also includes references for the following characters:

• Literal Characters

• Character Classes

• Position Characters

filter — page 108

lookup — page 109

like — page 110

max — page 112

min — page 110

sequence — page 112

strip — page 113

synchstatus — page 113

SyncOperationAttribute — page 114

validate_checkdigit — page 114

TIBCO Collaborative Information Manager Rulebase Guide

Page 97: Tib Cim Rulebaseguide

Logical Operators | 83

Logical Operators

and — compute logical andSynopsis: <and>

Arguments: 1 or more boolean expressions.

— TRUE — if all arguments are true.

— FALSE — if any argument is false.

— Null — if any argument is null.

By default, and stops evaluating new arguments when the current value is FALSE or null. To optimize execution time, place expressions based on single attributes first in the condition, and expressions involving complicated relationship traversals or database accesses last. In that way, if the first condition is FALSE the system does not evaluate subsequent expressions.

Truth Tables for AND (&):

Argument 1 Argument 2 Result

F F F

F T F

T F F

T T T

Null T or F or Null Null

Scalar:

Argument1 B1,1

Argument2 B2,1

Result B1,1 & B2,1

Scalar and Array

Argument1 B1,1

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

TIBCO Collaborative Information Manager Rulebase Guide

Page 98: Tib Cim Rulebaseguide

84 | Chapter 3 Operator and Character Reference

If m is not equal to n, an error is generated. Each null value generates one null entry. If only one argument is given, all entries in the array are combined (‘anded’ together).

Optimization

Arguments into and are evaluated on a need basis when the expression is evaluated. As an optimization, the rulebase engine stops evaluating arguments when the current result is either FALSE or null. This is an efficient way of bypassing arguments that affect the result. For example, if the UOM is CASE and you want to look at all Products in the Contains relationship to make sure that they are of type EACH. This expression might be as follows:

<and><eq><var>UOM</var><const type="string">CASE</const></eq><eq><var>CONTAINS_RELATIONSHIP/UOM</var><const type="string">EACH</const></eq></and>

Traversing the Contains relationship to get the UOM of the Contained product(s) should be avoided if possible. Therefore, if UOM of the parent product is not CASE, the engine stops evaluating the expression before it starts fetching all the records pointed at by the Contains relationship.

Arrays are considered one argument - as a result, individual array entries are not optimized.

Result [B1,1 & B2,1 , B1,1 & B2,2 , B1,1 & B2,3 ... B1,1 & B2,n]

Array and Array

Argument1 [B1,1 , B1,2 , B1,3 ... B1,m]

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 & B2,1 , B1,2 & B2,2 , B1,3 & B2,3 ... B1,m & B2,n]

1 Argument

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Result B1,1 & B1,2 & B1,3 ... & B1,n

Scalar:

TIBCO Collaborative Information Manager Rulebase Guide

Page 99: Tib Cim Rulebaseguide

Logical Operators | 85

not — compute logical notSynopsis: <not>

Arguments: 1 boolean expression.

Returns:

TRUE — if argument is FALSE.

FALSE — if argument is TRUE.

null — if argument is NULL.

or — compute logical orSynopsis: <or>

Arguments: 2 or more boolean expressions.

Returns:

TRUE — if any argument is true.

FALSE — if all arguments are false.

Null — if any argument is Null.

By default, ‘or’ stops evaluating new arguments when the current value is TRUE or null. To optimize execution time, put expressions based on single attributes first in the condition, and expressions involving complicated relationship traversals or database accesses last. In that way, if the first condition is FALSE, the system does not evaluate subsequent expressions. For more information, see “Optimization” on page 82.

Truth Tables for | :

Argument 1 Argument 2 Result

F F F

F T T

T T T

T T T

Null T or F or Null Null

TIBCO Collaborative Information Manager Rulebase Guide

Page 100: Tib Cim Rulebaseguide

86 | Chapter 3 Operator and Character Reference

If m is not equal to n, an error is generated. Each null value generates one null entry. If only one argument is given, all the entries in the array are combined ("anded" together).

Scalar

Argument1 B1,1

Argument2 B2,1

Result B1,1 | B2,1

Scalar and Array

Argument1 B1,1

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 \/ B2,1 , B1,1 \/ B2,2 , B1,1 \/ B2,3 ... B1,1 \/ B2,n]

Array and Array

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 \/ B2,1 , B1,2 \/ B2,2 , B1,3 \/ B2,3 ... B1,m \/ B2,n]

1 Argument

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Result B1,1 \/ B1,2 \/ B1,3 ... \/ B1,n

As an optimization, or stops evaluating arguments when it encounters the first TRUE or null value.

TIBCO Collaborative Information Manager Rulebase Guide

Page 101: Tib Cim Rulebaseguide

Comparison Operators | 87

Comparison Operators

changed — test an attribute to see if it has changedSynopsis: <changed>

Arguments: 1 — var, see table, 2 — flag.

Returns:

TRUE — if attribute value has changed from its previous version.

FALSE — if attribute value has not changed.

Description:

Check if SHORTDESC has changed since the previous confirmed version:

<condition><changed>

<var>SHORTDESC</var><const type="string">PREVIOUS_CONFIRMED_VERSION</const>

</changed></condition>

For multi-value attribute, it returns true if the previous set of values is different from the current values:

<constraint><name>TestChanged</name><description>test changed</description><condition><changed><var>Installments</var><const type="string"> PREVIOUS_CONFIRMED_VERSION</const></changed></condition><action><assign>

Arguments Keyword

1 Variable

2 Keyword:

PREVIOUS_CONFIRMED_VERSION

PREVIOUS_VERSION (default)

TIBCO Collaborative Information Manager Rulebase Guide

Page 102: Tib Cim Rulebaseguide

88 | Chapter 3 Operator and Character Reference

<var>AmtPaid</var><const type="number">12000</const></assign></action></constraint>

defined — determine if value is definedSynopsis: <defined>

Arguments: 1 <var> tag.

Returns:

TRUE — if <var> has a non-null, non-empty value.

FALSE — if otherwise (see undefined on page 93).

Description:<defined>

<var>SIZE_UOM</var>

</defined>

Returns true if SIZE_UOM attribute is defined.

eq — equalsSynopsis: <eq> or <eq scalarMatching=false>

Arguments: 2 expressions.

Note: When checking for a multi-value attribute, you must pass the scalarMatching=false as follows:

<constraint><name>TestEq</name><description>test</description><condition>

<and><defined>

<var>MTEST</var></defined><eq scalarMatching="false"><!-NEW flag scalarMatching '

<var>MTEST</var><var>TEMP</var>

</eq></and>

</condition><action>

<access mode="hide">SHORTDESC</access>

TIBCO Collaborative Information Manager Rulebase Guide

Page 103: Tib Cim Rulebaseguide

Comparison Operators | 89

</action>

</constraint>

Returns:

Argument 1 Argument 2 Result

String1 String2 Case insensitive compare of String1 and String2

Number1 Number2 Number1 = Number2

Boolean1 Boolean2 Boolean1 = Boolean2

Date1 Date2 Date1 = Date2

Null Any of the above Null

Null Null Null

Scalar

Argument1 B1,1

Argument2 B2,1

Result B1,1 = B2,1

Scalar and Array

Argument1 B1,1

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 = B2,1 , B1,1 = B2,2 , B1,1 = B2,3 ... B1,1 = B2,n]

Array and Array

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 = B2,1 , B1,2 = B2,2 , B1,3 = B2,3 ... B1,m = B2,n]

Result(scalarMatching=true)

[B1,1 , B1,2 , B1,3 ... B1,n] = [B2,1 , B2,2 , B2,3 ... B2,n]

TIBCO Collaborative Information Manager Rulebase Guide

Page 104: Tib Cim Rulebaseguide

90 | Chapter 3 Operator and Character Reference

geq — greater than or equalSynopsis: <geq>

Arguments: 2 expressions.

Returns:

TRUE — if first argument is >= second argument.

FALSE — if first argument is < second argument.

For array behavior, see, filter — filter a list of records, page 108.

gt — greater thanSynopsis: <gt>

Arguments: 2 expressions.

For array behavior, see, filter — filter a list of records, page 108.

Returns:

TRUE — if first argument is > second argument.

FALSE — if first argument is < second argument.

in — check if argument contained in a listSynopsis: <in>

Arguments: 1 — variable to check; 2 — list of n value.

1 Argument

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Result B1,1 = B1,2 = B1,3 ... = B1,n

If m is not equal to n, an error is generated. Each null value generates one null entry.

Scalar

TIBCO Collaborative Information Manager Rulebase Guide

Page 105: Tib Cim Rulebaseguide

Comparison Operators | 91

Returns:

TRUE — if arg1 in (arg2, arg3, ...,argn).

FALSE — if otherwise.

Description:

Equivalent to: (arg1 == arg2)||(arg1 == arg3)||...||(arg1 == argn)

leq — less than or equalSynopsis: <leq>

Arguments: 2 expressions.

Returns:

TRUE — if first argument is <= second argument.

FALSE — if first argument is > second argument.

For array behavior, see, filter — filter a list of records, page 108.

lt — less thanSynopsis: <lt>

Arguments: 2 expressions.

Returns:

TRUE — if first argument is < second argument.

FALSE — if first argument is >= second argument.

For array behavior, see , filter — filter a list of records, page 108.

match — regular expression matchSynopsis: <match>

Arguments: 1 — variable to match; 2 — regular expression.

For information on regular expression syntax, see, Regular Expressions, page 118.

TIBCO Collaborative Information Manager Rulebase Guide

Page 106: Tib Cim Rulebaseguide

92 | Chapter 3 Operator and Character Reference

Example:

<check><explanation lang="en">GTIN has to be 14 numeric characters.</explanation><match><var/><const type="string">/^\d{14}$/</const></match></check>

<check><explanation>Has to be a non-negative number.</explanation><match><var/><const type="string">/^((\d+(\.\d*)?)|(\d*\.\d+))$/</const></match></check>

Returns:

TRUE — if argument 1 matches regular expression argument 2.

FALSE — if first argument does not match second argument.

neq — not equalSynopsis: <neq>

Arguments: 2 expressions.

Note: When checking for a multi-value attribute, you must pass the scalarMatching=false as follows:

<constraint><name>TestEq</name><description>test</description><condition>

<and><defined>

<var>MTEST</var></defined><neq scalarMatching="false"><!-NEW flag scalarMatching '

<var>MTEST</var><var>TEMP</var>

</neq></and>

</condition><action>

<access mode="hide">SHORTDESC</access></action>

</constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 107: Tib Cim Rulebaseguide

Comparison Operators | 93

Returns:

TRUE — if first argument is not equal to second argument.

FALSE — if first argument is equal to second argument.

For information on array behavior, see , filter — filter a list of records, page 108.

undefined — determine if value is undefinedSynopsis: <undefined>

Arguments: 1 <var> tag.

Returns:

TRUE — if the <var> is null or empty.

FALSE — if otherwise (see defined on page 107).

TIBCO Collaborative Information Manager Rulebase Guide

Page 108: Tib Cim Rulebaseguide

94 | Chapter 3 Operator and Character Reference

String Operators

concat — concatenate string valuesSynopsis: <op func="concat">

Arguments: 1 to n — string expressions.

Returns:

String, which is the concatenation of all input strings.

Description:

Concatenates two or more strings.

<assign><var>SEQ</var><op func="concat"><const type="string">PREFIX-</const><op func="pad"><var>PRODUCT_NUMBER</var><const type="number">9</const><const type="string">0</const></op><const type="string">-SUFFIX</const></op></assign>

Constructs a string from a prefix, product number, and suffix.

length — compute length of stringSynopsis: <op func="length">

Arguments: 1 — string expression.

Returns:

Returns the length of the specified string.

Description:

<op func="length"> <const type="string">ABCDEF</const> </op>

TIBCO Collaborative Information Manager Rulebase Guide

Page 109: Tib Cim Rulebaseguide

String Operators | 95

This example would return a value of 6.

pad — pads a string on left or rightSynopsis: The option determines whether we pad to the left or right.Any null argument returns a null expression.<op func="pad"> <op func="pad" option="left"><op func="pad" option="right">

Arguments :

Returns:

The option="left"

Any null argument returns a null expression.

Example:

<assign><var>PADABC</var><op func="pad" option="right"><var>ABC</var><const type="number">6</const><const type="string">0</const>

Argument Use Type Comment

1 string to pad string or

array of strings

If array, pad each string in array.

2 final length of padded string

number The final length will be max of (original length, final length). That is, the string will never shrink.

3 character to pad with string Optional.

If omitted, pad with spaces.

String Length Character Result

ABC 1 * ABC

ABC 5 ** **ABC

ABC null null

TIBCO Collaborative Information Manager Rulebase Guide

Page 110: Tib Cim Rulebaseguide

96 | Chapter 3 Operator and Character Reference

</op></assign>

substringSynopsis: <op func="substring">

Arguments:

Returns:

Any null argument returns a null expression.

Description:

Returns a new string that is a substring of this string.

<op func="substring"> <const type="string">ABCDEF</const> <const type="number">0</const> <const type="number">3</const> </op>

Argument Use Type Comment

1 string to subset string or

array of strings

If array, compute substring for each string in array.

2 start position number 0 is first position.

If less than 0, set to start of string.

3 number of characters number Optional.

If omitted, return until end of string.

String Start Length Result

ABCDEF 1 2 BC

ABCDEF 4 EF

ABCDEF null null

TIBCO Collaborative Information Manager Rulebase Guide

Page 111: Tib Cim Rulebaseguide

String Operators | 97

This example will return string as "ABC".

trim — trims leading and trailing spacesSynopsis: <op func="trim">

Arguments: 1 — string expression.

Returns:

String with leading and trailing spaces removed.

Description:

<op func="trim"> <const type="string"> ABCDEF </const> </op>

This example returns a value of "ABCDEF".

uppercase — returns uppercase of inputSynopsis: <op func="uppercase">

Arguments: 1 — string expression.

Returns:

String with all characters converted to uppercase equivalent.

Description:

<op func="uppercase"> <const type="string">aBc</const> </op>

This would return a string "ABC".

TIBCO Collaborative Information Manager Rulebase Guide

Page 112: Tib Cim Rulebaseguide

98 | Chapter 3 Operator and Character Reference

Math Operators

div — divides valuesSynopsis:<op func="div"><op func="div" round="<n>"> <!-- n is the number of decimal places

the result should round to -->

Arguments: 1...n — numeric expressions.

Returns:

Calculated numerical — Arg1 / Arg2 / Arg3 / ... Argn

Division by 0 returns null.

By default results are rounded to 8 decimal places.

Scalar

Argument1 B1,1

Argument2 B2,1

Result B1,1 / B2,1

Scalar and Array

Argument1 B1,1

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 / B2,1 , B1,1 / B2,2 , B1,1 / B2,3 ... B1,1 / B2,n]

Array and Array

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 / B2,1 , B1,2 / B2,2 , B1,3 / B2,3 ... B1,m / B2,n]

1 Argument

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Result B1,1 / B1,2 / B1,3 ... / B1,n

TIBCO Collaborative Information Manager Rulebase Guide

Page 113: Tib Cim Rulebaseguide

Math Operators | 99

Description:

<op func="div"> <const type="number">10</const> <const type="number">2</const> </op>

<op func="div" round="4"> <const type="number">1</const> <const type="number">3</const> </op>

minus — calculates subtraction of valuesSynopsis:<op func="minus"> <op func="minus" round="4"> <!-- Round the result by 4 decimal

places -->

Arguments: 1...n — numeric expressions.

Returns:

Calculated numerical — Arg1 - Arg2 - Arg3 - ... Argn

Scalar

Argument1 B1,1

Argument2 B2,1

Result B1,1 - B2,1

Scalar and Array

Argument1 B1,1

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 - B2,1 , B1,1 - B2,2 , B1,1 - B2,3 ... B1,1 - B2,n]

Array and Array

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 - B2,1 , B1,2 - B2,2 , B1,3 - B2,3 ... B1,m - B2,n]

1 Argument

TIBCO Collaborative Information Manager Rulebase Guide

Page 114: Tib Cim Rulebaseguide

100 | Chapter 3 Operator and Character Reference

Description:

Example of operator minus on numbers:

<op func="minus"> <const type="number">10</const> <const type="number">2</const> </op>

Example of operator minus on dates:

<op func="minus"><var>SESSION/DATE</var><var>OPERATION_DATE</var></op>

mult — multiplies valuesSynopsis: <op func="mult">

Arguments: 1...n — numeric expressions.

Returns:Calculated numerical — Arg1 * Arg2 * Arg3 * ... Argn

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Result B1,1 - B1,2 - B1,3 ... - B1,n

Date Argument

Date 1 D1

Date 2 D2

Result D1 - D2 : returns the difference in seconds.

Scalar

Scalar

Argument1 B1,1

Argument2 B2,1

Result B1,1 * B2,1

Scalar and Array

TIBCO Collaborative Information Manager Rulebase Guide

Page 115: Tib Cim Rulebaseguide

Math Operators | 101

Description:

<op func="mult"> <const type="number">10</const> <const type="number">2</const> </op>

percent — computes percentageSynopsis:<op func="percent"><op func="percent" round="<n>"> <!-- replace n with the actual

number to use for rounding -->

Arguments: 1...n — numeric expressions.

Returns:

Calculated numerical — (Arg2 - Arg1) / Arg1

Division by 0 returns null.

By default results are rounded to 8 decimal places.

Argument1 B1,1

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 * B2,1 , B1,1 * B2,2 , B1,1 * B2,3 ... B1,1 * B2,n]

Array and Array

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 * B2,1 , B1,2 * B2,2 , B1,3 * B2,3 ... B1,m * B2,n]

1 Argument

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Result B1,1 * B1,2 * B1,3 ... * B1,n

Scalar

Scalar

Argument1 B1,1

TIBCO Collaborative Information Manager Rulebase Guide

Page 116: Tib Cim Rulebaseguide

102 | Chapter 3 Operator and Character Reference

Description:

<op func="percent"> <const type="number">10</const> <const type="number">2</const> </op>

<op func="percent" round="4"> <const type="number">1</const> <const type="number">3</const> </op>

plus — calculates addition of valuesSynopsis: <op func="plus"><op func="plus" round="<n>"> <!-- n is the number of decimal places

to round to -->

Arguments: 1...n — numeric expressions.

Argument2 B2,1

Result B1,1 % B2,1

Scalar and Array

Argument1 B1,1

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 % B2,1 , B1,1 % B2,2 , B1,1 % B2,3 ... B1,1 % B2,n]

Array and Array

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 % B2,1 , B1,2 % B2,2 , B1,3 % B2,3 ... B1,m % B2,n]

1 Argument

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Result B1,1 % B1,2 % B1,3 ... % B1,n

Scalar

TIBCO Collaborative Information Manager Rulebase Guide

Page 117: Tib Cim Rulebaseguide

Math Operators | 103

Returns:

Calculated numerical — Arg1 + Arg2 + Arg3 +... Argn

Description:

<op func="plus"> <const type="number">10</const> <const type="number">2</const> </op>

round — rounds to a defined set of decimal placesSynopsis: <op func="round">

Scalar

Argument1 B1,1

Argument2 B2,1

Result B1,1 + B2,1

Scalar and Array

Argument1 B1,1

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 + B2,1 , B1,1 + B2,2 , B1,1 + B2,3 ... B1,1 + B2,n]

Array and Array

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Argument2 [B2,1 , B2,2 , B2,3 ... B2,n]

Result [B1,1 + B2,1 , B1,2 + B2,2 , B1,3 + B2,3 ... B1,m + B2,n]

1 Argument

Argument1 [B1,1 , B1,2 , B1,3 ... B1,n]

Result B1,1 + B1,2 + B1,3 ... + B1,n

TIBCO Collaborative Information Manager Rulebase Guide

Page 118: Tib Cim Rulebaseguide

104 | Chapter 3 Operator and Character Reference

Arguments:

The rounding methods available are as follows (they are available from java.math.BigDecimal class):

Argument Use Type Comment

1 number(s) to round number or array of numbers

if array, then round each entry in the array.

2 number of decimal places to round to

number optional.

Default to 0.

3 rounding method. String optional.

Default is HALF_UP. See description below.

Rounding Method Comment

CEILING Rounding mode to round towards positive infinity. If the BigDecimal is positive, behaves as for ROUND_UP; if negative, behaves as for ROUND_DOWN. Note that this rounding mode never decreases the calculated value.

DOWN Rounding mode to round towards zero. Never increments the digit prior to a discarded fraction (i.e., truncates). Note that this rounding mode never increases the magnitude of the calculated value.

FLOOR Rounding mode to round towards negative infinity. If the BigDecimal is positive, behave as for ROUND_DOWN; if negative, behave as for ROUND_UP. Note that this rounding mode never increases the calculated value.

HALF_DOWN Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. Behaves as for ROUND_UP if the discarded fraction is > .5; otherwise, behaves as for ROUND_DOWN.

TIBCO Collaborative Information Manager Rulebase Guide

Page 119: Tib Cim Rulebaseguide

Math Operators | 105

Returns:

Numbers rounded to appropriate number of decimal places.

Description:<assign><var>RES20</var><op func="round"><var>NUM13</var><const type="number">2</const><const type="string">HALF_UP</const></op></assign>

HALF_EVEN Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. Behaves as for ROUND_HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for ROUND_HALF_DOWN if it's even. Note that this is the rounding mode that minimizes cumulative error when applied repeatedly over a sequence of calculations.

HALF_UP Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. Behaves as for ROUND_UP if the discarded fraction is >= .5; otherwise, behaves as for ROUND_DOWN. Note that this is the rounding mode that most of us were taught in grade school.

UNNECESSARY Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary. If this rounding mode is specified on an operation that yields an inexact result, an ArithmeticException is thrown.

UP Rounding mode to round away from zero. Always increments the digit prior to a non-zero discarded fraction. Note that this rounding mode never decreases the magnitude of the calculated value.

Rounding Method Comment

TIBCO Collaborative Information Manager Rulebase Guide

Page 120: Tib Cim Rulebaseguide

106 | Chapter 3 Operator and Character Reference

Other Operators

checkdigitSynopsis: <op func=”checkdigit”>

Arguments: 1 — checkdigit type, see table, 2 — input value.

Returns:

Input value + checkdigit

Description:

Checks the number of digits in an attribute (GTIN). For example:

<op func="checkdigit"><const type="string">14</const><var>GTIN</var></op>

The same example can be rewritten as:

<op func="checkdigit"><const type="string">GTIN</const><var>GTIN</var></op>

CheckDigit Type Keyword

EAN/UCC-8 8

UPC-11 11

UCC-12 or UPC-12 12

EAN/UCC-13 or UPC-13 or GLN 13, GLN

EAN/UCC-14 or UPC-14 or GTIN 14, GTIN

B.O.L. BOL, B.O.L.

S.S.C.C. SSCC, S.S.C.C.

TIBCO Collaborative Information Manager Rulebase Guide

Page 121: Tib Cim Rulebaseguide

Other Operators | 107

count — count number of (non-null, non-false) entries in arraySynopsis: <op func="count">

Arguments: 1 : array of values (or single value).

Returns:

Number of entries in array that are not null and not false.

Description:

Returns the count of non-null entries in an array.

<op func="count"> <var>CHILDCITIES</var></op>

This function goes through an array and counts the number of non-null, non-False entries. For example, you might want to check whether a parent field exists, or if a child has a “CREDITCARD” payment method. If the count function returns 1 or greater, the condition is assumed to be true.

<condition><op func="count"><eq><const type="string">CREDITCARD</const><var>CHILDRECORDS/PAYMENT_METHOD</var></eq></op></condition>

distinct — returns distinct valuesSynopsis: <op func="distinct">

Arguments: 1 : array of values.

Returns:

Array with duplicate values removed.

Description:

<op func="distinct"> <var>CHILDCITIES</const> </op>

TIBCO Collaborative Information Manager Rulebase Guide

Page 122: Tib Cim Rulebaseguide

108 | Chapter 3 Operator and Character Reference

When getting values from an array, remove duplicate values. For example, used in conjunction with the count function, you can check if a value is unique within a set of records:

<check><explanation>UOM of Siblings must not be the same.</explanation><eq><op func="count"><var>SIBLING_REL/UOM</var></op><op func="count"><op func="distinct"><var>SIBLING_REL/UOM</var></op></op></eq></check>

filter — filter a list of recordsSynopsis: <op func="filter">

Arguments: 1 : array of records, 2: selection criteria.

Returns:

Array of records that match filter criteria.

Description:

The filter operator takes an array of records and extracts the ones that match the filter criteria. In the sample below, for records with PERISHABLE=YES and where the child record count is greater than 1, STORAGE_TEMPERATURE is assigned a value of 20.56. If no record is present with PERISHABLE=YES , no value is assigned to STORAGE_TEMPERATURE .

<?xml version="1.0" encoding="UTF-8"?><rulebase metaversion="1.0"><name>Repository Validations</name><description>Repository Validations</description><constraint><name>filterFunction</name><description>filterFunction.</description><declare><var>CHILD_RECORDS</var><link type="relationship_record"><literal>Contains</literal></link></declare><usefor><var>STORAGE_TEMPERATURE</var>

TIBCO Collaborative Information Manager Rulebase Guide

Page 123: Tib Cim Rulebaseguide

Other Operators | 109

</usefor><condition><and><undefined><var/></undefined><op func="count"><assign><var>PERISHABLE_LIST</var><op func="filter"><var>CHILD_RECORDS</var><condition><eq><var>PERISHABLE</var><const type="string">YES</const></eq></condition></op></assign></op></and></condition><action><assign><var>STORAGE_TEMPERATURE</var><const type="string">20.56</const></assign></action></constraint></rulebase>

lookup — lookup value in databaseSynopsis: <op func="lookup">

Arguments: 1 — expression to look up; 2 — table expression. First column is used to lookup value, second column is the value returned.

Returns:

The corresponding value in the database or null if not found.

Description:

The following example looks up the value of UOM in datasource UOMCODES in column VALUE, and returns the value in column CODE.

The returned value is then assigned to variable UOM_CODE. The result of lookup can be used in other functions.

<assign><var>UOM_CODE</var>

TIBCO Collaborative Information Manager Rulebase Guide

Page 124: Tib Cim Rulebaseguide

110 | Chapter 3 Operator and Character Reference

<op func="lookup"><var>UOM</var><table source="datasource"><const type="string">UOMCODES</const><const type="string">VALUE</const><const type="string">CODE</const></table></op></assign>

max— maximum valueSynopsis: <op func="max">

Arguments: 1 .. n: single or array values.

Returns:

Maximum value encountered. Nulls are ignored.

Description:

<op func="max"> <var>CHILDPRICES</var> </op>

This function goes through all its arguments (arrays are expanded) and returns the maximum value found. Null values are ignored.

min — minimum valueSynopsis: <op func="min">

Arguments: 1 .. n : single or array values.

Returns:

Minimum value encountered. Nulls are ignored.

Description:

<op func="min"> <var>CHILDPRICES</var> </op>

This function goes through all its arguments (arrays are expanded) and returns the minimum value found. Null values are ignored.

TIBCO Collaborative Information Manager Rulebase Guide

Page 125: Tib Cim Rulebaseguide

Other Operators | 111

nvl — substitute non-NULL valueSynopsis: <op func="nvl">

Arguments: 2 expressions

Returns:

If expression1 is null, returns expression2; otherwise it returns expression1.

Description:

The nvl function offers a concise way to return or substitute a non-NULL value if the specified value is NULL.

<op func=”nvl”><var> expression1</var><const type="number">expression2</const></op>

Example:

<?xml version="1.0" encoding="UTF-8"?><rulebase metaversion="0.1"><!-- rulebase metaversion="0.1" --><name>rbtest1</name><description>Test Rulebase.</description><declare><var>CONTAINSREL</var><link type="relationship"><literal>CONTAINS</literal></link></declare><declare><var>CONTAINS_RECORD</var><link type="relationship_record"><literal>CONTAINS</literal></link></declare><constraint><name>Add up weight1</name><description>Test roll-up of all child records gross weights and assign to parent gross weight.</description><usefor><var>NETWEIGHT</var></usefor><action><assign><var>NETWEIGHT</var><op func="plus"><op func="mult"><var>CONTAINSREL/QUANTITY</var><op func="nvl"><var>CONTAINS_RECORD/NETWEIGHT</var>

TIBCO Collaborative Information Manager Rulebase Guide

Page 126: Tib Cim Rulebaseguide

112 | Chapter 3 Operator and Character Reference

<const type="number">100</const></op></op></op></assign></action></constraint></rulebase>

sequence — returns a database sequenceSynopsis: <op func="sequence">

Arguments: 1 : name of the database sequence.

Returns:

Next sequence value converted to string.

Description:<op func="sequence"><const type="string">MQ_SEQUENCE_1</const></op>

To automatically generate names for records you often want to have access to, a sequential number generator is defined in the database. This function lets you get the next value from a database sequence. Note that care must be given to only call this function once, otherwise too many sequences will be generated. One way to ensure this is to put it into the newrecord.xml file, not the general repository validation file.

<constraint><name>SequenceGenerator</name><description>Generate a sequence</description><action><assign><var>SEQ</var><op func="concat"><const type="string">HS-</const><op func="pad"><op func="sequence"><const type="string">MQ_SEQUENCE_1</const></op><const type="number">9</const><const type="string">0</const></op><const type="string">-JAL</const></op></assign></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 127: Tib Cim Rulebaseguide

Other Operators | 113

strip — removes all null values from an arraySynopsis: <op func="strip">

Arguments: 1 : array.

Returns:

Array with all null values removed.

Description:

<op func="strip"> <var>CHILDWEIGHT</var> </op>

When getting values from a record’s child, you might want to strip out all null values before doing a computation. This will ensure that the result of the computation does not become null due to the array containing a null value. For example, if the gross weights of a child record were [8.2, 5.2, null, 9.2] then doing a <op func=”plus”> on this array would yield null. However, if you strip out null values first, the result is the expected value:

<op func="plus"> <op func="strip"> <var>CHILDWEIGHT</var> </op></op>

synchstatusSynopsis: <op func="synchstatus">

Arguments:

Argument Use Type Comment

1 Marketplace string Marketplace/Datapool Organization name.

2 Operation string Valid values are:

ADD (default)

PUBLISH

LINK

COMMIT

TIBCO Collaborative Information Manager Rulebase Guide

Page 128: Tib Cim Rulebaseguide

114 | Chapter 3 Operator and Character Reference

Returns:

true - if this record has ever been Added/Published/Linked/Committed to this Marketplace/Datapool.

false - otherwise.

Example:

<!-- no operation is defined. Will check for ADD. -->

<op func="synchstatus"> <const type="string">1Sync</const> </op>

<!-- explicitly defined operation. -->

<op func="synchstatus"> <const type="string">UCCnet</const> <const type="string">PUBLISH</const> </op>

SyncOperationAttribute — used to find the operation date (GDSN Only)It allows you to get the latest sync date for the given Operation (only ADD is supported), Datapool, or Trading Partner (optional).

Its syntax :<var>OPERATION_DATE</var>

<op func="SyncOperationAttribute">

<const type="string">ADD</const>

<const type="string">WWRE</const>

<!--const type="string">Trading Partner Name</const-->

</op>

For this function, three in parameters can be specified.

The second parameter is the marketplace or datapool name. This is optional, if not specified, the rulebase will evaluate it.

The third parameter is the trading partner name (and is not mandatory). If not specified, it will look for all TP; if specified, it will look for the operation for the given TP.

validate_checkdigit - validates checkdigitSynopsis: <op func=”validate_checkdigit”>

Arguments: 1 — checkdigit type, see table, 2 — input value.

TIBCO Collaborative Information Manager Rulebase Guide

Page 129: Tib Cim Rulebaseguide

Other Operators | 115

Returns:

True - string contains valid checkdigit.

False - checkdigit is not correct.

Description:

<op func="validate_checkdigit"><var>GTIN-14</var><var>GTIN</var></op>

CheckDigit Type Number of Digits

GTIN-8 8

GTIN-12 12

GTIN-13 13

GTIN-14 14

S.S.C.C. 18

TIBCO Collaborative Information Manager Rulebase Guide

Page 130: Tib Cim Rulebaseguide

116 | Chapter 3 Operator and Character Reference

Syntax for Expressions

The general syntax of an expression consists of an operator tag followed by arguments, such as the following:

<eq> <var>A</var> <var>B</var> </eq>

In this example, a logical expression "A is equal to B" is evaluated. The arguments to a function can be var (variable) tags, const (constant) values, logical expressions, or built-in functions.

Special CharactersSince validation is stored in XML, you must use escaped version special characters for them to be read correctly. The following table lists special characters and their escaped versions.

const The const tag defines a constant, and the data type is defined by the type attribute. The following is a list of valid data types:

Special Character Escaped Version

< &lt;

& &amp;

‘ (single quote) &apos;

" (double quotes) &quot;

Datatype Description

<const type="boolean"> TRUE or FALSE.

<const type="date"> Date constant.

<const type="number"> Number constant.

<const type="string"> String constant.

TIBCO Collaborative Information Manager Rulebase Guide

Page 131: Tib Cim Rulebaseguide

Syntax for Expressions | 117

The following is an example.

<const type="string">0980</const> <const type="number">1</const>

To define a list of values, use the sep tag inside the const tag, as follows:<enum><const type="string">Soup<sep/>Cookies<sep/>Pasta</const></enum>

var In an expression, the var tag refers to a variable’s value. If you use an empty var tag, then it refers to the variable in the usefor section.

This is an easy way to reuse the same rule for multiple attributes. You list out all the attributes in the usefor section, and then use the var tag when you need to refer to the value of the currently executing variable. The following is an example.

<constraint><name>Valid Numbers</name><description>Valid non-negative number</description><usefor><var>UNITPRICE</var><var>PREPRICED_AMOUNT</var><var>SIZE</var></usefor><action><check><explanation>Has to be a non-negative number</explanation><match><var><const type="string">/^((\d+(\.\d*)?)|(\d*\.\d+))$/</const></match></check></action></constraint>

Undefined (Null) Values If a condition contains a variable with a null value, the condition is not evaluated and any associated action is skipped. Similarly, if an action contains a variable with a null value, it is not executed.

The exception to this is when either expression uses defined or undefined tags. With these functions you can check if a variable has a value and take action appropriately. The following is such an example:

<undefined> <var>PRODUCTHEIGHT</var> </undefined>

TIBCO Collaborative Information Manager Rulebase Guide

Page 132: Tib Cim Rulebaseguide

118 | Chapter 3 Operator and Character Reference

Regular Expressions

In a regular expression, most characters map to themselves. Such as the expression /TIBCO/ matching any string containing TIBCO.

Literal CharactersThere are some characters, however, with special usage within a regular expression and their escaped versions must be used. This is done through the use of a backward slash (\), causing them to be used as literal characters.

The following table lists special use literal characters and their meanings.

Character Description

\f Form feed

\n New line

\r Carriage return

\t Tab

\v Vertical tab

\/ Literal /

\\ Literal \

\. Literal .

\* Literal *

\+ Literal +

\? Literal ?

\| Literal |

\( Literal (

\) Literal )

\[ Literal [

\] Literal ]

TIBCO Collaborative Information Manager Rulebase Guide

Page 133: Tib Cim Rulebaseguide

Regular Expressions | 119

Character Classes There are sets of characters and position characters that can be used in conjunction with literal characters. They include the following:

• Individual literal characters—combine into character classes when placed between square brackets. A character class matches any one character contained within the brackets. For example, /[abc]/ matches a, b, or c.

• Negated character classes—match any character not inside the brackets. These are specified by placing a caret (^) as the first character. For example, /[^abc]/ matches any character except a, b, or c.

• Ranges of characters—specified with a hyphen (-). For example, /[a-z]/ matches all lowercase characters. All alphanumeric characters are matched in this example: /[a-zA-Z0-9]/.

Position CharactersPosition characters specify the position in a string. The most useful of these are the caret (^), which matches the beginning of a string, and the dollar sign ($) which matches the end of the string.

The following table provides a list of regular expression character classes and their descriptions.

\{ Literal {

\} Literal }

\xxx ASCII character of octal value xxx

\xnn ASCII character with hex number nn

\cX ASCII character ^X

Character Description

Character Description

[...] Any one character between the brackets.

[^...] Any one character not between the brackets.

. Any character except newline; equal to [^\n].

TIBCO Collaborative Information Manager Rulebase Guide

Page 134: Tib Cim Rulebaseguide

120 | Chapter 3 Operator and Character Reference

Repetition CharactersRepetition characters specify how many characters are matched.

\w Any word character; equal to [a-zA-Z0-9].

\W Any non-word character; equal to [^a-zA-Z0-9].

\s Any whitespace character; equal to [\t\n\f\r\v].

\S Any non-whitespace characters; equal to [^\t\n\f\r\v].

\d Any digit; equal to [0-9].

\D Any character other than a digit; equal to [^0-9].

[\b] A literal backspace; a special case.

^ The beginning of a string.

$ The end of a string.

\b Word boundary.

\B Not a word boundary.

Character Description

Character Description

{n,m} Match the previous item at least n times, but no more than m times.

{n,} Match the previous item no more than n times.

{n} Match the previous item exactly n times.

? Match zero or one occurrence; equal to {0,1}.

+ Match one or more occurrences; equal to {1,}.

* Match zero or more occurrences; equal to {0,}.

TIBCO Collaborative Information Manager Rulebase Guide

Page 135: Tib Cim Rulebaseguide

Regular Expressions | 121

Alternation, Grouping, Reference The following special characters separate alternatives, group items, and provide references:

• Pipe (|) character — Separates alternatives. For example, /ab|cd|ef/ matches either ab or cd or ef.

• Parentheses — Group items as a single unit so that they can be acted on by the repetition operators. For example, /(ab|cd)+/ matches one or more repetitions of the strings ab or cd.

• Backslash followed by a number — Matches the same characters that were matched in group number n.

Character Description

| Match either subexpression.

(...) Group several items.

\ Match the same characters matched when group number n was first matched.

Groups are subexpressions within (possibly nested) parenthesis. Group numbers are assigned by counting left parentheses from left to right.

TIBCO Collaborative Information Manager Rulebase Guide

Page 136: Tib Cim Rulebaseguide

122 | Chapter 3 Operator and Character Reference

Built-in Functions

The built-in function is called with the following syntax:

<op func="funcname"></op>

Child values are considered arguments to the function. In turn, each function returns a result value which can be used by another function.

TIBCO Collaborative Information Manager Rulebase Guide

Page 137: Tib Cim Rulebaseguide

Custom Functions | 123

Custom Functions

In addition to the built-in functions, you can write your own functions.

During rulebase execution, if an unknown function is encountered, the application looks for the custom function definition from RulebaseCustomFunction.class .

It is located in the following directory:

$MQ_COMMON_DIR/<internal_enterprise_name>/rulebase

Creating a Custom Function1. Copy the sample RulebaseCustomFunction.java file from

$MQ_HOME/common/standard/rulebase .

This class has a predefined method, execCustomFunction , with the following signature.public HashMap execCustomFunction(HashMap args)

This method takes one argument, which is a HashMap and expects HashMap in return. The following is a list of predefined constants that can be used:

Input HashMap

The input HashMap has the following entries:

FUNCTION_ARGUMENTS are passed in an ArrayList with the same order as that specified in the rulebase constraint. The following is a list of data types in the rulebase and corresponding Java types:

Rulebase Constant Equivalent String Constant Description

FUNCTION_NAME FUNC_NAME The name of the function to execute.

FUNCTION_ARGUMENTS FUNC_ARGUMENTS ArrayList of input arguments.

Rulebase Type Java Type

string String

number Long

BigDecimal

TIBCO Collaborative Information Manager Rulebase Guide

Page 138: Tib Cim Rulebaseguide

124 | Chapter 3 Operator and Character Reference

Output HashMap

The output HashMap has the following entries:

2. Implement custom function as a separate method and call it from execCustomFunction depending upon the FUNCTION_NAME passed in.

For example:if (funcName.equals("checkNumber"))

{

retValue = checkNumber(inArgs);

}

3. Compile the RulebaseCustomFunction.java . For example:javac RulebaseCustomFunction.java -classpath $MQ_HOME/lib/mq/AllECMClasses.jar:$MQ_HOME/lib/external/log4j-1.2.14.jar

boolean Boolean

date java.util.Date

array java.util.ArrayList

Rulebase Type Java Type

Rulebase Constant Equivalent String Constant Description

FUNCTION_SUCCESS FUNC_SUCCESS Set to Boolean.

TRUE, if function found and executed successfully else Boolean.

FALSE.

FUNCTION_RETURN_VALUE FUNC_RETURN_VALUE Output of the function.

FUNCTION_ERROR_MESSAGE FUNC_ERROR_MESSAGE Error message in case error occurred in function execution.

This error message is logged in the $MQ_HOME/elink.log file.

Ensure that $MQ_HOME/lib/mq/AllECMClasses.jar and $MQ_HOME/lib/external/log4j-x.x.jar are in the classpath for compilation.

TIBCO Collaborative Information Manager Rulebase Guide

Page 139: Tib Cim Rulebaseguide

Custom Functions | 125

4. Copy the RulebaseCustomFunction.class file to $MQ_COMMON_DIR/<internal_enterprise_name>/rulebase folder and restart the application server.

Custom Rulebase Class Example

For an example, refer to $MQ_HOME/common/standard/rulebase/RulebaseCustomFunction.java .

TIBCO Collaborative Information Manager Rulebase Guide

Page 140: Tib Cim Rulebaseguide

126 | Chapter 3 Operator and Character Reference

TIBCO Collaborative Information Manager Rulebase Guide

Page 141: Tib Cim Rulebaseguide

| 127

Chapter 4 Rulebase Patterns

This chapter deals with various rulebase patterns.

Topics

• Non-Negative Numbers, page 128

• Dependent Variables, page 129

• Dependent Drop-Down Values, page 130

• Specify Data Sources, page 133

• Checking Child Records for Value, page 134

TIBCO Collaborative Information Manager Rulebase Guide

Page 142: Tib Cim Rulebaseguide

128 | Chapter 4 Rulebase Patterns

Non-Negative Numbers

The following rule pattern matches any number of the form 1, 1., 1.0, 0.1,.1.

<constraint> <name>ValidNumbers</name> <description>Valid non-negative number.</description> <usefor> <var>UNITPRICE</var> </usefor> <action> <check> <explanation>Has to be a non-negative number.</explanation> <match> <var/> <const type="string">/^((\d+(\.\d*)?)|(\d*\.\d+))$/</const> </match> </check> </action> </constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 143: Tib Cim Rulebaseguide

Dependent Variables | 129

Dependent Variables

In this scenario, if one variable is defined, another variable must also be defined. For example, if size is specified, its unit must also be specified.

<constraint><name>SIZE_UOM</name><description>See that they are defined.</description><usefor><var>SIZE_UOM</var></usefor><action><check><explanation>Units need to be defined if size specified.</explanation><and><defined><var>SIZE</var></defined><defined><var>SIZE_UOM</var></defined></and></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 144: Tib Cim Rulebaseguide

130 | Chapter 4 Rulebase Patterns

Dependent Drop-Down Values

This scenario shows how the value of one menu item (CATEGORYX2) display depends on another (CATEGORYX1). The last rule illustrates how to specify data sources.

These examples establish a category with three subcategories. The drop-down menu displayed is dependent upon the menu option (subcategory) selected. When you choose Soup, Cookies, or Pasta, their related options are shown.

• Soup — Classic, Chunky, Light

• Cookies — Sugar, Chocolate, Fudge

• Pasta — Spaghetti, Fettuccine, Macaroni

Create a Category With Three Subcategories

<!-- The following constraints are examples of the types of

constraints that can be specified. They can be used as templates for custom repositories. --><constraint> <name>CategoryName</name> <description>Category Name has to be a set of valid values.</description> <usefor> <var>CATEGORYX1</var> </usefor> <action> <select novalue="no"> <enum> <const type="string">Soup<sep/>Cookies<sep/>Pasta</const> </enum> </select> </action> </constraint>

Create First Subcategory: Soup

<constraint> <name>SubCategorySoup</name> <description>Sub Category for Soup</description> <usefor> <var>CATEGORYX2</var> </usefor> <condition>

These examples may be used as templates for custom repository constraints.

TIBCO Collaborative Information Manager Rulebase Guide

Page 145: Tib Cim Rulebaseguide

Dependent Drop-Down Values | 131

<eq> <var>CATEGORYX1</var> <const type="string">Soup</const> </eq> </condition> <action> <select novalue="no"> <enum> <const type="string">Classic</const> <const type="string">Chunky</const> <const type="string">Light</const> </enum> </select> </action> </constraint>

Create Second Subcategory: Cookies

<constraint> <name>SubCategoryNameCookies</name> <description>Sub Category for Cookies</description> <usefor> <var>CATEGORYX2</var> </usefor> <condition> <eq> <var>CATEGORYX1</var> <const type="string">Cookies</const> </eq> </condition> <action><select novalue="no"> <enum> <const type="string">Sugar</const> <const type="string">Chocolate Chip</const> <const type="string">Fudge</const> </enum> </select> </action> </constraint>

Create Third Subcategory: Pasta

<constraint> <name>SubCategoryNamePasta</name> <description>Sub Category for Pasta</description> <usefor> <var>CATEGORYX2</var> </usefor> <condition> <eq> <var>CATEGORYX1</var> <const type="string">Pasta</const> </eq> </condition>

TIBCO Collaborative Information Manager Rulebase Guide

Page 146: Tib Cim Rulebaseguide

132 | Chapter 4 Rulebase Patterns

<action> <select novalue="no"> <enum> <const type="string">Spaghetti</const> <const type="string">Fettuccine</const> <const type="string">Macaroni</const> </enum> </select> </action> </constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 147: Tib Cim Rulebaseguide

Specify Data Sources | 133

Specify Data Sources

The following is an example of using a datasource to specify the values of a drop-down list. The datasource name is “DSX1”. The database value is stored in a column called “VALUE” and the text of the message is stored in a column called “DESCRIPTION”.

<constraint><name>DataSourceValues</name><description>Get values from data source</description)<usefor><var>DATASOURCEX1</var></usefor><action><select novalue="no"><table source="datasource"><const type="string">DSX1</const><const type="string">VALUE</const><const type="string">DESCRIPTION</const></table></select></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 148: Tib Cim Rulebaseguide

134 | Chapter 4 Rulebase Patterns

Checking Child Records for Value

Below is an example of requiring an attribute to be present. (MATERIAL_CODE_AGENGY) if one of the children has a certain value.

First, declare 2 variables. RELA_REL points to all the records pointed at by the “RelA” relationship.

The RELA_LIST variable is a local variable which will store the children that contain a value. This is not necessary, but the list can be used in the <information> tag. The list of values will then show up in the validation page of the record.

<declare><var>RELA_REL</var><link type="relationship_record"><literal>RelA</literal></link></declare><declare usage="local"><var>RELA_LIST</var></declare>

The condition checks that the RECORD_TYPE is correct and that the value is not already defined. Through this optimization, looking at all the children can be skipped if the variable is already defined. Looking at the children is an expensive operation, so if it is known that MATERIAL_CODE_AGENCY is set to the correct value, the check can be skipped altogether.

<constraint><name>MaterialCodeAgency</name><description>Material Code Agency is mandatory if LevelA has Coupon Family Code set to SI.</description><usefor><var>MATERIAL_CODE_AGENCY</var></usefor><condition><and><eq><var>RECORD_TYPE</var><const type="string">LEVEL1</const></eq><undefined><var/></undefined></and></condition><action><check><explanation>Material Code Agency is mandatory if LevelA has Coupon Family Code set to SI.</explanation><information><var>RELA_LIST</var>

TIBCO Collaborative Information Manager Rulebase Guide

Page 149: Tib Cim Rulebaseguide

Checking Child Records for Value | 135

</information><eq><const type="number">0</const><op func="count"><assign><var>RELA_LIST</var><op func="filter"><var>RELA_REL</var><condition><eq><var>COUPON_FAMILY_CODE</var><const type="string">SI</const></eq></condition></op></assign></op></eq></check></action></constraint>

Below is an example of an actual run of the rule (obtained by setting System Debugging > RuleBase Debug Mode to true in the Configurator). The test fails because 2 children exist that have the value.

<constraint><name>MaterialCodeAgency</name><usefor><var>MATERIAL_CODE_AGENCY</var></usefor><condition><and><eq><var>RECORD_TYPE<result><![CDATA[LEVEL1]]></result></var><const type="string">LEVEL1</const><result><![CDATA[true]]></result></eq><undefined><var><result/></var><result><![CDATA[true]]></result></undefined><result><![CDATA[true]]></result></and></condition><action><check><explanation>Material Code Agency is mandatory if LevelA has Coupon Family Code set to SI.</explanation><information><var>RELA_LIST<result><![CDATA[[k5-A-1/1/1, k5-A2/1/1]]]></result></var></information>

TIBCO Collaborative Information Manager Rulebase Guide

Page 150: Tib Cim Rulebaseguide

136 | Chapter 4 Rulebase Patterns

<eq><const type="number">0</const><op func="count"><assign><var>RELA_LIST</var><op func="filter"><var>RELA_REL</var><condition><eq><var>COUPON_FAMILY_CODE</var><const type="string">SI</const></eq></condition><result><![CDATA[[k5-A-1/1/1, k5-A2/1/1]]]></result></op></assign><result><![CDATA[2]]></result></op><result><![CDATA[false]]></result></eq><result><![CDATA[false]]></result></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 151: Tib Cim Rulebaseguide

| 137

Chapter 5 Rulebase Examples

This section has extensive rulebase code examples divided into functional segments (modules) to call attention to each of their functions.

Topics

• Rulebase Header, page 139

• Specify Mandatory Attributes, page 140

• Access Modes, page 141

• Check for a Value (GTIN), page 142

• CATALOG_NAME Variable, page 143

• Specify Valid Numbers, page 144

• Assign TRUE or FALSE, page 145

• Check Values of Related Attributes, page 146

• Check Values of Attributes Related to MINIMUM_SHIP, page 147

• Check Code Length, page 148

• Validate Code, page 149

• Validate Temperature Values, page 150

• Skip First Pass, page 152

• Specify Valid Values, page 154

• Check for DIMENSIONUOM, page 155

• Specify Types For a Drop-Down Menu, page 156

• Check Length of UPC Code, page 157

• Validate Against First Order Date, page 159

• Validate Against First Ship Date, page 160

• Validate Net Weight, page 161

TIBCO Collaborative Information Manager Rulebase Guide

Page 152: Tib Cim Rulebaseguide

138 | Chapter 5 Rulebase Examples

• Calculate Volume, page 162

• Specify New Size, page 163

• Propagate Attribute Value to Children, page 164

TIBCO Collaborative Information Manager Rulebase Guide

Page 153: Tib Cim Rulebaseguide

Rulebase Header | 139

Rulebase Header

<!--rulebase metaversion=?0.1?><name>Client Validations</name><description>Implements client validations</description><declare><var>CONTAINSLINK</var><link type="relationship_record"><literal>CONTAINS</literal></link></declare>

TIBCO Collaborative Information Manager Rulebase Guide

Page 154: Tib Cim Rulebaseguide

140 | Chapter 5 Rulebase Examples

Specify Mandatory Attributes

<constraint><name>Mandatory</name><description>Mandatory attributes</description><usefor><var>PRODUCTID</var><var>SHORTDESC</var></usefor><action><check><explanation>it is a mandatory attribute</explanation><defined><var/></defined></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 155: Tib Cim Rulebaseguide

Access Modes | 141

Access Modes

Mode: allow_merge

In this example, if the value of RECORD_TYPE is CUST, the record data is merged with the previous version's data. That is, previous version data is used in the final merged version. RECORD_TYPE will have the attribute value of the previous version. Previous version will be selected based on the input parameter of the record merge activity.

<constraint><name>AllowMergeForRecordTypeCUST</name><description>Allow merge if value of RECORD_TYPE is CUST.</description><condition> <eq><var>RECORD_TYPE</var><const type="string">CUST</const></eq> </condition><action><access mode="allow_merge"/></action></constraint></rulebase>

Mode: skip_merge

In this example, if the value of UOM is CASE, the record data is not merged with the target record. The data from the source record is used in the final merged version.

<constraint><name>SkipMergeForUOMCASE</name><description>Skip merge if value of UOM is CASE.</description><condition> <eq><var>UOM</var><const type="string">CASE</const></eq> </condition><action><access mode="skip_merge"/></action></constraint></rulebase>

TIBCO Collaborative Information Manager Rulebase Guide

Page 156: Tib Cim Rulebaseguide

142 | Chapter 5 Rulebase Examples

Check for a Value (GTIN)

<constraint><name>GTIN</name><description>GTIN checks</description><usefor><var>GTIN</var></usefor><action><check><explanation lang="en">GTIN has to be 14 numeric characters</explanation><match><var/><const type="string">/^\d{14}$/</const></match></check><check><explanation lang="en">GTIN cannot start with 0980,0981,0982,0983,0984,0985,0986,098,0988,099</explanation><not><or><in><op func="substring"><var>GTIN</var><const type="number">0</const><const type="number">4</const></op><const type="string">0980</const><const type="string">0981</const><const type="string">0982</const><const type="string">0983</const><const type="string">0984</const><const type="string">0985</const><const type="string">0986</const><const type="string">0988</const><const type="string">0989</const></in><in><op><var>GTIN</var><const type="number">0</const><const type="number">3</const></op><const type="string">098</const><const type="string">099</const></in></or></not></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 157: Tib Cim Rulebaseguide

CATALOG_NAME Variable | 143

CATALOG_NAME Variable

The CATALOG_NAME variable gets the name of the repository for the current record. This is useful when the rulebase in the ApplyRulebase activity of import workflow has constraints that need to be applied depending on the repository name.

For example, while creating a cross-repository relationship on the CAT1 and CAT2 repositories, if the rulebase has one constraint that needs to be applied for only the CAT2 Repository, then you can use the CATALOG_NAME as follows:

<constraint><name>ASSIGN_EXISTING_PRODUCT</name><description>Assign the existing product</description><condition><eq><var>CATALOG_NAME</var><const type="string">CAT2</const></eq></condition>..............................</constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 158: Tib Cim Rulebaseguide

144 | Chapter 5 Rulebase Examples

Specify Valid Numbers

<constraint><name>Valid Numbers</name><description>Valid non-negative number</description><usefor><var>UNITPRICE</var><var>PREPRICED_AMOUNT</var><var>SIZE</var><var>PRODUCTWIDTH</var><var>PRODUCTHEIGHT</var><var>PRODUCTDEPTH</var><var>NETWEIGHT</var><var>GROSSWEIGHT</var><var>VOLUME</var><var>TI</var><var>HI</var><var>MINIMUMORDER</var><var>MAXIMUMORDER</var><var>MINIMUM_SHIP</var><var>MAXIMUM_SHIP</var><var>ORDER_INCREMENT</var><var>FLASHPOINT_TEMP1</var><var>FLASHPOINT_TEMP2</var><var>HAZMAT_NUM1</var><var>HAZMAT_NUM2</var><var>UNITS_PER_CONTAINER</var><var>UNITS_PER_INNER_CONTAINER</var></usefor><action><check><explanation>Has to be a non-negative number</explanation><match><var/><const type="string">/^((\d+(\.\d*)?)|(\d*\.\d+))$/</const></match></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 159: Tib Cim Rulebaseguide

Assign TRUE or FALSE | 145

Assign TRUE or FALSE

This example shows how to assign TRUE or FALSE drop down values to boolean type attributes.

<constraint><name>TrueFalse</name><description>TRUE or FALSE</description><usefor><var>HAZMATFLAG</var><var>RECYCLEDMATERIALS</var><var>FREIGHTINCFLAG</var><var>PUNCHOUTENABLED</var><var>DELETE</var><var>CONSUMER_UNIT</var><var>ORDERABLE</var><var>PRIVATE</var></usefor><action><select novalue="default"><enum><const type="string">TRUE</const><const type="string">FALSE</const></enum></select></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 160: Tib Cim Rulebaseguide

146 | Chapter 5 Rulebase Examples

Check Values of Related Attributes

This example shows how to check values of related attributes: MAXIMUMORDER, MINIMUMORDER and MAXIMUMSHIP.

<constraint><name>MaximumOrder/name><description>Relationships</description><usefor><var>MAXIMUMORDER</var></usefor><condition><defined><var>MAXIMUMORDER</var></defined> </condition><action><check><explanation>maximum order has to be greater than minimum order</explanation><and><defined><var>MINIMUMORDER</var></defined><lt><var>MINIMUMORDER</var><var>MAXIMUMORDER</var></lt></and></check><check><explanation>maximum order should be greater than maximum ship</explanation><and><defined><var>MAXIMUM_SHIP</var></defined><gt><var>MAXIMUM_SHIP</var><var>MAXIMUMORDER</var></gt></and></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 161: Tib Cim Rulebaseguide

Check Values of Attributes Related to MINIMUM_SHIP | 147

Check Values of Attributes Related to MINIMUM_SHIP

This example shows you how to check values of attributes related to MINIMUM_SHIP, namely MAXIMUMSHIP and MINIMUMORDER.

<constraint><name>MinimumShip</name><description>Check the values of related attributes of MinimumShip</description><usefor><var>MINIMUM_SHIP</var></usefor><condition><defined><var>MINIMUM_SHIP</var></defined></condition><action><check><explanation>minimum ship has to be less than or equal to maximum ship</explanation><and><defined><var>MAXIMUM_SHIP</var></defined><leq><var>MINIMUM_SHIP</var><var>MAXIMUM_SHIP</var></leq></and></check><check><explanation>minimum ship has to be greater or equal to minimum order</explanation><and><defined><var>MINIMUMORDER</var></defined><geq><var>MINIMUM_SHIP</var><var>MINIMUMORDER</var></geq></and></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 162: Tib Cim Rulebaseguide

148 | Chapter 5 Rulebase Examples

Check Code Length

<constraint><name>HazMatCodeLength</name><description>Check HazMat code and description length</description><usefor><var>HAZMAT_CODE1</var><var>HAZMAT_CODE2</var><var>HAZMAT_DESCRIPTION1</var><var>HAZMAT_DESCRIPTION2</var></usefor><action><check><explanation>Must be at least four characters</explanation><geq><op func="length"><var/></op><const type="number">4</const></geq></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 163: Tib Cim Rulebaseguide

Validate Code | 149

Validate Code

<constraint><name>HazMatCodeQualifier1</name><description>Check HazMat code qualifier and class code validation</description><condition><defined><var>HAZMAT_CODE_QUALIFIER1</var></defined></condition><action><check><explanation>Hazmat Class code is mandatory if HAZMAT_CODE_QUALIFIER1 is defined</explanation><defined><var>HAZMAT_CLASS_CODE</var></defined></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 164: Tib Cim Rulebaseguide

150 | Chapter 5 Rulebase Examples

Validate Temperature Values

This example shows you how to validate temperature values, units and define drop down for temperature units.

<constraint><name>FlashpointMax</name><description>Validate maximum temperature</description><usefor><var>FLASHPOIONT_TEMP1</var><var>FLASHPOIONT_TEMP2</var></usefor><action><check><explanation>Temperature must be less than 999</explanation><leq><var/><const type="number">999</const></leq></check></action></constraint><constraint><name>FlashpointUnit1</name><description>See that units are defined</description><usefor><var>FLASHPOIONT_UNITS1</var></usefor><action><check><explanation>If temperature is defined, units must be present</explanation><or><undefined><var>FLASHPOIONT_TEMP1</var></undefined><defined><var>FLASHPOIONT_UNITS1</var></defined></or></check></action></constraint><constraint><name>FlashpointUnit2</name><description>See that units are defined</description><usefor><var>FLASHPOIONT_UNITS2</var></usefor><action><check><explanation>If temperature is defined, units must be present</explanation><or>

TIBCO Collaborative Information Manager Rulebase Guide

Page 165: Tib Cim Rulebaseguide

Validate Temperature Values | 151

<undefined><var>FLASHPOIONT_TEMP2</var></undefined><defined><var>FLASHPOIONT_UNITS2</var></defined></or></check></action></constraint><constraint><name>FlashpointUnitSelect</name><description>Temperature drop-down menu</description><usefor><var>FLASHPOIONT_UNITS1</var><var>FLASHPOIONT_UNITS2</var></usefor><action><select novalue="default"><enum col="2"><const type="string">FA<sep/>Fahrenheit</const><const type="string">CE<sep/>Celsius</const><const type="string">KA<sep/>Kelvin</const></enum></select></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 166: Tib Cim Rulebaseguide

152 | Chapter 5 Rulebase Examples

Skip First Pass

<?xml version="1.0" encoding="UTF-8"?><rulebase metaversion="0.1"><name>rbfirstpass_sample</name><description>Rulebase to test first pass skip functionality.</description><execution_directive first_pass="skip"/><constraint><name>test1</name><description>Assign value to localvar</description><condition><undefined><var>TESTINT</var></undefined></condition><action><assign><explanation>Initializing TESTINT value...</explanation><var>TESTINT</var><const type='number'>1</const></assign></action><action><assign><explanation>Incrementing TESTINT value...</explanation><var>TESTINT</var><op func='plus'><var>TESTINT</var><const type='number'>1</const></op></assign></action></constraint></rulebase>

first_pass set to skip

1. Run sample rulebase with execution_directive first_pass set to skip.

2. Define a new Repository and copy the sample rulebase in the catalog directory.

3. Modify the repository and create a new attribute, TESTINT, of type integer.

4. Click on the Add new record link.

5. Check the value of TESTINT; it should be initialized to 1.

6. Save the record and check the value of TESTINT. It should be 2.

TIBCO Collaborative Information Manager Rulebase Guide

Page 167: Tib Cim Rulebaseguide

Skip First Pass | 153

first_pass set to required

1. Run sample rulebase with execution_directive first_pass set to Required.

2. Define a new Repository and copy the sample rulebase in the catalog directory.

3. Modify the repository and create a new attribute, TESTINT, of type integer.

4. Click on the Add new record link.

5. Check the value of TESTINT; it should be initialized to 1.

6. Save the record and check the value for TESTINT. It should be 3. This is because rulebase was executed twice incrementing the TESTINT value twice.

TIBCO Collaborative Information Manager Rulebase Guide

Page 168: Tib Cim Rulebaseguide

154 | Chapter 5 Rulebase Examples

Specify Valid Values

<constraint><name>HazMatNum</name><description>Valid values for HazMatNum</description><usefor><var>HAZMAT_NUM1</var></usefor><action><select novalue="default"><enum><const type="number">1</const><const type="number">2</const><const type="number">3</const><const type="number">4</const><const type="number">5</const></enum></select></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 169: Tib Cim Rulebaseguide

Check for DIMENSIONUOM | 155

Check for DIMENSIONUOM

This example shows how to check for DIMENSIONUOM if linear attribute values are defined.

<constraint><name>DIMENSIONSUOM</name><description>See that dimensions are defined for linear values</description><usefor><var>DIMENSIONSUOM</var></usefor><action><check><explanation>Units need to be defined if linear dimensions arespecified</explanation><and><or><defined><var>PRODUCTWIDTH</var></defined><defined><var>PRODUCTHEIGHT</var></defined><defined><var>PRODUCTDEPTH</var></defined></or><defined><var>DIMENSIONSUOM</var></defined></and></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 170: Tib Cim Rulebaseguide

156 | Chapter 5 Rulebase Examples

Specify Types For a Drop-Down Menu

<constraint><name>UPCTypes</name><description>UPC_TYPE drop-down menu</description><usefor><var>UPC_TYPE</var></usefor><action><select novalue="default"><enum><const type="string">UN</const><const type="string">UP</const><const type="string">UA</const><const type="string">UD</const><const type="string">UE</const><const type="string">EN</const><const type="string">UK</const><const type="string">U2</const><const type="string">UG</const><const type="string">UH</const><const type="string">UI</const></enum></select></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 171: Tib Cim Rulebaseguide

Check Length of UPC Code | 157

Check Length of UPC Code

<constraint><name>UPC12</name><description>Check length of UPC code</description><usefor><var>UPC</var></usefor><condition><or><eq><var>UPC_TYPE</var><const type="string">UN</const></eq><eq><var>UPC_TYPE</var><const type="string">UP</const></eq><eq><var>UPC_TYPE</var><const type="string">UA</const></eq><eq><var>UPC_TYPE</var><const type="string">UD</const></eq><eq><var>UPC_TYPE</var><const type="string">UE</const></eq><eq><var>UPC_TYPE</var><const type="string">UG</const></eq></or></condition><action><check><explantion> For UPC Type UN,UP,UA,UD,UE,and UG,UPC must havelength 12</explanation><eq><op func="length"><var/></op><const type="number">12</const></eq></check></action></constraint><constraint><name>UPC13</name><description>Check length of UPC code</description><usefor><var>UPC</var>

TIBCO Collaborative Information Manager Rulebase Guide

Page 172: Tib Cim Rulebaseguide

158 | Chapter 5 Rulebase Examples

</usefor><condition><or><eq><var>UPC_TYPE</var><const type="string">EN</const></eq><eq><var>UPC_TYPE</var><const type="string">U2</const></eq></or></condition><action><check><explantion> For UPC Type EN,and U2,UPC must havelength 13</explanation><eq><op func="length"><var/></op><const type="number">13</const></eq></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 173: Tib Cim Rulebaseguide

Validate Against First Order Date | 159

Validate Against First Order Date

<constraint><name>FirstOrderDate</name><description>Validations against First Order Date</description><usefor><var>LAST_ORDER_DATE</var><var>FIRST_SHIP_DATE</var></usefor><condition><defined><var>FIRST_ORDER_DATE</var></defined></condition><action><check><explanation>LAST_ORDER_DATE and FIRST_SHIP_DATE cannot be earlier than First Order Date.</explanation><geq><var/><var>FIRST_ORDER_DATE</var></geq></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 174: Tib Cim Rulebaseguide

160 | Chapter 5 Rulebase Examples

Validate Against First Ship Date

<constraint><name>FirstShipDate</name><description>Validations against First Ship Date</description><usefor><var>LAST_SHIP_DATE</var></usefor><condition><defined><var>FIRST_SHIP_DATE</var></defined></condition><action><check><explanation>LAST_SHIP_DATE cannot be earlier than First Ship Date</explanation><geq><var/><var>FIRST_SHIP_DATE</var></geq></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 175: Tib Cim Rulebaseguide

Validate Net Weight | 161

Validate Net Weight

<constraint><name>NetWeight</name><description>Validations against Net Weight</description><usefor><var>NETWEIGHT</var></usefor><condition><defined><var>GROSSWEIGHT</var>/defined></condition><action><check><explanation>Net Weight has to be less than Gross Weight</explanation><leq><var/><var>GROSSWEIGHT</var></leq></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 176: Tib Cim Rulebaseguide

162 | Chapter 5 Rulebase Examples

Calculate Volume

<constraint><name>ComputeVolume</name><description>Calculate Volume</description><usefor><var>VOLUME</var></usefor><action><assign><var>VOLUME</var><op func="mult"><var>PRODUCTWIDTH</var><var>PRODUCTHEIGHT</var><var>PRODUCTDEPTH</var></op></assign></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 177: Tib Cim Rulebaseguide

Specify New Size | 163

Specify New Size

<constraint><name>PreviousSize</name><description>New size cannot change by more than 2 from previous version</description><action><check><explanation>Size cannot increase by more than 2 from previous version</explanation><lt><op func="minus"><var>SIZE</var><var>PREVIOUS_VERSION/SIZE</var></op><const type="number">2.0</const></lt></check></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 178: Tib Cim Rulebaseguide

164 | Chapter 5 Rulebase Examples

Propagate Attribute Value to Children

<constraint><name>PropagateHazMatFlag</name><description>Roll-down HazMatFlag to contain children</description><usefor><var>HAZMATFLAG</var></usefor><condition><changed><var>HAZMATFLAG</var></changed></condition><action><propagate type="inline"><declare><var>CONTAINSLINK</var><link type="relationship_record"><literal>CONTAINS</literal></link></declare><var>CONTAINSLINK</var><action><assign><var>HAZMATFLAG</var><var>LINK/HAZMATFLAG</var></assign></action></propagate></action></constraint>

TIBCO Collaborative Information Manager Rulebase Guide

Page 179: Tib Cim Rulebaseguide

| 165

Chapter 6 Embedding Rulebases

This chapter describes how to embed one rulebase into another so that duplication of rules in more than one rulebases can be avoided.

Topics

• Overview, page 166

• Procedure, page 167

• Error Handling and Debugging, page 168

TIBCO Collaborative Information Manager Rulebase Guide

Page 180: Tib Cim Rulebaseguide

166 | Chapter 6 Embedding Rulebases

Overview

Managing all rules in a single rulebase file tends to be difficult as the number of rules increase. It also becomes difficult to reuse parts of one rulebase in other rulebases.

To avoid duplication of rules in more than one rulebases, CIM allows you to embed one rulebase into another. The embedding can be done up to any levels. That is, rulebase A may embed rulebase B, which may embed rulebase C and so on. However, cyclic embedding is not supported. That is, Rulebase A can include B and B can includes C but C cannot include A.

The embedding works as if the embedded rulebase was part of the original rulebase (in which embedding happens).

An example of embedded rulebases is the use of the rulebase for the EvaluateRulebase activity. This activity accepts only ONE rulebase as input but the records being processed may belong to different repositories and hence different rulebases. In this case, we can create one MAIN rulebase that will embed the rulebases for the other repositories.

Another case where rulebases could be embedded: For each repository associated with a cross-repository relationship, a separate rulebase is created. However, there may be some validations for bundles which must be applied irrespective of which record is being validated. For example, if there is a mandatory one-to-one relationship (such as, customer must have one and only one address). To validate such constraints, rules must be added to both the rulebases.

To avoid duplicate rules which require more efforts to maintain, common rules can be separated in a third rulebase, which is then embedded within other rulebases as required.

All rulebase features, including propagation, are available in embedded rulebases.

TIBCO Collaborative Information Manager Rulebase Guide

Page 181: Tib Cim Rulebaseguide

Procedure | 167

Procedure

To embed a rulebase, define a new action as shown in the following example. This way, you can also control the include based on conditions.

<constraint> <name>Include another rulebase</name> <description>Some descr </description> <condition> Any condition here </condition> <action> <include> <literal>/standard/rulebase/testrulebase.xml</literal> <literal>LogicalName</literal> </include> </action></constraint>

The first literal specifies the rulebase file location. This is mandatory. The rulebase being embedded must be a complete and valid rulebase. It must not be a fragment and it should be possible to use this rulebase independently. The embedded rulebase file is looked for in the following order:

• Standard enterprise rulebase directory or standard rulebase relative to commondir.

• Absolute path specified by the literal

The second literal is optional and specifies a logical name for the embedded rulebase. This name is used to add a prefix to all constraints to generate unique constraint name.

Though there is no limit, we recommend that you keep the logical name between 8 to 12 characters. Also, no check is done to see whether the same logical name is assigned to more than one embedded rulebases. If duplicate constraint names are generated because of the same logical name being assigned to more than one embedded rulebases, it does not affect the functionality but debugging will become a little difficult.

The order of rules is maintained. For example, if rulebase B is embedded after constraint "test_constraint", all constraints of rulebase B are executed or applied after constraint "test_constraint".

TIBCO Collaborative Information Manager Rulebase Guide

Page 182: Tib Cim Rulebaseguide

168 | Chapter 6 Embedding Rulebases

Error Handling and Debugging

• If duplicate declarations are present in both rulebases, an error is displayed. Duplicate declarations within a rulebase are also not allowed.

• If duplicate constraints are present in both rulebases (Constraint A appears in Rulebase A as well as Rulebase B), they are considered as separate constraints.

• All rulebases share the same context.

• If the same rulebase is embedded more than once (Rulebase A embeds Rulebase B twice), it is reported as a "duplicate declaration".

• Any severity, threshold definitions in the embedded rulebase are ignored.

As the constraint names include the logical name assigned to the rulebase, the name of the constraint in the trace file will help in finding out which rulebase the constraint came from.

The execution trace of embedded rulebase is included along with parent rulebase.

TIBCO Collaborative Information Manager Rulebase Guide

Page 183: Tib Cim Rulebaseguide

| 169

Appendix A Synch_History

This chapter describes how the synchronization history of a record can be accessed using the SYNCH_HISTORY variable.

Topics

• SYNCH_HISTORY, page 170

TIBCO Collaborative Information Manager Rulebase Guide

Page 184: Tib Cim Rulebaseguide

170 | Appendix A Synch_History

SYNCH_HISTORY

The synchronization history of a record can be accessed using SYNCH_HISTORY variable. This variable is only active during a synchronization.

SYNCH_HISTORY Explanation

IS_DISCONTINUED Is Discontinued

IS_ADDED Is_Added

HAS_BASE_ATTRIBUTE_SET_CHANGED Has_Base_Attribute_Set_Changed

HAS_ATTRIBUTE_SET_CHANGED Has_Attribute_Set_Changed

HAS_PARTNER_ATTRIBUTE_SET_CHANGED Has_Partner_Attribute_Set_Changed

IS_PUBLISHED Is_Published

IS_PUBLISHED_TO_ANY_PARTNER Is_Published_To_Any_Partner

IS_LINKED Is_Linked

IS_DELETED Is_Deleted

IS_REVIEWED Is_Reviewed

IS_ACCEPTED Is_Accepted

IS_REJECTED Is_Rejected

IS_SYNCHRONIZED Is_Synchronized

HAS_PUBLISHED_RELATION_CHANGED Has_Published_Relation_Changed

HAS_LINKED_RELATION_CHANGED Has_Linked_Relation_Changed

HAS_CHILDREN Has_Children

HAS_PREVIOUSLY_PUBLISHED_PARENT Has_Previously_Published_Parent

HAS_ANY_CHILD_CHANGED Has_Any_Child_Changed

HAS_INPROGRESS_SYNC_EVENT Has_Inprogress_Sync_Event

IS_ROOT_RECORD Is_Root_Record

TIBCO Collaborative Information Manager Rulebase Guide

Page 185: Tib Cim Rulebaseguide

SYNCH_HISTORY | 171

IS_PARENT Is_Parent

IS_CHILD Is_Child

IS_ADD_REQUESTED Is_Add_Requested

IS_CORRECTION_REQUESTED Is_Correction_Requested

IS_DELETE_REQUESTED Is_Delete_Requested

IS_PUBLISH_REQUESTED Is_Publish_Requested

IS_RELOAD_REQUESTED Is_Reload_Requested

IS_CANCEL_REQUESTED Is_Cancel_Requested

IS_DISCONTINUE_REQUESTED Is_Discontinue_Requested

IS_INCREMENTAL_REQUESTED Is_Incremental_Requested

IS_ACCEPT_REQUESTED Is_Accept_Requested

IS_REJECT_REQUESTED Is_Reject_Requested

IS_REVIEW_REQUESTED Is_Review_Requested

IS_SYNCHRONIZE_REQUESTED Is_Synchronize_Requested

VALID_NEXT_OPERATIONS Valid_Next_Operations

OPERATION_REQUESTED Operation_Requested

MASTERCATALOG_ID Mastercatalog_Id

MASTERCATALOG_NAME Mastercatalog_Name

BUYER_ID Buyer_Id

BUYER_NAME Buyer_Name

TRADING_PARTNER_ID Trading_Partner_Id

TRADING_PARTNER_NAME Trading_Partner_Name

TRADING_PARTNER_TYPE Trading_Partner_Type

SYNCH_HISTORY Explanation

TIBCO Collaborative Information Manager Rulebase Guide

Page 186: Tib Cim Rulebaseguide

172 | Appendix A Synch_History

Example:

<constraint><name> Get operation when it’s a root record and is published before and attribute set changed</name><description>Constraint to return operation when it’s a root record and is published before and attribute set changed.</description><condition><var>SYNCH_HISTORY/IS_ROOT_RECORD</var>

DATAPOOL_ID Datapool_Id

DATAPOOL_NAME Datapool_Name

INCREMENTAL_FLAG Incremental_Flag

RELOAD_FLAG Reload_Flag

ADD_FLAG Add_Flag

CORRECTION_FLAG Correction_Flag

DELETE_FLAG Delete_Flag

PUBLISH_FLAG Publish_Flag

CANCEL_FLAG Cancel_Flag

DISCONTINUE_FLAG Discontinue_Flag

ACCEPT_FLAG Accept_Flag

REJECT_FLAG Reject_Flag

REVIEW_FLAG Review_Flag

SYNCHRONIZE_FLAG Synchronize_Flag

CONFIRM_OPERATION_REQUESTED Confirm_Operation_Requested

ROOT_ADD_OPERATION Root_Add_Operation

ROOT_LINK_OPERATION Root_Link_Operation

ROOT_UNLINK_OPERATION Root_Unlink_Operation

ROOT_PUBLISH_OPERATION Root_Publish_Operation

SYNCH_HISTORY Explanation

TIBCO Collaborative Information Manager Rulebase Guide

Page 187: Tib Cim Rulebaseguide

SYNCH_HISTORY | 173

</condition><action><assign><explanation>Operation.</explanation><var>PUBLISH_OPERATION</var><const>PUBLISH:::ADD</const></assign></action>

TIBCO Collaborative Information Manager Rulebase Guide

Page 188: Tib Cim Rulebaseguide

174 | Appendix A Synch_History

TIBCO Collaborative Information Manager Rulebase Guide

Page 189: Tib Cim Rulebaseguide

| 175

Appendix B System Variables

This appendix lists the implicit system variables.

Topics

• System Implicit Variables, page 176

TIBCO Collaborative Information Manager Rulebase Guide

Page 190: Tib Cim Rulebaseguide

176 | Appendix B System Variables

System Implicit Variables

The following is a list of implicit system variables. These variables are used to access the values of the system attribute for the record.

Table 6 Implicit System Variables

Variable Description

STATE Gets the product state of the current record.

RECORD_VERSION Gets the product version of the current record.

RECORD_ACTION Gets current record action of the record.

RECORD_CHECKSUM Gets current record checksum.

RECORD_LAST_MODIFIED_ON Gets current record last modified time.

RECORD_CREATED_DATE Gets current record creation date.

RECORD_ACTIVE_FLAG Gets current record active flag.

RECORD_LAST_MODIFIED_BY Gets modify member ID of the member who modified current record in last.

RECORD_KEY Gets internal bundle key. Contains record key ID and repository ID.

RECORD_ID Gets record ID for the current record.

RECORD_IDEXT Gets record ID and Ext for the current record.

RECORD_KEYID Gets recordkey ID for the current record.

CATALOG_NAME Gets the name of the repository for the current record.

RECORD_IS_ROOT Gets information on whether the record is the root of the bundle.

TIBCO Collaborative Information Manager Rulebase Guide

Page 191: Tib Cim Rulebaseguide

| 177

Index

C

Context Variables 69customer support xiv

D

Dependant variables 129

E

Establishing XML rules file 3Expressions 59, 175Expressions - Syntax 116

G

Getting started with rules 1Global property settings 56

N

Non-negative numbers 128

O

Operator and character reference 79Operators - by area 80Operators - comparison 80

Operators - logical 80Operators - other 81Operators by name 83

R

Regular Expressions 118Rulebase Examples 137Rulebase Patterns 127

S

SQL Expressions 60support, contacting xivSynch_History 169

T

technical support xiv

V

Variable declarations 9

TIBCO Collaborative Information Manager Rulebase Guide

Page 192: Tib Cim Rulebaseguide

178 | Index

TIBCO Collaborative Information Manager Rulebase Guide