Announcement

Collapse
No announcement yet.

array_insert issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    array_insert issue

    I am running into something that I can't really figure out or even explain. A very simplified version of the code and the result is below, it is dropping the first result for some reason.

    Code:
    <MvASSIGN NAME = "l.discos" VALUE = "{ miva_array_deserialize( Module_Product_Field_Value( l.module, Items.d.product_id, 'raves' ) ) }" />
    
    <MvFOREACH ITERATOR = "disco" ARRAY = "discos">
        <MvASSIGN NAME = "l.ok" VALUE = "{ miva_array_insert( l.disco_list, l.disco, -1 ) }" />
    </MvFOREACH>
    Custom Field = A,B,C
    l.discos = A,B,C
    l.disco_list = B,C
    Chris Dye
    http://www.kseriesparts.com

    #2
    First thing I would try is to make sure l.discos has three array elements by evaluating miva_array_elements(l.discos)

    Also, you may want to consider simply assign l.disco_list the l.discos array instead of going around with the miva_Array_insert...
    Code:
    <MvASSIGN NAME = "l.disco_list" VALUE = "{ l.discos }" />
    M.A.D.* since 1997

    http://www.scotsscripts.com

    *miva application developers

    Comment


      #3
      array_elements does produce the correct number.

      I tried the direct assign and that produces the same result missing the first value.
      Chris Dye
      http://www.kseriesparts.com

      Comment


        #4

        Ok, I just noticed you're not scoping your variables. When using miva script you have to scope variables, it's not like mvt code. Try this:
        Code:
          
        <MvFOREACH ITERATOR = "l.disco" ARRAY = "l.discos">    
          <MvASSIGN NAME = "l.ok" VALUE = "{ miva_array_insert( l.disco_list, l.disco, -1 ) }" />
        </MvFOREACH>
        M.A.D.* since 1997

        http://www.scotsscripts.com

        *miva application developers

        Comment


          #5
          looks the same, am I missing something?
          Chris Dye
          http://www.kseriesparts.com

          Comment


            #6
            Look at the mvforeach. I put l.disco and l.discos and you had disco and discos
            M.A.D.* since 1997

            http://www.scotsscripts.com

            *miva application developers

            Comment


              #7
              My quick test using your original code output the values as expected. I'd double check what's actually being returned from your custom field call.
              Code:
              <MvASSIGN NAME = "l.discos" VALUE = "{ miva_array_deserialize( '[1]=A,[2]=B,[3]=C' ) }" />
              
              <MvFOREACH ITERATOR = "disco" ARRAY = "discos">
                  <MvASSIGN NAME = "l.ok" VALUE = "{ miva_array_insert( l.disco_list, l.disco, -1 ) }" />
              </MvFOREACH>
              
              <MvEVAL EXPR = "{ l.disco_list }">
              output
              Code:
              A,B,C
              David Carver
              Miva, Inc. | Software Developer

              Comment


                #8
                Originally posted by Scot - ScotsScripts.com View Post
                Look at the mvforeach. I put l.disco and l.discos and you had disco and discos
                Thanks! That seems to have cleared it up and doing more testing on it now.
                Chris Dye
                http://www.kseriesparts.com

                Comment


                  #9
                  Originally posted by Scot - ScotsScripts.com View Post
                  Look at the mvforeach. I put l.disco and l.discos and you had disco and discos
                  Thanks again, testing does appear to have it on track now!
                  Chris Dye
                  http://www.kseriesparts.com

                  Comment

                  Working...
                  X