Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By Marvin
#825837
Hello,

I have a grid named GDOrder used to record Sales, where:
Qty | Desc | Price

I need to copy it to another grid say, ITEMDesc where for each item a unique identification code needs to be inserted.

Example - GDOrder
2 Laptop $3,000
3 Printer $1,500

Item is expanded in ITEMDesc
# | Desc | Price | UID
Row1 Laptop $3,000 xxxx-xxxx-xxxx
Row2 Laptop $3,000 xxxx-xxxx-xxxx
Row3 Printer $1,500 xxxx-xxxx-xxxx
Row4 Printer $1,500 xxxx-xxxx-xxxx
Row5 Printer $1,500 xxxx-xxxx-xxxx

Help much appreciated.
User avatar
By amosbatto
#825874
You didn't explain how the unique ID numbers are being obtained, so I will give you an example using auto-incrementing IDs:
Code: Select all
@=ITEMDesc = array(); //create an empty grid

if (is_array(@=GDOrder)) {
   $rowNo = 1;
   $id = rand(0, 1000);

   foreach (@=GDOrder as $aOrder) {
      $quantity = $aOrder['Qty'];

      for ($i=1; $i <= $quantity; $i++) {
           @=ITEMDesc[ $rowNo ] = array(
              "No" => $rowNo,
              "Desc" => $aOrder['Desc'],
              "Price" => $aOrder['Price'],
              "UID" => $id + $rowNo 
           );
           $rowNo++;
      }
   }        
}
Make sure that the grid variables and the IDs in the grid fields are spelled exactly as listed in the above code.
By Marvin
#825889
Dear Sir Amosbatto,

You are a legend. It works!!! Thanks.

I just removed the auto-generating ID since the keys are actually provided by outside suppliers.
I shall keep it in mind for future use.
Task doesnt have any users.

Amosbatto: One more thing if you can help me with.[…]

Just guide me to implement this?

Hi, I have a text control (rfq_segment) and I wan[…]

Genial!!! gracias. :D i need to translate an[…]