Notes
Notes - notes.io |
<import>
<DataChange public-id="bc:AssociateTicketsViaJoin">
<ExternalReference>Associate_TroubleTickets_Through_Join_Table</ExternalReference>
<Description>Associate trouble tickets with policies using TroubleTicketJoinEntity</Description>
<Status>OPEN</Status>
<Script><![CDATA[
uses gw.api.database.Query
uses gw.api.database.Relop
uses gw.transaction.Transaction
uses entity.PolicyPeriod
uses entity.TroubleTicket
uses entity.TroubleTicketJoinEntity
var resultWriter = DataChange.util.ResultWriter
resultWriter.append("== Trouble Ticket Association Started ==n")
// ===== TICKET-TO-POLICY MAPPING =====
// Add your specific ticket number -> policy number mappings here
var ticketPolicyMappings = {
"TT000001" -> "H0MN0000022385", // Format: "TroubleTicketNumber" -> "PolicyNumber"
"TT000002" -> "H0MN0000022390",
"TT000003" -> "H0MN0000022400"
// Add all your mappings in this format
}
// ====================================
try {
var processed = 0
var succeeded = 0
var failed = 0
// Process each ticket-policy mapping
ticketPolicyMappings.eachKeyAndValue( ticketNumber, policyNumber -> {
processed++
resultWriter.append("nProcessing Ticket ${ticketNumber} -> Policy ${policyNumber}n")
// 1. Find Trouble Ticket by TroubleTicketNumber
var troubleTicket = Query.make(TroubleTicket)
.compare(TroubleTicket#TroubleTicketNumber, Relop.Equals, ticketNumber)
.select()
.AtMostOneRow
if (troubleTicket == null) {
resultWriter.append("!! ERROR: TroubleTicket ${ticketNumber} not foundn")
failed++
return
}
// 2. Find PolicyPeriod by PolicyNumber
var policyPeriod = Query.make(PolicyPeriod)
.compare(PolicyPeriod#PolicyNumber, Relop.Equals, policyNumber)
.select()
.AtMostOneRow
if (policyPeriod == null) {
resultWriter.append("!! ERROR: PolicyPeriod ${policyNumber} not foundn")
failed++
return
}
// 3. Check if association already exists in TroubleTicketJoinEntity
var existingJoin = Query.make(TroubleTicketJoinEntity)
.compare("TroubleTicket", Relop.Equals, troubleTicket)
.compare("PolicyPeriod", Relop.Equals, policyPeriod)
.select()
.AtMostOneRow
if (existingJoin != null) {
resultWriter.append("✓ Association already exists in TroubleTicketJoinEntityn")
resultWriter.append(" - Join Entity ID: ${existingJoin.PublicID}n")
succeeded++
return
}
// 4. Create new association in TroubleTicketJoinEntity
try {
Transaction.runWithNewBundle( bundle -> {
// Create new TroubleTicketJoinEntity
var newJoin = new TroubleTicketJoinEntity(bundle)
// Set the required fields directly (bypassing private setters)
newJoin.TroubleTicket = troubleTicket
newJoin.PolicyPeriod = policyPeriod
// Set other required fields if needed (based on your entity definition)
// newJoin.Account = policyPeriod.Account
// newJoin.Policy = policyPeriod.Policy
resultWriter.append("✓ Created new TroubleTicketJoinEntity associationn")
resultWriter.append(" - TroubleTicket: ${troubleTicket.TroubleTicketNumber}n")
resultWriter.append(" - PolicyPeriod: ${policyPeriod.PolicyNumber}n")
resultWriter.append(" - Policy: ${policyPeriod.Policy.PolicyNumber}n")
resultWriter.append(" - Account: ${policyPeriod.Account.AccountNumber}n")
}, "su") // Run as super user to bypass permissions
succeeded++
} catch (e: Exception) {
resultWriter.append("!! ERROR creating association: ${e.Message}n")
resultWriter.append("!! ERROR Details: ${e.StackTraceAsString}n")
failed++
}
})
// 5. Summary Report
resultWriter.append("n" + "="*50 + "n")
resultWriter.append("ASSOCIATION SUMMARY:n")
resultWriter.append("Processed: ${processed}n")
resultWriter.append("Succeeded: ${succeeded}n")
resultWriter.append("Failed: ${failed}n")
if (failed > 0) {
resultWriter.append("n!! SOME ASSOCIATIONS FAILED - CHECK ERRORS ABOVE !!n")
} else {
resultWriter.append("n✓ ALL ASSOCIATIONS COMPLETED SUCCESSFULLYn")
}
resultWriter.append("="*50 + "n")
} catch (e: Exception) {
resultWriter.append("!! GLOBAL ERROR: ${e.Message}n")
resultWriter.append("!! StackTrace: ${e.StackTraceAsString}n")
}
resultWriter.append("== Ticket Association Completed ==n")
]]></Script>
</DataChange>
</import>
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
