0

HELP! What is wrong with my code? Trigger after update problems

I have a multiple choice field with two options; 'Salvage' and 'Staff Purchase'.

I have the code set up to create a line in another table when 'Salvage' is selected, and delete it if not (thanks to Dean again, if you're reading this).

However, I'm trying to make it more complicated by having the option repeat but with a different table if 'Staff Purchase' is selected.

This is my code currently:

let key := this;
if 'Salvage SP' = 1 then
let p := Part;
let d := 'Damage Type';
let c := Comment;
let s := Specification;
let r := Cost;
let t := (create Salvage);
'Salvage Primary Key' := t.Id;
t.(Frameset := key);
t.('Part / Item' := p);
t.('Damage Type' := d);
t.(Comment := c);
t.(Specification := s);
t.(RRP := r)
else
if 'Salvage SP' = 0 or 2 then
let pk := 'Salvage Primary Key';
delete (select Salvage where Id = pk)
else
if 'Salvage SP' = 2 then
let p := Part;
let d := 'Damage Type';
let c := Comment;
let s := Specification;
let r := Cost;
let t := (create 'Staff Purchases');
'Staff Purchases Primary Key' := t.Id;
t.(Frameset := key);
t.('Part / Item' := p);
t.('Damage Type' := d);
t.(Comment := c);
t.(Specification := s);
t.(RRP := r)
else
if 'Salvage SP' = 0 or 1 then
let pk := 'Staff Purchases Primary Key';
delete (select 'Staff Purchases' where Id = pk)
end
end
end
end

 

When I select 'Salvage' it creates a line in that table as planned, and when I deselect it, it deletes it, all good. 

The 'Staff Purchase' selection is not working at all however.

Either my code is wrong somewhere, or I'm trying to do too much functionality in this one trigger (likely both)...can anyone help please? Thanks!

5 replies

null
    • Anna_Wenlock
    • 3 yrs ago
    • Reported - view

    Never mind, I have figured a way around it!

    • Karen_Estrada
    • 3 yrs ago
    • Reported - view

    Anna, if you don't mind ... what did you need to do? If it's too time-consumming to reply don't worry about it. I've had your thread bookmarked so I could check back periodically to see answers/suggestions, I was just curious. Thanks! Karen

    • Anna_Wenlock
    • 3 yrs ago
    • Reported - view

    Hi Karen,

    I had a button that when clicked created a line in table2 using the data from table1. I was trying to expand on this by having a choice field instead of a button, and then different choices resulted in the same data from table1 creating a line in different table e.g. 

    if option1 selected then create line in table2 but if option2 selected then create line in table3

    (not code above, just the logic)

    I also wanted it to delete the line created if the choice is changed/unselected.

    I can't seem to get it to work like that, so have settled for having two buttons, each just taking care of its part of the logic. So one button creates a line in table1 if true and deletes it again if false, and the other button does table2 in the same way. Not as neat as I would like it, but it solved the problem for now.

    I hope this makes sense?

    • Karen_Estrada
    • 3 yrs ago
    • Reported - view

    Hi Anna, thanks! Yes it does!

    ===

    I'm going to take a look at this tomorrow <my brain is on strike refusing to code anymore tonight ... /> ... I remember having a hard time with something similar so I need to check my "Notes" dB to see if I finally did figure it out ... I have a feeling I gave up on it temporarily but hopefully not.

    If I have something that could be helpful I'll definitely post it here! Karen

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    I am not sure to fully understand what you want to do, but here are a few things that seem to need attention.

    if 'Salvage SP' = 0 or 2 then -> if 'Salvage SP' = 0 or 'Salvage SP' = 2 then

    if 'Salvage SP' = 0 or 1 then -> if 'Salvage SP' = 0 or 'Salvage SP' = 1 then

    Does the general structure of your script correspond to what you want it to do?

    if 'Salvage SP' = 1 then
      >>>> Executed when 'Salvage SP' = 1
    else
      if 'Salvage SP' = 0 or 'Salvage SP' = 2 then
        >>>> Executed when 'Salvage SP' = 0 or 'Salvage SP' = 2
      else
        if 'Salvage SP' = 2 then
          >>>> Never executed
        else
          if 'Salvage SP' = 0 or 'Salvage SP' = 1 then
            >>>> Never executed
          end
        end
      end
    end

Content aside

  • 3 yrs agoLast active
  • 5Replies
  • 691Views