Prepopulating edit form

I have the following case:

- Milestone-like interface for editing CDT (e.g. employee) in which first step is selecting one existing record from database:

- Based on that selection, I try to save expression rule result rule!EEDM_GetEmployeeById(ri!selectedEmployee) into rule input ri!employee when click NEXT button (part of my NEXT button code is given below):

 a!buttonWidget(
label: "Next",
value: local!activeStep + 1,
saveInto: {
local!activeStep,
a!save(
ri!employee,
if(
local!activeStep = 2,
rule!EEDM_GetEmployeeById(
ri!selectedEmployee
),
ri!employee
)
)...

- Values should then be prepopulated in edit form as my rule input ri!employee has values

Problem is I keep getting this error:

However, it seems that my categoryIcon field in ri!employee is correctly saved:

What is the cause?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Can you post the code for whichever dropdown or component uses the categoryIcon piece?  Also, when posting code like this, please use Insert --> Insert Code functionality found here to paste your code into a code box that will retain formatting and make the post/comment display a bit more friendly looking.

  • Thx for the instructions! In the meantime, I've realized I've made a mistake with my expression rule for retrieving employee data as I didn't cast it from dictionary to my CDT EEDM_Employee. Now, I've corrected it. This is my rule EEDM_GetEmployeeById:

     

    cast('type!{urn:com:mcom:eedm}EEDM_Employee?list',
      a!queryEntity(
      entity: cons!EEDM_EMPLOYEE_DATA_STORE_ENTITY,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "id",
              operator: "=",
              value: ri!id
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        )
      ),
      fetchTotalCount: false
    ).data)

    My save part:

     a!buttonWidget(
              label: "Next",
              value: local!activeStep + 1,
              saveInto: {
                local!activeStep,
                a!save(
                  ri!employee,
                  if(
                    local!activeStep = 2,
                    rule!EEDM_GetEmployeeById(
                      ri!selectedEmployee
                    ),
                    ri!employee
                  )
                ),

    Then I try to save it into a rule input ri!employee and I get new error:

    My categoryIcon field is now empty for some reason, even though it is populated in the database:

    rule input:

    expression rule result:

     

    This is the code that uses this field on the interface:

    a!imageField(
                        labelPosition: "ABOVE",
                        images: a!documentImage(
                          document: ri!employee.categoryIcon
                        ),
                        size: "MEDIUM",
                        isThumbnail: false,
                        style: "STANDARD"
                      )

Reply
  • Thx for the instructions! In the meantime, I've realized I've made a mistake with my expression rule for retrieving employee data as I didn't cast it from dictionary to my CDT EEDM_Employee. Now, I've corrected it. This is my rule EEDM_GetEmployeeById:

     

    cast('type!{urn:com:mcom:eedm}EEDM_Employee?list',
      a!queryEntity(
      entity: cons!EEDM_EMPLOYEE_DATA_STORE_ENTITY,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "id",
              operator: "=",
              value: ri!id
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        )
      ),
      fetchTotalCount: false
    ).data)

    My save part:

     a!buttonWidget(
              label: "Next",
              value: local!activeStep + 1,
              saveInto: {
                local!activeStep,
                a!save(
                  ri!employee,
                  if(
                    local!activeStep = 2,
                    rule!EEDM_GetEmployeeById(
                      ri!selectedEmployee
                    ),
                    ri!employee
                  )
                ),

    Then I try to save it into a rule input ri!employee and I get new error:

    My categoryIcon field is now empty for some reason, even though it is populated in the database:

    rule input:

    expression rule result:

     

    This is the code that uses this field on the interface:

    a!imageField(
                        labelPosition: "ABOVE",
                        images: a!documentImage(
                          document: ri!employee.categoryIcon
                        ),
                        size: "MEDIUM",
                        isThumbnail: false,
                        style: "STANDARD"
                      )

Children
  • +1
    Certified Lead Developer
    in reply to ivanm0004

    You shouldn't need to do that typecasting within the query expression rule - I've found it's only very rarely necessary, personally.  I don't see any way in which any of your initial issues were caused by that.  Since your button is saving it directly into the rule input which I assume is already cast to the CDT type, the casting would occur there anyway in this case.

    For the category icon - I'm not sure what's going on there but your image field definitely needs to handle the case of a null category icon, which it currently isn't.  On that note - you showed a screenshot of (i assume) "ri!categoryIcon", but your code is referencing ri!employee.categoryIcon - so i'm confused as to which one you intend to actually use.

  • So, this should also work (speaking of rule EEDM_GetEmployeeById)?

    a!queryEntity(
      entity: cons!EEDM_EMPLOYEE_DATA_STORE_ENTITY,
      query: a!query(
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "id",
              operator: "=",
              value: ri!id
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        )
      ),
      fetchTotalCount: false
    ).data

    If I switch to the inital code (without typecasting as you recommended) for expression rule, my CDT base rule input is populated correctly. However, old error shows up again on NEXT button click:

    My rule input is based on EEDM_Employee (my screenshot was a little bit confusing because I cut out only that part of CDT base rule input. Now other fields are masked):

    For image component, I'm aware I should handle NULL but it seems that this has nothing to do with my problem at the moment.

    Is there anything else I can send you here that can help with the error cause detection?

  • Nevermind, thank you for your answers! You've directed me into another way of thinking about my problem and I actually found out that I use the same ri!employee.categoryIcon in another a!save block before I've configured everything I need for that block to execute successfully.

    Note to myself: reusing code from other similar interfaces is dangerous Slight smile

  • 0
    Certified Lead Developer
    in reply to ivanm0004

    Cool, thanks for confirming.