Your script has a lot of If blocks that will never execute due to their expressions being enclosed in /* comment brackets */
This will happen when you import your script from another file (or copy/paste the script steps) and they are not valid in the new context. So your script would appear to have a lot of problems here unless you deliberately commented them to temporarily disable those portions of your script.
But what you describe does not necessarily need any script at all.
Example 1, define a calculation field:
If ( Invoice::Status = "Sold" ; Globals::gSoldContainer ; Globals::gAvailableContainer )
Be sure to select "Container" as the result type and you would put this calculation field on your layout. Your two sold/available graffics would be inserted into the two global fields referenced here.
Example 2, Put the images into separate records of a related table. Set __pkImageID in this table to 1 for the Sold graphic and 2 for the Available graphic.
Define a relationship: Invoices::_fkAvailabilityKey = AvailabilityImages::__pkImageID
Put AvailabilityImages::ContainerField on your Invoices layout.
Then your script can set Invoices::_fkAvailabilityKey to 1 to show the sold graphic and set it to 2 to show the Available graphic.
Or define _fkAvailabilityKey as a calculation field:
If ( Invoice::Status = "Sold" ; 1 ; 2 )
Also, i have since managed to get this to work with a button and script combo..
I guess I could do a button that does the same but back wards to make an artwork available again. What would be cool would to make an artwork status change from sold to available when it is removed from an invoice.
Tried this is my remove artworks script but it doesn't seem to work. any ideas?
You are aware that the If block at the top of your script will never execute?
What layout is current when the Go To Related Records (GTRR) script step executes? On what table occurrence is it based?
GTRR followed by other script steps that modify data in the found set of records produced by the GTRR can be dangerous to your data integrity if there is any possibility that the GTRR might execute when there are no related records to "go to". In such cases, the script continues to the next step and performs it just as though there were no GTRR script step in your script--possibly modifying the wrong record(s).
In such cases, you should either use an If step to check for the existence of related records before doing the GTRR or use an If step to check for an error code immediately after the GTRR.
thanks, yes that's ok, I don't use the invoice concluded bit.
The script (and GTRR) is starting from an invoice layout. Attached is a pic of my relationships if that helps.
In theory all artworks should have a status at all times, so I'm not too concerned about no related records.
The value of Status does not determine whether there are any related records in Artworks for a given record in Invoices. That will be determined by the values in Invoices::ID and Artwork::Id_Invoice.
"Doesn't seem to work" does not tell me much. HOW doesn't it work?
Does the status field of the correct record get set to "available" when this script executes?
Can't there be more than one record in Artworks linked to a given invoice?
Your script only modifies the status field of a single record and it would do the same even if you removed the GTRR step as the relationship will allow it to modify the very same record--so long as this executes from a layout that shows "Invoices" in "Show Records From" found in Layout Setup... (Which is the very same requirement for GTRR to work in this script.)
Thanks, the status field does not change when the script is executed.
Yes there can be more than one record in artworks linked to a given invoice but I am using a fairly simple portal which lists them.
ah, its working now. I just moved it all up a few lines.
on a simliar note, i'm trying to make an artworks "SOLD" when it is added to an invoice. Trying to slot similar steps in the script but it doesn't affect the status yet. Any ideas?