Not able to populate data from nested CDT on grid

Hello,

 

I have array of CDT within CDT. When I'm trying to populate data from that array to grid column I'm getting blank value with index function.

CDT Structure:

 

Datasubset value:[ userAssignedRequestName="test",
      users=[userName=dc_creator, email=dc_creator@bankcorp.com, phone=410-858-8811, firstName=test User, lastName=, status=active, role=xxxx, lastUserAction=creator];
            [userName=dc_modifier, email=dc_modifier@bankcorp.com, phone=410-858-8812, firstName=test User2, lastName=, status=active, role=xxxx, lastUserAction=modifier]]; 

Below code is not returning user array:

  a!gridTextColumn(
                  label: "User Name",
                  field: "lastUpdatedUserId",
                  data: rule!REST_getLastUpdatedUser(
                    index(                           
                              local!datasubset.data,
                             "users",
                             {}
                           )                  
                        )
                   ),

above highlighted code is not returning users array. Can anyone faced this issue with nested CDT ?

inside rule rule!REST_getLastUpdatedUser I have logic to return particular user name.

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    Hi couple of quick questions here:

    1. May I know, which entity is being queried by REST_getLastUpdatedUser rule ?

    2. Did you try indexing the other field i.e. userAssignedRequestName instead of users? If so, did you get your expected data?

    3. Did you try executing this rule independently? What was the return type of this rule?
  • is REST_getLastUpdatedUser expecting a singular user? Or an array of users? Does it return a user or an array of users?
  • Hi Alok,

    Below is the REST_getLastUpdatedUser. Input is users array and out put is single userName text. This rule works fine independently.

    load(
    local!updatedUser: index(ri!dcrUserDetails,wherecontains("creator",ri!dcrUserDetails.lastUserAction)),
    if(rule!PFDC_isBlank(local!updatedUser),{},local!updatedUser.userName)
    )

    Thanks,
    Tushar
  • Hi Robert,

    Below is the REST_getLastUpdatedUser. Input is users array and out put is userName text. This rule works fine independently.

    load(
    local!updatedUser: index(ri!dcrUserDetails,wherecontains("creator",ri!dcrUserDetails.lastUserAction)),
    if(rule!PFDC_isBlank(local!updatedUser),{},local!updatedUser.userName)
    )

    Thanks,
    Tushar
  • Also indexing of other fields works perfectly fine. I think other fields are just single text and not cdt array that's why it works.
  • Hi Tushar,

    I am suspecting that "you have already applied data while fetching the datasubset in query entity". Please remove data in index and tried the below.

     a!gridTextColumn(

                     label: "User Name",

                     field: "lastUpdatedUserId",

                     data: rule!REST_getLastUpdatedUser(

                       index(                          

                                 local!datasubset,

                                "users",

                                {}

                              )                  

                           )

                      ),

     

    below code is working for me (For time being I have hard coded values)

    load(
    local!data: {
    userAssignedRequestName: "test",
    users: {
    {
    userName: "dc_creator",
    email: "dc_creator@bankcorp.com",
    phone: "410-858-8811",
    firstName: "test User",
    lastName: "",
    status: "active",
    role: "xxxx",
    lastUserAction: "creator"
    },
    {
    userName: "dc_modifier",
    email: "dc_creator@bankcorp.com",
    phone: "410-858-8811",
    firstName: "test User",
    lastName: "",
    status: "active",
    role: "xxxx",
    lastUserAction: "modifier"
    }
    }
    },
    local!pagingInfo: topaginginfo(
    1,
    - 1
    ),
    a!gridField(
    label: "Grid",
    totalCount: 2,
    columns: {
    a!gridTextColumn(
    label: "User Name",
    field: "lastUpdatedUserId",
    data: index(
    local!data,
    "users",
    {}
    )
    )
    },
    value: local!pagingInfo,
    saveInto: local!pagingInfo

     

    Thanks

    Siva Chimata

  • Hi

    This is what you have mentioned in one of your replies..

    "Below is the REST_getLastUpdatedUser. Input is users array and out put is userName text. This rule works fine independently."

     

    If you are expecting single text to be displayed as it is in grid you need to wrap it with curly braces.

     

    a!gridTextColumn(
    label: "User Name",
    field: "lastUpdatedUserId",
    data: {
                rule!REST_getLastUpdatedUser
                (
                    index(local!datasubset.data,"users",{})
                )
            }
    )

     

    Regards,

    Mayur Mondhe

  • Hi tushark171

     

    Try below code, it will return as you expected and modify your rule accordingly.

     

    rule!R_Expr_ReturnFirstUserName(ri!arrayValues)  arrayValues (Any Type)

     

    if(

      rule!APN_isEmpty(

        ri!arrayValues

      ),

      ri!arrayValues,

      ri!arrayValues[1].userName

    )

     

    ===================================================

     rule!R_SailGrid_UsersList

     

    load(

      local!pagingInfo: a!pagingInfo(

        startIndex: 1,

        batchSize: 2

      ),

      local!data: {

        userAssignedRequestName : "test",

        users: {

          {

            userName : "dc_creator",

            email : "dc_creator@bankcorp.com",

            phone : "410-858-8811",

            firstName : "test User",

            lastName : "",

            status : "active",

            role : "xxxx",

            lastUserAction : "creator"

          },

          {

            userName : "dc_modifier",

            email : "dc_creator@bankcorp.com",

            phone : "410-858-8811",

            firstName : "test User",

            lastName : "",

            status : "active",

            role : "xxxx",

            lastUserAction : "creator"

          }

        }

      },

      with(

        local!datasubset: fn!todatasubset(

          local!data,

          local!pagingInfo

        ),

        a!gridField(

          totalCount: local!datasubset.totalCount,

          columns: {

            a!gridTextColumn(

              label: "userAssignedRequestName",

              field: "userAssignedRequestName",

              data: index(

                local!datasubset.data,

                "userAssignedRequestName",

                {}

              )

            ),

            a!gridTextColumn(

              label: "users",

              field: "users",

              data: a!forEach(

                local!datasubset.data,

                rule!R_Expr_ReturnSingleValue(

                  a!flatten(

                    index(

                    fv!item,

                    "users",

                    null

                  )

                  )             

                )

              )

            ) },

          value: local!pagingInfo,

          saveInto: local!pagingInfo

        )

      )

    )

  • Hi Siva,

    Thanks for above suggestion. It's not working by just using datasubset.
    When I print my datasubset it gives me below values:

    [startIndex=1, batchSize=50, sort=[field=lastUpdatedDateTime, ascending=false], totalCount=3, data=[ userAssignedRequestName="Test1", users=[userName=dc_creator, email=dc_creator@bankcorp.com, phone=410-858-8811, firstName=Jean1, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=creator]; [userName=dc_modifier, email=dc_modifier@bankcorp.com, phone=410-858-8811, firstName=Jean2, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=modifier]; [userName=dc_approver, email=dc_approver@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=approver]; [userName=dc_applier, email=dc_applier@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=applier]];
    [userAssignedRequestName="Test2", users=[userName=dc_creator, email=dc_creator@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=creator]; [userName=dc_modifier, email=dc_modifier@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=modifier]; [userName=dc_approver, email=dc_approver@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=approver]; [userName=dc_applier, email=dc_applier@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=applier]];
    [userAssignedRequestName="Test3", users=[userName=dc_creator, email=dc_creator@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=creator]; [userName=dc_modifier, email=dc_modifier@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=modifier]; [userName=dc_approver, email=dc_approver@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=approver]; [userName=dc_applier, email=dc_applier@bankcorp.com, phone=410-858-8811, firstName=Jean-Luc, lastName=, status=active, role=PFDC_DATA_CORRECTION_TEAM, lastUserAction=applier]], identifiers=1; 2; 3]

    when I try to print just index( local!datasubset.data, "userAssignedRequestName",{} ) it gives me Test1;Test2;Test3
    when I try to print index( local!datasubset.data, "users",{} ) it gives me nothing

    when I modified my rule "REST_PFDC_getLastUpdatedUser" as below it prints "Empty User" for first row and Blank in other rows.

    if(rule!PFDC_isBlank(ri!dcrUserDetails),"Empty User","User1")
  • Hi Mayur,

    I tried this but it's not working. I have mentioned datasubset structure in reply to Siva.

    Thanks,
    Tushar