Hi community,
Hope everyone is doing well.
This is my first blog post, so please bear with me 🙂
Sometime ago, I’ve faced a requirement where a customer wanted to copy information from a custom BO embedded in a Ticket TI screen, using the standard “Copy” functionality.
Therefore, in this blog post I’ll show to you how I’ve achieved this requirement.
Assumptions
- Custom BO and Ticket have the same ID;
- Not possible to create a stand-alone Custom BO instance.
In standard Ticket UI, via adaptation mode
- Create a KUT field to maintain the Ticket ID that was copied. Note: KUT Fields are also copied when Action-> ‘Copy’ is used. Therefore, it will act as a temporary variable which will hold Ticket ID, working as a Reference ID:
Custom BO
- AlternativeKey of Custom BO must be the Ticket ID.
- Create a Reference ID, to maintain the ID which data was copied.
- [Optional] Create a CreatedOn field, to use as validation field.
- In CustomBO beforeSave event, create a logic to get data from the reference ID, if any (here, it will work as a copy for custom BO fields) and copy to the new instance (here you can put some validation to do this only during custom BO creation, for example):
if(!this.TicketID.IsInitial()){
var getTicketData = ServiceRequest.Retrieve(this.TicketID);
if(getTicketData.IsSet()){
if(!getTicketData.KUT_CopiedTicketReference.IsInitial()){
this.ReferenceID.content = getTicketData.KUT_CopiedTicketReference;
this.ReferenceID.content.RemoveLeadingZeros();
}
}
}
if(this.CreatedOn.content.IsInitial()){
if(!this.ReferenceID.IsInitial() && this.ReferenceID.content != this.TicketID.content.RemoveLeadingZeros()){
var ticketCustomRef = TicketCustomData.Retrieve(this.ReferenceID.RemoveLeadingZeros());
if(ticketCustomRef.IsSet()){
this.Integer1 = ticketCustomRef.Integer1;
this.String1 = ticketCustomRef.String1;
this.String2 = ticketCustomRef.String2;
}
}
this.CreatedOn = Context.GetCurrentSystemDateTime();
}
Embedded Component
- Create an Embedded Component.
- In Data Model tab:
- Bind the Custom BO to the Root:
- Create an Inport Data Structure and add a data field to maintain the incoming Ticket ID.
- Add desired fields to the Data Model.
- In Data Model tab:
-
- In Controller tab:
- Create an Inport;
- Add the incoming parameter from standard screen;
- Set “RequestFireOnInitialization” to true;
- Create an Event Handler to be triggered OnFire;
- In Controller tab:
-
-
- EventHandler will perform a BOOperation to read or create a Custom BO instance:
-
-
-
- DataOperation to assign Inport Ticket ID to Custom Ticket ID:
-
-
-
- Save action:
-
Standard Screen
- Bind Embedded Component to standard screen (here, I’ve added the EC in Ticket Overview screen):
Ticket beforeSave event
- Copy the ticket ID to the created KUT Field. Here I’ve put a condition to fulfill the field only during ticket creation:
foreach (var ticket in this){
if(ticket.SystemAdministrativeData.CreationDateTime == ticket.SystemAdministrativeData.LastChangeDateTime){
//if field is not populated, copy the ticket id to it
if(ticket.KUT_CopiedTicketReference.IsInitial()){
ticket.KUT_CopiedTicketReference = ticket.ID.content.RemoveLeadingZeros();
}
}
}
Basically, with these steps, when Ticket is created, KUT field in Ticket Header and Reference ID from Custom BO are filled with created Ticket ID. When user executes “Copy” in Ticket actions, KUT Field is copied to the new ticket, with the ID from the copied ticket. For example, ticket with ID 1 is created (KUT field will be populated with 1). By performing a copy, KUT field is copied to the new ticket (ID = 2), working as a reference to the copied ticket. The same will work for the Custom BO data, as we have a reference ID into it.
Test
After Ticket creation, KUT field is filled with Ticket ID:
Custom BO instance is created:
After performing a “Copy” action in the Ticket, a new ticket is created with Custom BO information:
If needed, I can change the data from the new custom BO instance (745) that will not impact the reference instance (743).
Conclusion
With these steps, you are now able to copy data from a custom BO that is linked to a standard BO. This could be useful when you are not able to simply create a node with extension fields (due to number of fields, for example) and need to create custom BOs to maintain fields.