LaRetta Posted March 20, 2007 Posted March 20, 2007 Users work in Credit Memos in a new window. I want only a Close button. I want the script to test that each piece is done and branch depending upon the results. A Memo can't be Approved until it is Finished. It can't be Processed until it has been Approved. If everything is done, I want the window to simply close. As I list out the script, I realize there are many ways to write it. But I want elegant and I keep getting twisted in Else If[] and how to group the steps. Psuedo-script below: If [ Finished and Approved and Processed ] Close Window Halt Script Else If [ Approved ] Show Custom Dialog [ No ; Yes ; "Memo hasn't been Processed. Do now?"] If [ Get ( LastMessageChoice ) = 2 ] Set Field [ ProcessedBy ; Get ( AccountName ) ] Set Field [ ProcessDate ; Get ( CurrentDate ) ] End If Else If [ Finished ] Show Custom Dialog [ No ; Yes ; "Memo hasn't been Approved. Do now?"] If [ Get ( LastMessageChoice ) = 2 ] Set Field [ ApprovedBy ; Get ( AccountName ) ] Set Field [ ApproveDate ; Get ( CurrentDate ) ] End If Else Show Custom Dialog [ No ; Yes ; "Is this Memo Finished?"] If [ Get ( LastMessageChoice ) = 2 ] Set Field [ FinishedBy ; Get ( AccountName ) ] Set Field [ FinishDate ; Get ( CurrentDate ) ] End If Close Window I am asking because I can use a Case() statement within the Custom Dialog to combine them. But I'll still have to branch on the results because I'm using Set Field[]. The script has more tests but I used these three because they follow a sequence and I thought it would be clearer for reviewing. Ideas appreciated. I'm not totally comfortable with Else If[] yet either. LaRetta
Vaughan Posted March 20, 2007 Posted March 20, 2007 I don't have a problem with this. While I strive for elegance and brevity in scripts, theese goals are balanced with "transparency" which is the ability to easily see what the script does and how it does it. A question: is the Halt Script step after the Close Window step necessary? Will it ever run?
LaRetta Posted March 20, 2007 Author Posted March 20, 2007 Hi there Vaughan! In this instance, I have another running script which must be stopped; otherwise I would use Exit Script[]. Thank you for the input! L
Genx Posted March 20, 2007 Posted March 20, 2007 I'd personally use reps to make it easier... but otherwise maybe just get rid of the cust dialogs? If [ Finished and Approved and Processed ] Close Window Halt Script End If Set Variable[ $message ; Case( Approve ; "Memo hasn't been processed. Do now?" ; Finished ; "Memo hasn't been Approved. Do now?" ;"Is this Memo Finished?" ) ] Show Dialog[ No ; Yes ; $message ] Set Variable[ $choice ; Get(LastMessageChoice) ] If [ $choice = 2 and Approved ] Set Field [ ProcessedBy ; Get ( AccountName ) ] Set Field [ ProcessDate ; Get ( CurrentDate ) ] Else If [ $choice = 2 and Finished ] Set Field [ ApprovedBy ; Get ( AccountName ) ] Set Field [ ApproveDate ; Get ( CurrentDate ) ] Else If[ $choice = 2 ] Set Field [ FinishedBy ; Get ( AccountName ) ] Set Field [ FinishDate ; Get ( CurrentDate ) ] End If Close Window
LaRetta Posted March 20, 2007 Author Posted March 20, 2007 (edited) Thanks! Yes, this was the other direction I was considering. But I'd write it without the variables as: If [ Finished and Approved and Processed ] Close Window Halt Script End If Show Dialog[ No ; Yes ; "Memo hasn't been " & Case ( not Processed ; "Processed" ; not Approved ; "Approved"; "Finished" ) & ". Do it now?"] If [ Get ( LastMessageChoice ) = 2 and not Processed ] Set Field [ ProcessedBy ; Get ( AccountName ) ] Set Field [ ProcessDate ; Get ( CurrentDate ) ] Else If [ Get ( LastMessageChoice ) = 2 and not Approved ] Set Field [ ApprovedBy ; Get ( AccountName ) ] Set Field [ ApproveDate ; Get ( CurrentDate ) ] Else Set Field [ FinishedBy ; Get ( AccountName ) ] Set Field [ FinishDate ; Get ( CurrentDate ) ] End If Close Window It's getting better! Edited March 20, 2007 by Guest Added Not to tests
Genx Posted March 20, 2007 Posted March 20, 2007 ... Lol, i like variables -- no it's just a habit, i usually use message choices down the track in a script (sorry).
LaRetta Posted March 20, 2007 Author Posted March 20, 2007 (edited) No prob, Genx. I fight the old habit of creating globals to hold my work. :girlgiggle: I see I also copy/pasted the wrong Set Fields [] into it; but I'm sure it's clear to everyone. I'll correct it anyway. :wink2: Edited March 20, 2007 by Guest
Recommended Posts
This topic is 6460 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now