Skip to main content
naomis0001
December 20, 2021
Solved

Get current object

  • December 20, 2021
  • 9 replies
  • 0 views

Here is my expression:

a!localVariables(
  /* Loop checks against passed in value of type to pull values
     from specific requirementActivity match */
  a!forEach(
    items: ri!requirement.requirementActivities, 
    expression: 
    if(contains(ri!activityType, fv!item.type),
    'type!{urn:com:appian:types:UW}UW-Requirement-Activity'(
      key: fv!item.key,
      type: fv!item.type,
      creatorId: fv!item.creatorId,
      creatorFullName: fv!item.creatorFullName,
      createdDate: fv!item.createdDate,
      commentText: fv!item.commentText
    ), 
    {}), 
  ),
),

activityType is Text Array
snippet of rule in play:
local!requirements: {
        a!forEach(
          items: local!requirementsResponse,
          expression: a!localVariables(
            local!receivedRequirementActivity: rule!UW_GetRequirementActivityByType(
              requirement: fv!item,
              activityType:  "RECEIVED"
            ),
            local!waivedOrAcceptedRequirementActivity: rule!UW_GetRequirementActivityByType(
              requirement: fv!item,
              activityType: {
                "WAIVED",
                "ACCEPTED"
              }
            ),
            a!map(
              type: property(
                fv!item,
                "name",
                {}
              ),
              status: property(
                fv!item,
                "status",
                {}
              ),
              orderDate: property(
                fv!item,
                "createdTimestamp",
                {}
              ),
              orderRep: property(
                fv!item,
                "requestedBy",
                {}
              ),
              receiveDate: property(
                local!receivedRequirementActivity,
                "createdDate",
                {}
              ),
              receiveRep: property(
                local!receivedRequirementActivity,
                "creatorFullName",
                {}
              ),

It works great unless their are duplicate ActivityTypes - I need to return the current ActivityType and I'm rather new to Appian development and having a time sorting out how to handle this. What is currently happening is the fields: creatorFullName: fv!item.creatorFullName & createdDate: fv!item.createdDate in my table are populating every associated date and creator returned that's associated with the activityType. 

I've been searching the docs and I'm just not really finding a direction to go. Any guidance would be greatly appreciated.

    Best answer by peter.lewis

    I'd suggest doing a few steps:

    1. Move your queries up out of the a!forEach() for local!requirements into the top level and query all the requirement activity for all requirementResponses so that you're only running one query instead of one for each response. This should improve the performance by reducing the number of queries executed.
    2. Update your local!requirementsResponse within the a!forEach() to return the requirements that relate to the given response. I typically do this using the displayvalue() function because it allows you to match an item from your response to your activity list.
    3. At this point you're still likely returning a list of values for each response and you need to return only the most recent. I'd use the index() function to return only the first item from each list to ensure you only display one value.

    I know that's a pretty high level, but hopefully that at least can get you started - of course feel free to ask any questions as you're going!

    One other thing to mention - my suggestion was primarily for keeping the same data model as you currently have. If you are using something like synced records it would actually be much easier to do this because there is a function for a!relatedRecordData() that lets you directly define the properties for your activites. Some app developers also prefer to set up this logic in a database view, because you can use any of the functions that SQL offers to get your data in the format you need.

    9 replies

    danny.verb
    December 20, 2021

    Can you describe from a higher level what you're trying to accomplish? 

    naomis0001
    December 20, 2021

    I am populating an interface grid with data being called from our api - I am successfully sorting an array of objects by type "activityType" and displaying related data to the in the grid. However when we have objects with the same type the grid is being populated with all createdDates and CreaorFullName that matches that type. Example of what is occurring (this is sample data) So in this instance below I had 3 activities with the same TYPE of RECEIVED resulting in the below. 

    peter.lewis
    Employee
    December 20, 2021

    Can you describe your data model? From what you're saying, it sounds to me like you have a 1:M relationship between the source record and some of the data displayed in your columns for Date Received and Received By. If that's the case, do you want to display all of the related records or only a subset? Also could you post the expression of the entire grid instead of only the snippets above?