Difference in load() with () and other functions

A Score Level 1

Hi folks,

Can anyone please tell me the difference between load(),with(), a!localvariable and a!refreshvariable functions. In what different scenarios are all these used. Is a!localvariable replacement of load and with both ?

It would be better if someone explain them using a code snippet.

  Discussion posts and replies are publicly visible

Parents Reply Children
  • Because you can't assign a value to a local!variable from within the scope of the a!forEach() - or, if you can, I'm not seeing how that's done. Here's what I've just experimented with. First is what works using a with():

    a!localVariables(
      local!myNestedArray: {
        {
          {record: 1, attributes: {"A","B","C"}},
          {record: 2, attributes: {"D","E","F"}}
        },
      },
      a!forEach(
        items: local!myNestedArray,
        expression: with(
          local!currentItem: concat("SJB/", fv!item.record),
          a!forEach(
            items: fv!item.attributes,
            expression: {
              local!currentItem,
              fv!item
            }
          )
        )
      )
    )

    ...and secondly here's what I've tried to do just using local!variables (which I can't get to work):

    a!localVariables(
      local!myNestedArray: {
        {
          {record: 1, attributes: {"A","B","C"}},
          {record: 2, attributes: {"D","E","F"}}
        },
      },
      local!currentItem: null,
      a!forEach(
        items: local!myNestedArray,
        expression: {
          local!currentItem: fv!item.record,
          a!forEach(
            items: fv!item.attributes,
            expression: {
              local!currentItem,
              fv!item
            }
          )
        }
      )
    )

    Arguably (and I might take that position for more a more sophisticated transformation in the inner loop) you'd have a helper rule. And maybe that's best practice, but I'm always (!) suspicious when someone is definitive in their reply! ;-)

  • 0
    Certified Lead Developer
    in reply to Stewart Burchell

    Found your problem... you replaced with(), with nothing, instead of a!localVariables()...

    should be:

    a!localVariables(
      local!myNestedArray: {
        {
          {record: 1, attributes: {"A","B","C"}},
          {record: 2, attributes: {"D","E","F"}}
        },
      },
      local!currentItem: null,
      a!forEach(
        items: local!myNestedArray,
        expression: a!localVariables(
          local!currentItem: fv!item.record,
          a!forEach(
            items: fv!item.attributes,
            expression: {
              local!currentItem,
              fv!item
            }
          )
        )
      )
    )