Jump to content

Scripted Find with calculated Set Field result


This topic is 3165 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hello All,

I want to script a find based on two fields.  One field is based on a global field and is used 'straight' - I mean the global field's value is "Wider Life" and I want to search for all records with the value "Wider Life"

I have another global field which is user selected {"Awaiting Confirmation"; "Confirmed"; "Rejected"}.  I need to convert this to a single letter {"A"; "C"; "R"} using a Case in a calculated result of a set field like this:

Go to Layout [ “CPD Attendance” (CPD Attendance) ]
Enter Find Mode [ ]
Set Field [ CPD::CPD Type ; CPD::gTypeFilter ]
Set Field [ CPD Attendance::CPD Confirmed ; Let ( [
$Txt = CPD Attendance::gConfirmFilter;
$Sym = Case (
$Txt="Confirmed"; "C";
$Txt="Rejected"; "R";
$Txt="Awaiting Confirmation"; "A";
"@")];
CPD Attendance::CPD Confirmed=$Sym) ]
Show Custom Dialog [ Title: "Find this in CPD_CONFIRMED field"; Message: $Sym; Default Button: “OK”, Commit: “Yes” ]
Perform Find [ ]

In the script debugger I can see that my temp variable $Sym has the value "A" as expected and the debugging custom dialogue returns "A" but the value "0" (Zero) is entered in the field for the find.  The field type is set as Text.

Any ideas what the problem is?  Thanks very much!

Ben

 

SShot.png

Edited by benmort81
Link to comment
Share on other sites

The problem is the result expression of your Let(); it doesn't return $sym, but the Boolean result (0 or 1) of a comparison between $sym and the original global field, and that result is entered as search criterion – while what you want is simply (the value of) $sym.

Note that you shouldn't create $vars in Let() without reason – and that declaring a $var in the result calculation of a Set Variable[] that creates a $var of the same name is confusing, to say the least …

You could change your script/calculation to

Set Variable [ $sym ; 
Let ( 
  theFilter = CPD Attendance::gConfirmFilter;
  Case (
    theFilter = "Confirmed" ; "C" ;
    theFilter = "Rejected" ; "R" ;
    theFilter = "Awaiting Confirmation"; "A";
    "@"
  )
)
]
Set Field [ CPD Attendance::CPD Confirmed ; $sym ] 
Show Custom Dialog [ … Message: $sym; … ]

 

Edited by eos
  • Like 1
Link to comment
Share on other sites

This topic is 3165 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.