0

If possible, adapt the script.

for in 'Article Name'. 'Products' do
  // Verify that the required fields exist and are valid
  if Product.'Cost Price' > 0 and product.Markup != null then

    // Increase markup by 15%
    Product.Markup := Product.Markup * 1.15;

    // Recalculate sales price (rounded to 2 decimal places)
    product.'Sale Price' := round(Product.'Costo Price' * (1 + (Product.Markup / 100)), 2);

    // Save Changes
    update product;
  else
    // Error log
    log('Error en producto ID: ' + product.id +
        ' | Costo: ' + toText(product.Costo) +
        ' | Markup: ' + toText(product.Markup));
  end
end

5 replies

null
    • Rafael Sanchis
    • Rafael_Sanchis
    • 4 days ago
    • Reported - view

    do as server
        for loop in select Products where 'Cost Price' > 0 and 'Markup %' != null do
            loop.('Markup %' := number(loop.'Markup %') + 0.5)
        end
    end

    Works 

      • Rafael Sanchis
      • Rafael_Sanchis
      • 4 days ago
      • Reported - view
      let response := true;
      if response then
          do as server
      
              let updatedCount := 0;
      
              for loop in select Products where 'Cost Price' > 0 and 'Markup %' != null do
                  loop.('Markup %' := number(loop.'Markup %') + 0.5);
                  updatedCount := updatedCount + 1;
              end;
      
              if updatedCount > 0 then
                  alert(updatedCount + " productos actualizados exitosamente.");
              else
                  alert("No se encontraron productos para actualizar.");
              end;
          end
      end
      

      The Alert's don't working some idea?

      • Ninox partner
      • RoSoft_Steven.1
      • 4 days ago
      • Reported - view

       alerts don't work in a do as server scope

    • John_Halls
    • 3 days ago
    • Reported - view

    Hi Rafael

    Why do you have these lines?

    let response := true;
    if response then
    

    Regards John

      • Rafael Sanchis
      • Rafael_Sanchis
      • 3 days ago
      • Reported - view

       Thanks John I eliminate this 2 lines and works.