Skip to main content
trungt2435
New Participant
Jul 5, 2023 3:47 PM UTC
Question

Displaying an Image from External API on Interface Load ?

Hi,

I want to display an image from an external API call. Currently, I can achieve this on the interface using a button, but it is not ideal. The user wants to load this image from the API on interface/page load without the need to click on the button. Is it possible? Below is the current call I use for the button. thank you.

a!buttonArrayLayout(
buttons: {
a!buttonWidget(
label: "View API Image",
saveInto: rule!GI_APIExternal_itemImage(
imageNumber: Local!ImageNumber,
onSuccess: {
a!save(local!FTNICallresult, fv!result),
a!save(
local!AppianInternalDocumentID,
rule!LCP_GetNumberOutOfText(local!Callresult.body.imageData)
)
},
onError: {
a!save(
local!CallErrorMessage,
fv!error.message
)
}
),
size: "STANDARD",
style: "NORMAL"
)
},
align: "START"
)

    5 replies

    mathieud0001
    Genius
    Jul 5, 2023 4:24 PM UTC

    The API would have to return a URL to the image for that to work.

    trungt2435
    New Participant
    Jul 5, 2023 5:00 PM UTC

    oh ok, thank you, yeah it returns a  base64 encoded string of an image, which is why I need to use saveInto so it converts to an image for display back, etc... 

    mikes0011
    Brainy
    Jul 5, 2023 6:03 PM UTC

    I haven't tried this, so I have no idea whether it would really work, but just for the sake of thoroughness, what would happen if you declare a local variable as the result of the API call?

    The Expression Guru
    trungt2435
    New Participant
    Jul 5, 2023 7:37 PM UTC

    it would give me this because inside this call use smartservice to convert base64 into image:  Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error : An error occurred when creating local!CallWebAPI. a!save() and smart service functions cannot be used in a local variable unless "refreshAlways" is true for that local variable using the a!refreshVariable() function.

    mikes0011
    Brainy
    Jul 6, 2023 12:15 PM UTC
    unless "refreshAlways" is true for that local variable

    And if you try using a local variable set to RefreshAlways?

    The Expression Guru