0

Some Help

let opt := dialog("Transfer data", "Select what you want to transfer", ["Cancel", "Major Project", "Small Project"]);
let count := 0;
if opt != "Cancel" then
    for a in select 'Activities List' do
        if opt = "Major Project" and a.Type_Project = 1 or
            opt = "Small Project" and a.Type_Project = 2 then
            let e := (create 'Estimate Budget');
            " Asignación de campos ";
            e.(IDCod := a.IDCod);
            e.(Activities := a.Activities);
            e.('Group Work' := a.'Group Work');
            e.(Discipline := a.Discipline);
            " Horas según tipo de proyecto ";
            if a.Type_Project = "Major Project" then
                e.(Hours := a.'Major Hrs')
            end;
            if a.Type_Project = "Minor Project" then
                e.(Hours := a.'Minor Hrs')
            end;
            count := count + 1
        end
    end;
    alert("Transfer completed.\ Records copied: " + text(count))
end

 

 

The Type_Project is a Multiple choice dyn with 2 option (Major Project and Small Project)

Something is wrong.

Only copie the Small Project 

The problem is the same with Mulriple Choice or Muktiole Choice dyn

7 replies

null
    • Fred
    • 3 days ago
    • Reported - view

    Multi- choice (simple or dynamic) can return an array of selections. The best way to deal with it is to use the contains() command.

            if (opt = "Major Project" and contains(a.Type_Project, 1)) or
                (opt = "Small Project" and contains(a.Type_Project, 2)) then
    

    Also you might want to try to put parenthesis around the grouping.  

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

       Hi Fred

      Function is not defined: contains(dmulti,number) at line 5, column 68

      Give me this error

      • Fred
      • 3 days ago
      • Reported - view

       sorry, forgot numbers().

              if (opt = "Major Project" and contains(numbers(a.Type_Project), 1)) or
                  (opt = "Small Project" and contains(numbers(a.Type_Project), 2)) then
      
      • Rafael Sanchis
      • Rafael_Sanchis
      • 2 days ago
      • Reported - view

       

      let opt := dialog("Transfer data", "Select what you want to transfer", ["Cancel", "Major Projects", "Small Projects"]);
      let count := 0;
      if opt != "Cancel" then
          for a in select 'Activities List' do
              let shouldCopy := false;
              let projectType := number(a.Type_Project);
              if opt = "Major Projects" and (projectType = 1 or projectType = 3) then
                  shouldCopy := true
              end;
              if opt = "Small Projects" and (projectType = 2 or projectType = 3) then
                  shouldCopy := true
              end;
              if shouldCopy then
                  let e := (create 'Estimate Budget');
                  e.(IDCod := a.IDCod);
                  e.(Activities := a.Activities);
                  e.('Group Work' := a.'Group Work');
                  e.(Discipline := a.Discipline);
                  " Copiar horas según la opción seleccionada ";
                  if opt = "Major Projects" then
                      e.('Hours Est' := a.'Major Hrs')
                  end;
                  if opt = "Small Projects" then
                      e.('Hours Est' := a.'Minor Hrs')
                  end;
                  count := count + 1
              end
          end;
          alert("Transfer completed. Records copied: " + text(count))
      end
      

      I don't know if the best option but work. Thanks

    • John_Halls
    • yesterday
    • Reported - view

    Hi 

    I hope you don't mind me looking at your code. I see it as a challenge to make it as succinct as possible and I have come up with

    let options := ["Cancel", "Major Projects", "Small Projects"];
    let opt := index(options, dialog("Transfer data", "Select what you want to transfer", options));
    if opt then
       let b := select 'Activities List' where number(Type_Project) = opt or number(Type_Project) = 3;
       for a in b do
           (create 'Estimate Budget').(
           IDCod := a.IDCod;
           Activities := a.Activities;
           'Group Work' := a.'Group Work';
           Discipline := a.Discipline;
           'Hours Est' := if opt = 1 then a.'Major Hrs' else a.'Minor Hrs')
       end;
       alert("Transfer completed. Records copied: " + count(b))
    end
    

    So what's going on here?

    Lines 1 & 2 By defining the options in an array and using the index() function the variable opt now equals 0, 1, or 2

    Line 3, by design if 0 is false, and if 1 or if 2 is true

    Line4  opt can now be used in the select

    Line 11 Use the if in the value assigned

    Regards John

      • Rafael Sanchis
      • Rafael_Sanchis
      • yesterday
      • Reported - view

       

      Thanks John, much clear and half the code. I appreciate your help. 👍

      • John_Halls
      • yesterday
      • Reported - view

      My pleasure

Content aside

  • Status Answered
  • yesterdayLast active
  • 7Replies
  • 43Views
  • 3 Following