Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Overview

Admins can use Pulsar Settings to implement Validation Rules and Triggers for the following execution points:

1. OnCreate 

2. BeforeEdit

3. BeforeSave

4. OnSave

5. BeforeDelete

6. OnDelete

7. onBarcodeScan

Validation Rules and Trigger execution points are composed of three "post-action" execution points, OnCreate, OnSave, and OnDelete, where the create, save, or delete action has occurred or is certain to occur, and three "pre-action" execution points, BeforeEdit, BeforeSave, and BeforeDelete, where conditions can be validated before the actions occur. The differences between Validation Rules and Triggers actually have to do with the actions taken within the setting. Validation Rules will contain Alert actions that inform the user of a failed condition. Triggers will often update the current record or other records with no user interaction. Validation Rules and Triggers can be combined in Pulsar, and all of the logic for a particular object type and execution point can be contained in a single setting. 

Usage

The Validation Rules and Triggers are defined using Pulsar Settings Language (PSL). The general format for such a setting is as follows:

Name:  Object Name – execution point
Key:     pulsar.<executionPoint>.<ObjectAPIName>
Value:  Pulsar Settings Language

One exception to this format is the OnCreate setting, which can have one of the following formats:

Name:  Object Name – execution point
Key:     pulsar.onCreate.<Parent Object API Name>.<Child Object API Name>
Value:  Pulsar Settings Language

or

Name:  Object Name – execution point
Key:     pulsar.onCreate.<Parent Object API Name>.<Child Object API Name>.PreInit
Value:  Pulsar Settings Language

The first version (without PreInit) runs immediately after the object is created, but before the object is committed to the database (before other save triggers have a chance to run). The second version (PreInit), runs before the object is created, in case there are trigger actions that must occur before the new child object can be created, perhaps to ensure certain values are passed to the create action.

Example Validation Rule

Name:   Order - Before Edit
Key:      pulsar.beforeEdit.Order__c
Value:   See the code below. This setting executes when the user tries to edit a record, and uses a query to determine if the user attempted to update a record that is already in status "Finalized" or "Cleared". If so, it alerts the user with the appropriate message.

DEFAULT{ 
Action=SetVar; 
VarName=Order_Id; 
VarValue=@@CurrentObjectId; 
| 
Action=SqlQuery; 
QueryString=SELECT Id FROM Order__c WHERE Id = '%%Order_Id%%' AND Status__c IN ('Cleared','Finalized'); 
QueryReturnFields=@@QueryCount; 
QueryTest=%%QueryCount%%=0; 
QueryTestTrue=SUCCESS; 
| 
Action=Alert; 
Message=Update is not allowed on Orders with status finalized, or cleared.; 
} 
SUCCESS 
{ 
}

Example Trigger

Name: On Save – Order Line Item

Key: pulsar.onSave.Order_Line_Item__c
Value:   See the code below. The following example  runs the code to update the total amount (Sub_Total__c) on the Order object when a line item is updated. This update is committed to the database when this setting executes, and this change will be pushed to the server upon the next sync. Note that this Trigger setting does not include any failure states (Alert actions).

DEFAULT{
Action=SetVar;
VarName=Order_Id;
VarValue=Order__c;
|
Action=SqlQuery;
QueryString=Select SUM ( CAST( Amount__c AS REAL ) ) AS SUM_ORDER_AMOUNT FROM Order_Line_Item__c WHERE Order__c = ‘%%Order_Id%%’;
QueryReturnFields=SUM_ORDER_AMOUNT;
|
Action=SqlQuery;
QueryString=Update Order__c SET Sub_Total__c = ‘%%SUM_ORDER_AMOUNT%%’ WHERE Id = ‘%%Order_Id%%’;
}

 

Example Barcode Scanner Setting

Name: On Barcode – Opportunity

Key: pulsar.onBarcodeScan.Opportunity

Note that there is another setting that first needs to be enabled for the user to see the scan barcode icon on a record. (pulsar.layout.enableBarcodeScanner. Refer to that setting on Layout View Settings).

 

DEFAULT{ 
Action=SetVar; 
VarName=ScanCode; 
VarValue=@@CurrentScanCode; 
| 
Action=SetVar; 
VarName=UserId; 
VarValue=@@CurrentUserId; 
| 
Action=SetVar; 
VarName=CurrentDate; 
VarValue=@@Today; 
| 
Action=SqlQuery; 
QueryString=select (CASE WHEN length('%%ScanCode%%') = 0 THEN 1 ELSE 0 END) as emptyScanCode; 
QueryReturnFields=emptyScanCode; 
QueryTest=%%emptyScanCode%%=1; 
QueryTestTrue=BARCODE_SCANNER_ERROR; 
| 
Action=SqlQuery; 
QueryString=select Id from Store_Asset__c where Scan_Code__c = '%%ScanCode%%' LIMIT 1; 
QueryReturnFields=@@QueryCount, Id AS AssetId; 
QueryTest=%%QueryCount%%<=0; 
QueryTestTrue=ASSET_NOT_FOUND; 
| 
Action=CreateAndMapFields; 
ObjectType=Task; 
ActionShouldComplete=TRUE; 
ActionShouldDisplay=FALSE; 
OwnerId=%%UserId%%; 
WhatId=%%AssetId%%; 
Status="Completed"; 
Subject="Post Call Auto Create"; 
ActivityDate=%%CurrentDate%%; 
| 
Action=Alert; 
Message="Successfully logged the asset"; 
AlertType=DismissCurrentWindow; 
} 

ASSET_NOT_FOUND{ 
Action=Alert; 
Message=No Asset matching %%ScanCode%% is found in the database; 
} 

BARCODE_SCANNER_ERROR{ 
Action=Alert; 
Message=Please point the camera at the code and wait for the scanner to display the number; 
} 
  • No labels