need to update nested cdt column data

Certified Senior Developer

Hi

i have a process variable called request_data which is cdt type and in that there was one column called casettnotes which is a cdt casenotes cdt has currently 4 rows of data in that there was a column casenote which i need to update which is 4th row case note column data for this i dont have primary value it was null so i tried using other column which is issuetype like if issuetype is failed then update casenot for that issue type like that, all i want the casenote column which is 4th row column in casettnotes cdt need to be updated how to acheive this tried using many alforeach with update function but nothing working kindly suggest on this

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I tried to replicate your issue with map.
    Try it once for your CDT and let me know if that works for you.

    a!localVariables(
      local!request_data: a!map(
        requestId: 123,
        requestType: "Service Request",
        casettnotes: {
          a!map(
            id: null, 
            issuetype: "pending", 
            casenote: "First case note - pending review",
            createdDate: today()-3
          ),
          a!map(
            id: null, 
            issuetype: "approved", 
            casenote: "Second case note - approved by manager",
            createdDate: today()-2
          ),
          a!map(
            id: null, 
            issuetype: "review", 
            casenote: "Third case note - under review",
            createdDate: today()-1
          ),
          a!map(
            id: null, 
            issuetype: "failed", 
            casenote: "Fourth case note - THIS NEEDS UPDATE",
            createdDate: today()
          )
        }
      ),
    
      local!newNoteValue: "UPDATED: Fourth row has been successfully modified",
    
      local!updatedData: a!update(
          local!request_data,
          "casettnotes",
          a!forEach(
            items: local!request_data.casettnotes,
            expression: if(
              /* Condition: Update 4th row OR where issuetype = "failed" */
              or(
                fv!index = 4,
                fv!item.issuetype = "failed"
              ),
              a!update(
                fv!item,
                "casenote",
                local!newNoteValue
              ),
              fv!item
            )
          )
        ),
      
      local!updatedData
    )

Reply
  • 0
    Certified Lead Developer

    I tried to replicate your issue with map.
    Try it once for your CDT and let me know if that works for you.

    a!localVariables(
      local!request_data: a!map(
        requestId: 123,
        requestType: "Service Request",
        casettnotes: {
          a!map(
            id: null, 
            issuetype: "pending", 
            casenote: "First case note - pending review",
            createdDate: today()-3
          ),
          a!map(
            id: null, 
            issuetype: "approved", 
            casenote: "Second case note - approved by manager",
            createdDate: today()-2
          ),
          a!map(
            id: null, 
            issuetype: "review", 
            casenote: "Third case note - under review",
            createdDate: today()-1
          ),
          a!map(
            id: null, 
            issuetype: "failed", 
            casenote: "Fourth case note - THIS NEEDS UPDATE",
            createdDate: today()
          )
        }
      ),
    
      local!newNoteValue: "UPDATED: Fourth row has been successfully modified",
    
      local!updatedData: a!update(
          local!request_data,
          "casettnotes",
          a!forEach(
            items: local!request_data.casettnotes,
            expression: if(
              /* Condition: Update 4th row OR where issuetype = "failed" */
              or(
                fv!index = 4,
                fv!item.issuetype = "failed"
              ),
              a!update(
                fv!item,
                "casenote",
                local!newNoteValue
              ),
              fv!item
            )
          )
        ),
      
      local!updatedData
    )

Children
  • 0
    Certified Senior Developer
    in reply to Shubham Aware

    thank you so much for code 

    casetnotes cdt has many columns like more that 20 do i need map every column could you please confirm? 

  • 0
    Certified Lead Developer
    in reply to dharanik2600

    No!  a!update() only modifies the fields you specify and automatically preserves all other columns unchanged.

  • 0
    Certified Lead Developer
    in reply to Shubham Aware

    If you want to update 20 columns i would recommend below approach

    a!localVariables(
      local!request_data: a!map(
        requestId: 123,
        requestType: "Service Request",
        casettnotes: {
          a!map(
            id: null,
            issuetype: "pending",
            casenote: "First note",
            status: "open",
            priority: "low",
            assignedTo: "user1",
            department: "IT",
            category: "Hardware",
            subcategory: "Laptop",
            createdDate: today() - 3,
            createdBy: "john.doe",
            modifiedDate: null,
            modifiedBy: null,
            resolution: null,
            resolutionDate: null,
            escalationLevel: 0,
            reviewerNotes: null,
            approvalStatus: "pending",
            attachmentId: null,
            ticketNumber: "TKT-001",
            customerEmail: "customer1@test.com",
            customerPhone: "123-456-7890",
            location: "Building A",
            urgencyReason: null
          ),
          a!map(
            id: null,
            issuetype: "approved",
            casenote: "Second note",
            status: "in_progress",
            priority: "medium",
            assignedTo: "user2",
            department: "HR",
            category: "Access",
            subcategory: "Badge",
            createdDate: today() - 2,
            createdBy: "jane.smith",
            modifiedDate: today() - 1,
            modifiedBy: "admin",
            resolution: null,
            resolutionDate: null,
            escalationLevel: 1,
            reviewerNotes: "Under review",
            approvalStatus: "approved",
            attachmentId: 12345,
            ticketNumber: "TKT-002",
            customerEmail: "customer2@test.com",
            customerPhone: "234-567-8901",
            location: "Building B",
            urgencyReason: "New employee"
          ),
          a!map(
            id: null,
            issuetype: "review",
            casenote: "Third note",
            status: "on_hold",
            priority: "high",
            assignedTo: "user3",
            department: "Finance",
            category: "Software",
            subcategory: "License",
            createdDate: today() - 1,
            createdBy: "bob.wilson",
            modifiedDate: null,
            modifiedBy: null,
            resolution: null,
            resolutionDate: null,
            escalationLevel: 2,
            reviewerNotes: "Awaiting approval",
            approvalStatus: "review",
            attachmentId: 67890,
            ticketNumber: "TKT-003",
            customerEmail: "customer3@test.com",
            customerPhone: "345-678-9012",
            location: "Building C",
            urgencyReason: "Budget approval needed"
          ),
          a!map(
            id: null,
            issuetype: "failed",
            casenote: "OLD NOTE - NEEDS UPDATE",
            status: "open",
            priority: "low",
            assignedTo: "user4",
            department: "Operations",
            category: "Other",
            subcategory: "General",
            createdDate: today(),
            createdBy: "alice.jones",
            modifiedDate: null,
            modifiedBy: null,
            resolution: null,
            resolutionDate: null,
            escalationLevel: 0,
            reviewerNotes: null,
            approvalStatus: "pending",
            attachmentId: null,
            ticketNumber: "TKT-004",
            customerEmail: "customer4@test.com",
            customerPhone: "456-789-0123",
            location: "Building D",
            urgencyReason: null
          )
        }
      ),
      local!updates: a!map(
        casenote: "RESOLVED: Issue has been fixed and verified",
        status: "resolved",
        priority: "critical",
        assignedTo: "senior.manager",
        department: "IT-Security",
        category: "Security",
        subcategory: "Access Violation",
        modifiedDate: now(),
        modifiedBy: loggedInUser(),
        resolution: "Access restored after security review",
        resolutionDate: today(),
        escalationLevel: 3,
        reviewerNotes: "Escalated to management and resolved",
        approvalStatus: "completed",
        attachmentId: 99999,
        urgencyReason: "Critical security issue - immediate action taken"
      ),
      local!updatedData: a!update(
        local!request_data,
        "casettnotes",
        a!forEach(
          items: local!request_data.casettnotes,
          expression: if(
            fv!index = 4,
            a!localVariables(
              local!mergedData: updateDictionary(fv!item, local!updates),
              local!mergedData
            ),
            fv!item
          )
        )
      ),
      local!updatedData
    )