create one formula for many conditional fields crystal

SOLVED

Hi...

I have 50 individual check box udfs in customer maintenance for each of the 50 states.  For each customer there could be many of the fields enabled.  I want to write a report showing each customer and which states are checked.  But I don't want to write 50 formulas saying if udf_AL is 'Y' then 'Alabama', if udf_AK is 'AK' then 'Alaska' and so on.  Can I just write one formula and combine all the fields that are 'Y' and show only those states that are enabled?

Thanks so much...

B

  • 0
    SUGGESTED

    Create a formula using Crystal Syntax as the following

    local stringvar state;

    if {AR_Customer.UDF_AL} = "N" then State := State + "Alabama" else State := State;
    if {AR_Customer.UDF_AK} = "N" then State := State + " Alaska" else state := State;

  • 0 in reply to Sage100Reports

    Thank you Sage Reports... The formula works for a few customers, but doesn't work for others... Not sure what it is I'm doing wrong.  I changed the "N" to "Y" as that didn't work either... Here is the formula I show... any ideas?

    local stringvar State;

    if {AR_Customer.UDF_AL} = "Y" then State := State + " " + "AL" else State := State;
    if {AR_Customer.UDF_AK} = "Y" then State := State + " " + "AK" else State := State;
    if {AR_Customer.UDF_AZ} = "Y" then State := State + " " + "AZ" else State := State;
    if {AR_Customer.UDF_AR} = "Y" then State := State + " " + "AR" else State := State;
    if {AR_Customer.UDF_CA} = "Y" then State := State + " " + "CA" else State := State;
    if {AR_Customer.UDF_CO} = "Y" then State := State + " " + "CO" else State := State;
    if {AR_Customer.UDF_CT} = "Y" then State := State + " " + "CT" else State := State;
    if {AR_Customer.UDF_DE} = "Y" then State := State + " " + "DE" else State := State;
    if {AR_Customer.UDF_FL} = "Y" then State := State + " " + "FL" else State := State;
    if {AR_Customer.UDF_GA} = "Y" then State := State + " " + "GA" else State := State;
    if {AR_Customer.UDF_HI} = "Y" then State := State + " " + "HI" else State := State;
    if {AR_Customer.UDF_ID} = "Y" then State := State + " " + "ID" else State := State;
    if {AR_Customer.UDF_IL} = "Y" then State := State + " " + "IL" else State := State;
    if {AR_Customer.UDF_IN} = "Y" then State := State + " " + "IN" else State := State;
    if {AR_Customer.UDF_IA} = "Y" then State := State + " " + "IA" else State := State;
    if {AR_Customer.UDF_KS} = "Y" then State := State + " " + "KS" else State := State;
    if {AR_Customer.UDF_KY} = "Y" then State := State + " " + "KY" else State := State;
    if {AR_Customer.UDF_LA} = "Y" then State := State + " " + "LA" else State := State;
    if {AR_Customer.UDF_ME} = "Y" then State := State + " " + "ME" else State := State;
    if {AR_Customer.UDF_MD} = "Y" then State := State + " " + "MD" else State := State;
    if {AR_Customer.UDF_MA} = "Y" then State := State + " " + "MA" else State := State;
    if {AR_Customer.UDF_MI} = "Y" then State := State + " " + "MI" else State := State;
    if {AR_Customer.UDF_MN} = "Y" then State := State + " " + "MN" else State := State;
    if {AR_Customer.UDF_MS} = "Y" then State := State + " " + "MS" else State := State;
    if {AR_Customer.UDF_MO} = "Y" then State := State + " " + "MO" else State := State;
    if {AR_Customer.UDF_MT} = "Y" then State := State + " " + "MT" else State := State;
    if {AR_Customer.UDF_NE} = "Y" then State := State + " " + "NE" else State := State;
    if {AR_Customer.UDF_NV} = "Y" then State := State + " " + "NV" else State := State;
    if {AR_Customer.UDF_NH} = "Y" then State := State + " " + "NH" else State := State;
    if {AR_Customer.UDF_NJ} = "Y" then State := State + " " + "NJ" else State := State;
    if {AR_Customer.UDF_NM} = "Y" then State := State + " " + "NM" else State := State;
    if {AR_Customer.UDF_NY} = "Y" then State := State + " " + "NY" else State := State;
    if {AR_Customer.UDF_NC} = "Y" then State := State + " " + "NC" else State := State;
    if {AR_Customer.UDF_ND} = "Y" then State := State + " " + "ND" else State := State;
    if {AR_Customer.UDF_OH} = "Y" then State := State + " " + "OH" else State := State;
    if {AR_Customer.UDF_OK} = "Y" then State := State + " " + "OK" else State := State;
    if {AR_Customer.UDF_OR} = "Y" then State := State + " " + "OR" else State := State;
    if {AR_Customer.UDF_PA} = "Y" then State := State + " " + "PA" else State := State;
    if {AR_Customer.UDF_RI} = "Y" then State := State + " " + "RI" else State := State;
    if {AR_Customer.UDF_SC} = "Y" then State := State + " " + "SC" else State := State;
    if {AR_Customer.UDF_SD} = "Y" then State := State + " " + "SD" else State := State;
    if {AR_Customer.UDF_TN} = "Y" then State := State + " " + "TN" else State := State;
    if {AR_Customer.UDF_TX} = "Y" then State := State + " " + "TX" else State := State;
    if {AR_Customer.UDF_UT} = "Y" then State := State + " " + "UT" else State := State;
    if {AR_Customer.UDF_VT} = "Y" then State := State + " " + "VT" else State := State;
    if {AR_Customer.UDF_VA} = "Y" then State := State + " " + "VA" else State := State;
    if {AR_Customer.UDF_WA} = "Y" then State := State + " " + "WA" else State := State;
    if {AR_Customer.UDF_WV} = "Y" then State := State + " " + "WV" else State := State;
    if {AR_Customer.UDF_WI} = "Y" then State := State + " " + "WI" else State := State;
    if {AR_Customer.UDF_WY} = "Y" then State := State + " " + "WY" else State := State;
    if {AR_Customer.UDF_DC} = "Y" then State := State + " " + "DC" else State := State;

    B

  • +1 in reply to beavis
    verified answer

    UDF's in Sage 100 are set to NULL when created and Crystal Reports doesn't play nice with NULLs.  Try something like this:

    if (not(isnull({AR_Customer.UDF_AL} )) and {AR_Customer.UDF_AL} = "Y" then ...

  • 0

    Select - Case would be a nice alternative to all of those if-then-else statements.

  • 0 in reply to BShockley

    I was about to say. Using the "Case" statement would be a lot better

  • 0 in reply to BigLouie

    I don't think a single Case statement would work, because each check needs to be done individually (building a text string), and it is my understanding that Case stops at the first match.

  • 0 in reply to Kevin M

    Most (if not all) of Sage 100's out of the box reports should have this option checked so checking for NULL shouldn't be necessary unless you created a brand new blank report and never checked it. 

    The option can be found under File > Report Options...

  • 0 in reply to Kevin M

    Doesn't the if - then - else statement stop at the first match as well?  

  • 0 in reply to BShockley

    Not this kind of formula, with semi-colon separated commands assigning values to a global variable.

  • 0 in reply to Kevin M

    Looks like a local variable to me.  Not too worried about it, but if this was my report, I would try a Select Case statement.  Don't really see the value of using a variable in this case.