Reject Function

Certified Senior Developer

Hi,

Im new to using reject function. 

Now im using the reject function in a process model in a script task 

In the input : I am calculating a map which looks like this : 

{

   id : <>,

   account : <account_cdt(id, name, hold_code)> 

}

Now in the output tab I want to use reject function to reject all those accounts who have hold codes null ... but then my requirement is that the ID should remain in the output

I am using reject function like this : 

reject(

fn!isnull(_),

    a!forEach(

          items : ac!map,

          expression : {

                 id : fv!item.id,

                 holdCodes : index(index(fv!item, "account"), "hold_code")

          }

   )

)

Now I know this wont work, but can anyone suggest me how to make it work ? 

  Discussion posts and replies are publicly visible

Parents
  • I don't understand the purpose of removing holdCode from the cdt if it is null and only show the account id in that case.

    But if I can understand the requirement correctly then you will be wanting to implement it as follows:

    a!localVariables(
      local!map: {
        a!map(
          id: 1,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test", holdCode: "")
        ),
        a!map(
          id: 2,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test1", holdCode: "abcd")
        ),
        a!map(
          id: 3,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test2", holdCode: "")
        )
      },
      a!forEach(
        items: local!map,
        expression: if(
          isnull(
            index(fv!item, "account", "holdCode", null)
          ),
          updatedictionary(
            fv!item,
            { account: { id: fv!item.account.id } }
          ),
          fv!item
        )
      )
    )

  • 0
    Certified Senior Developer
    in reply to Sanchit Gupta (Xebia)

    Thanks for the solution

    But the purpose was not to remove the hold code ... The purpose was to just retain the map who actually has a hold code and ignore the ones that doesn't

  • 0
    Certified Lead Developer
    in reply to GautamShenoy
    but then my requirement is that the ID should remain in the output

    Then what about this that you have mentioned above in the description?

  • 0
    Certified Senior Developer
    in reply to Sanchit Gupta (Xebia)

    Sorry I framed the question wrong maybe ... I want the entire map to persist whose account have a hold code ... The other maps should be ignored .... Thanks for correcting and sorry for the error

  • +1
    Certified Lead Developer
    in reply to GautamShenoy

    Then, just make a slight change in the code.

    a!localVariables(
      local!map: {
        a!map(
          id: 1,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test", holdCode: "")
        ),
        a!map(
          id: 2,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test1", holdCode: "abcd")
        ),
        a!map(
          id: 3,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test2", holdCode: "")
        )
      },
      reject(
        isnull(_),
        a!forEach(
          items: local!map,
          expression: if(
            isnull(
              index(fv!item, "account", "holdCode", null)
            ),
            null,
            fv!item
          )
        )
      )
    )

    edit: Even simpler 

    a!localVariables(
      local!map: {
        a!map(
          id: 1,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test", holdCode: "")
        ),
        a!map(
          id: 2,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test1", holdCode: "abcd")
        ),
        a!map(
          id: 3,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test2", holdCode: "")
        )
      },
      remove(
        local!map,
        wherecontains(null, local!map.account.holdCode)
      )
    )

Reply
  • +1
    Certified Lead Developer
    in reply to GautamShenoy

    Then, just make a slight change in the code.

    a!localVariables(
      local!map: {
        a!map(
          id: 1,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test", holdCode: "")
        ),
        a!map(
          id: 2,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test1", holdCode: "abcd")
        ),
        a!map(
          id: 3,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test2", holdCode: "")
        )
      },
      reject(
        isnull(_),
        a!forEach(
          items: local!map,
          expression: if(
            isnull(
              index(fv!item, "account", "holdCode", null)
            ),
            null,
            fv!item
          )
        )
      )
    )

    edit: Even simpler 

    a!localVariables(
      local!map: {
        a!map(
          id: 1,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test", holdCode: "")
        ),
        a!map(
          id: 2,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test1", holdCode: "abcd")
        ),
        a!map(
          id: 3,
          account: 'type!{urn:com:appian:types:PA}PA_accountTemp'(id: 1, name: "test2", holdCode: "")
        )
      },
      remove(
        local!map,
        wherecontains(null, local!map.account.holdCode)
      )
    )

Children