0

If, then 2 criteria

Hi, As always, I'm guessing this is a simple fix and my limited skills with coding are the problem here.

I am trying to configure a choice field to trigger on update and adjust a choice field in certain records on a separate table based on a specific criteria.

I need the trigger to activate when a specific choice is selected but only update the choice fields of the connected records if a yes/no field is set to yes on them.

Currently, I can easily change the status on all of the selected records but I am unable to filter out the records with the yes/no set to no.

I have tried using Switch but see the same results.

An example of the very basic code I have set is below:

if Status = 3 or Orders.'Assets 2'.'In shipment'= true then
    Orders.'Assets 2'.(Status := 4)
else
    if Status = 4 or Orders.'Assets 2'.'In shipment'= true then
        Orders.'Assets 2'.(Status := 1)
    end
end

Apologies that I have not supplied much more detail but I am hoping that this is a simple fix and I don't want to waste anyone's time adding too much detail.

Thanks in advance for any assistance

7 replies

null
    • szormpas
    • yesterday
    • Reported - view

     Hi, try this:

    switch true do
      case Status = 3 and Orders.'Assets 2'.'In shipment'= true:
        Orders.'Assets 2'.(Status := 4)
      case Status = 4 and Orders.'Assets 2'.'In shipment'= true:
            Orders.'Assets 2'.(Status := 1)
    end
    
      • Rob
      • yesterday
      • Reported - view

       Hi, many thanks for taking the time to have a look at this. I have tried your code but now nothing changes as opposed to everything changing :-)

      I'm currently trying all this on a copy of the live DB which might be making it more complicated. I'll create a simple new one and try your code again.

      Thanks again for your suggestion

    • Rob
    • yesterday
    • Reported - view

    OK, so the only thing I can work out is that the "and" "or" operators are tripping me up. Using and produces no change, using or changes everything, which makes sense to me as I have confirmed one of the criteria but not both. Hmmmmm I'll keep trying

      • szormpas
      • yesterday
      • Reported - view

        Hi,

      can you try also the following:

      let x := Status;
      for i in Orders.'Assets 2' do
        switch true do
          case (x = 3 and i.'In shipment'):
                  i.(Status := 4)
          case (x = 4 and i.'In shipment'):
                  i.(Status := 1)
        end
      end
      
      • Rob
      • yesterday
      • Reported - view

       That's it!!! 😄 Works exactly the way I need it to, I cant thank you enough for that.

      It's been 2 days of trial and error. Your solution will allow me to move forward on a project that I have needed to complete for 3 years so again, thank you so much for your support, very much appreciated.

      • szormpas
      • yesterday
      • Reported - view

        I'm glad you figured it out!

      • szormpas
      • 7 hrs ago
      • Reported - view

        Hi, you can make the above code even better

      let x := switch Status do
                  case 3:
                     4
                  case 4:
                     1
               end;
      Orders.'Assets 2'['In shipment'].(Status := x);
      

Content aside

  • Status Answered
  • 7 hrs agoLast active
  • 7Replies
  • 32Views
  • 2 Following