0

Creative Suggestions Needed for styled() within a Formula

I plan to utilize the styled() function within a Formula for user alerts, messages, and details. The only way I know to achieve this is to create a separate Formula for each alert, if I want to display multiple at a time. Ideally, appending a single Formula for all alerts would be the best solution. 

 

Does anyone have any suggestions?

 

In the screenshot, the first field would be the desired result, with the separate formatting. Although, unfortunately, the only functional way I have found to return multiple alerts is to create a separate formula for each, adding lots of extra fields. 

 

On a side note, for anyone interested in achieving a similar result, I wrote a global function that can be called to easily return a banner message. See below:

#{ visual settings, alerts}#;
function banner(bannerType : text,bannerMessage : text) do
    let bt := lower(bannerType);
    if bt = "info" then
        let alertPrefix := "INFO: ";
        let alertText := alertPrefix + bannerMessage;
        let iconJSON := {
                filling: 0,
                weight: 400,
                icon: "info",
                color: "#0041a8"
            };
        let iconFormatted := icon(formatJSON(iconJSON));
        styled(alertText, "#d6e6ff", "#0041a8", iconFormatted)
    else
        if bt = "warning" then
            let alertPrefix := "WARNING: ";
            let alertText := alertPrefix + bannerMessage;
            let iconJSON := {
                    filling: 0,
                    weight: 400,
                    icon: "warning",
                    color: "#e66b00"
                };
            let iconFormatted := icon(formatJSON(iconJSON));
            styled(alertText, "#fff0db", "#e66b00", iconFormatted)
        else
            if bt = "alert" then
                let alertPrefix := "ALERT: ";
                let alertText := alertPrefix + bannerMessage;
                let iconJSON := {
                        filling: 0,
                        weight: 300,
                        icon: "priority_high",
                        color: "#cb2010"
                    };
                let iconFormatted := icon(formatJSON(iconJSON));
                styled(alertText, "#fcdad4", "#cb2010", iconFormatted)
            end
        end
    end
end

Then, you would just have to call the function:

banner("warning", "THIS IS A WARNING BANNER!")

 

Thanks, 

S Moore

2 replies

null
    • SMoore
    • yesterday
    • Reported - view

    Here a cleaner version in a case statement:

    #{ visual settings, alerts}#;
    function banner(bannerType : text,bannerMessage : text) do
        let bt := lower(bannerType);
        switch bt do
        case "info":
            (
                let alertPrefix := "INFO: ";
                let alertText := alertPrefix + bannerMessage;
                let iconJSON := {
                        filling: 0,
                        weight: 400,
                        icon: "info",
                        color: "#0041a8"
                    };
                let iconFormatted := icon(formatJSON(iconJSON));
                styled(alertText, "#d6e6ff", "#0041a8", iconFormatted)
            )
        case "warning":
            (
                let alertPrefix := "WARNING: ";
                let alertText := alertPrefix + bannerMessage;
                let iconJSON := {
                        filling: 0,
                        weight: 400,
                        icon: "warning",
                        color: "#e66b00"
                    };
                let iconFormatted := icon(formatJSON(iconJSON));
                styled(alertText, "#fff0db", "#e66b00", iconFormatted)
            )
        case "alert":
            (
                let alertPrefix := "ALERT: ";
                let alertText := alertPrefix + bannerMessage;
                let iconJSON := {
                        filling: 0,
                        weight: 300,
                        icon: "priority_high",
                        color: "#cb2010"
                    };
                let iconFormatted := icon(formatJSON(iconJSON));
                styled(alertText, "#fcdad4", "#cb2010", iconFormatted)
            )
        end
    
    • red_kite
    • yesterday
    • Reported - view

    An other idea with a dmulti-field. You can hide the dmulti in background. Display is the formulafield. Mirko