Setting a value based on index?

Setting a value based on index?

Comments

  • Hello,

    If I have an array/list and I know which index I want to map data to, is there a way to do that without a foreach loop?

    Thanks,
    Jeremy

  • Hey there Jeremy!

    If you have an array youd like to map data to, you can use a "List Mapping Step".

    The list mapping step allows you to take in a list of data and map it appropriately to a specified output type.

    [img]att2[/img]

    You can see in the properties bar of the step that we have a list of inputs (in this case its a string list). Then I selected the output type to be "CarExample_FlowExtension". What this says is I want to map my list of strings into this data structure.

    With our inputs and output type figured out, we need to click the Show Item Mapping Editor action on the top of the properties bar.

    In our item mapping editor, we will see the flow data properties available in the left hand column and the output type on the right.

    Heres what eliminates the need for a ForEach loop; its the _INPUT on the left side. You see how it says [String] and this is because its a single item from the list we mapped in on the parent flow designer. Since I want to send this to a specific column on my CarExample_FlowExtension data structure, I selected "Build Data" and mapped it into the desired field.

    [img]att1[/img]

    Ive then successfully added that string to user defined data structure (of course this can be applied to other data types, this was just an example).

  • What if I wanted to do it on the fly. So lets say I ran a foreach loop on an array and I find a result I am looking for at index 45, I have the get index feature of the foreach loop so that value is available to me, now I want to manipulate a different list at the same index . Can I do that without a second foreach loop ?

  • I found it, there is a "Get Item by Index" step that I overlooked

  • If the two arrays are in the same order, you should be able to use the Get Item by Index step. It will ask you to input the item and the index the item is being pulled from.

    [color=rgb(127, 140, 141)][font=Roboto]"[img]att1[/img]"[/font][/color]

  • Hmmm but is there a way to Map data by index? Or to tell it to change value of an index on output
    [i]edited by Jeremy on 2/28/2020[/i]

  • So to confirm, you want to isolate an individual item based on its index and change that items values? Give this post a look, it should be the answer to your question if I understand it correctly!

    [url=https://support.decisions.com/forum/topic2346-changing-a-specific-item-within-a-list.aspx]https://support.decisions.com/forum/topic2346-changing-a-specific-item-within-a-list.aspx[/url]

    Basically, we utilize a Index of Item in list to get the index, Get Item by Index, then use a Create Data step in order to manipulate that isolated data.

Sign In or Register to comment.