This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event-BeforeSave.absl
executable file
·68 lines (56 loc) · 2.77 KB
/
Event-BeforeSave.absl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Add your SAP Business ByDesign scripting language implementation for:
Business Object: CustomerInvoice
Node: CustomerInvoice
Event: BeforeSave
Note:
- To access the elements of the business object node,
use path expressions, for example, this.<element name>.
- To use code completion, press CTRL+J.
- This script file is mass-enabled, i.e. the keyword "this"
refers to a collection of node instances.
- The solution uses this script when:
- the instance of the business object is being saved.
- the instance of the business object is created from other sources like web services, preview screen, and so on.
*/
import ABSL;
import AP.Common.GDT;
//Mass enabled for best performance - Create an event for each instance of CustomerInvoice
var eventList : collectionof BusinessObjectEvent;
var invoice : CustomerInvoice;
foreach(invoice in this)
{
//Prepare the event data structure
var eventRoot : elementsof BusinessObjectEvent;
//determine if it is Add or Update event.
var eventType = EventTypeCode.CO_01_ADD;
//if(CustomerInvoice.Retrieve(invoice.UUID).IsSet())
//If the invoice ID already exist,then it is an Update.
if(!invoice.ID.IsInitial())
eventType = EventTypeCode.CO_02_UPDATE;
//Determine Release or Approve or Reject event by comparing the ReleaseStatusCode and ApprovalStatusCode
//of invoice instance in cache against the invoice instance loaded from DB
var invoiceFromDB = CustomerInvoice.Retrieve(invoice.UUID);
if(!invoice.ID.IsInitial() && invoiceFromDB.IsSet() && !invoiceFromDB.ID.IsInitial())
{
//Important Note: This block of code is not working as expected. As a result,
//it is not possible to elaborate the event type Release, Approve and Reject from Update.
//ReleaseStatusCode: 3 - Released
//From non-released to released, then it is an Release event
if(invoiceFromDB.Status.ReleaseStatusCode != "3" && invoice.Status.ReleaseStatusCode == "3")
eventType = EventTypeCode.CO_05_RELEASE;
//ApprovalStatusCode: 4 - Approved
//From non-approved to Approved, then it is an Approve event
if(invoiceFromDB.Status.ApprovalStatusCode != "4" && invoice.Status.ApprovalStatusCode == "4")
eventType = EventTypeCode.CO_06_APPROVE;
//ApprovalStatusCode: 5 - Rejected
//From non-rejected to rejected, then it is an Reject event
if(invoiceFromDB.Status.ApprovalStatusCode != "5" && invoice.Status.ApprovalStatusCode == "5")
eventType = EventTypeCode.CO_07_REJECT;
}
eventRoot = EventReuseLibrary.CreateEvent(eventType, "004", invoice.UUID, invoice.ID.content, "Root", invoice.NodeID, EventPublisherCode.CO_00_INTERNAL);
//Create an instance of event
var instEvent;
instEvent = BusinessObjectEvent.Create(eventRoot);
eventList.Add(instEvent);
}