Child pages
  • Rules

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • You need to make sure the name of the rule is unique. 
  • You'll also want to validate the rule to make sure there are no errors. 
  • Finally, once you've successfully saved your rule, you need to make sure to click the Activate button from the rule grid for the rule to take effect.


The following are example of some custom requisition rules that can be created:

Require a deliver to address when creating a requisition 

Name: org.districtname.RequisitionDeliveryAddressRequired

...

Code Block
package org.districtName.Requistion.DeliveryAddressRequired;
dialect  "mvel"

import function org.ssdt_ohio.modules.rules.RulesHelper.*
import org.ssdt_ohio.model.ModelInformation;
import org.ssdt_ohio.model.ModelState;
import org.ssdt_ohio.model.events.*;
import org.ssdt_ohio.usas.model.requisition.Requisition;
import org.ssdt_ohio.usas.model.vendor.Vendor;

rule "requisition delivery address is required" 

	when
	    CreateObjectEvent() or UpdateObjectEvent()
    	ModelInformation(state != ModelState.IMPORTING, primary)
	    $requisition : Requisition(deliveryAddress.isEmpty())

    then
    	error(kcontext, "Requisition cannot be saved without a delivery address")

end



Require a vendor when creating a requisition

Name: org.districtname.RequisitionVendorRequired

...

Code Block
package org.districtName.Requisition.VendorRequired;
dialect  "mvel"

import function org.ssdt_ohio.modules.rules.RulesHelper.*
import org.ssdt_ohio.model.ModelInformation;
import org.ssdt_ohio.model.ModelState;
import org.ssdt_ohio.model.events.*;
import org.ssdt_ohio.usas.model.requisition.Requisition;
import org.ssdt_ohio.usas.model.vendor.Vendor;

rule "requisition vendor is required" 

	when
	    CreateObjectEvent() or UpdateObjectEvent()
    	ModelInformation(state != ModelState.IMPORTING, primary)
	    $requisition : Requisition(getVendor() == null)

    then
    	error(kcontext, "Requisition cannot be saved without a vendor")

end

Require that an account code be entered for each requisition line item when creating requisition

Name: org.districtname.RequisitionWithoutAccount 

...

Code Block
package org.ssdt_ohio.usas.model.requisition;
dialect "mvel"

import function org.ssdt_ohio.modules.rules.RulesHelper.*
import org.ssdt_ohio.model.events.*
import org.ssdt_ohio.model.ModelInformation
import org.ssdt_ohio.model.ModelState
import org.ssdt_ohio.usas.model.requisition.*
import org.ssdt_ohio.usas.model.accountChange.AccountChangeUpdateRules

rule "require accounts on requisitions"

	when
		CreateObjectEvent() or UpdateObjectEvent()
		ModelInformation(state != ModelState.IMPORTING, primary)
		not AccountChangeUpdateRules()
		$req : Requisition()
		RequisitionItem(charges.size() == 0) from $req.items

	then
		error(kcontext, "Expenditure Account is required")

end



Prevent Requisition from being created when the attention to field is blank

Name: org.districtname.RequisitionWithoutAttentionTo 
Description: Prevent requisition from being created when attention to is blank

Code Block
package org.districtName.RequisitionAttentionTo;
dialect  "mvel"

import function org.ssdt_ohio.modules.rules.RulesHelper.*
import org.ssdt_ohio.model.ModelInformation;
import org.ssdt_ohio.model.ModelState;
import org.ssdt_ohio.model.events.*;
import org.ssdt_ohio.usas.model.requisition.Requisition;
import org.ssdt_ohio.usas.model.vendor.Vendor;

rule "requisition vendor is required" 

	when
    	CreateObjectEvent() or UpdateObjectEvent()
    	ModelInformation(state != ModelState.IMPORTING, primary)
   		$requisition : Requisition(attention == null)

    then
    	error(kcontext, "Requisition must have valid attention field")

end


Prevent Requisition from being saved or updated when any of the item descriptions are null or are an empty string

Name: org.districtname.RequisitionItemsWithNoDescription

...

Code Block
package org.districtName.Requisition
dialect "mvel"

import function org.ssdt_ohio.modules.rules.RulesHelper.*
import org.ssdt_ohio.model.events.*
import org.ssdt_ohio.model.ModelInformation
import org.ssdt_ohio.model.ModelState
import org.ssdt_ohio.usas.model.requisition.*


rule "Requisition Items Must Have A Description"

	when
		$event : RepositoryModificationEvent(isCreate() || isUpdate())
		ModelInformation(state != ModelState.IMPORTING, primary)
		$requisition : Requisition() from $event.target
		$item : RequisitionItem(description == null || description.trim().length() == 0) from $requisition.getItems()

	then
		error(kcontext, "Requitistion item number: " + $item.lineNumber + ", units: " + $item.units +
		", quantity: " + $item.quantity + ", unit price: " + $item.unitPrice +
		" has no description from requisition: " + $requisition.description)

end


Require an amount on a Receipt item

Name: org.districtname.ReceiptItemsWithoutAmount

...