Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Enable/Disable a button depending of the value return by a webservice

Hello,

I need a button to be enable/disable according of the value return by a webservice?

Let's say the value would return '0' or '1', and it will control the status of the button

Is it possible? And would you code the condition?

Thanks in advance,

2 Replies
danielrozental
Master II
Master II

You could use a macro to check the webservice and set a variable that will controls whether the button is enabled or not.

Not applicable
Author

Hi,

Fyi, I started from the following link: http://community.qlik.com/docs/DOC-1320

This is my final code with:

- management of return code/message through Alert pop-up + email notification

- verification that current user has correct setting to run macro (specific topic can be found here: http://community.qlik.com/message/140870#140870)

Sub ModuleSecurityCheck

ms = ActiveDocument.GetCurrentModuleSecurity '2=System Access, 1=SafeMode

ActiveDocument.Variables("vModuleSecurityMode").SetContent ms, true

FireAlert "ALModuleSecurityCheck"

End Sub

Sub FireAlert(AlertID)

set albm = ActiveDocument.GetAlertAndBookmark(AlertID)

'msgbox alertID & albm

set alertstatus = ActiveDocument.CheckAlert(albm.Alert, albm.Bookmark)

if alertstatus.Default then

   set act = alertstatus.Action

   ActiveDocument.PerformAlertAction act

end if

End Sub

Sub DisplayErrorInfo(ExecutionStep)

    ErrorMessage = "Error: " & Err.Number &_

                   " | Source: " & Err.Source

    ErrorDetails = "Description: " & Err.Description & vbCrLf &_

                   "ExecutionStep: " &ExecutionStep

    Err.Clear

    ActiveDocument.Variables("vFlagStatus").setContent "Failed", true

    ActiveDocument.Variables("vFlagMessage").setContent ErrorMessage, true

    ActiveDocument.Variables("vFlagError").setContent ErrorDetails, true

End Sub

Sub DesactivateButton

'In case error was encountered during GetFlags, both buttons are disabled.

ActiveDocument.Variables("vFlagGEMS").setContent 0, true

ActiveDocument.Variables("vFlagGMSI").setContent 0, true

End Sub

Sub GetFlags

    On Error Resume Next

    ModuleSecurityCheck

    if ActiveDocument.Variables("vModuleSecurityMode").GetContent.String < 2 then

        'ActiveDocument.Variables("vPannel").setContent "0", true

        'ActiveDocument.Variables("vPannel2").setContent "0", true

        ActiveDocument.Variables("vFlagGEMS").setContent 1, true

        ActiveDocument.Variables("vFlagGMSI").setContent 1, true        

    else

        'Create xmlhttp opject

        Set xmlhttp = CreateObject("Microsoft.XMLHTTP")

        if  Err.Number <> 0  then

            DisplayErrorInfo "GetFlags: Creating XMLHTTP Object"

            DesactivateButton

        else

            'Call HTTP Get method passing WS URL and parameters

            xmlhttp.open "GET", ActiveDocument.Variables("sEMAWS").GetContent.String & "/GetFlags", false

            if  Err.Number <> 0  then

                DisplayErrorInfo "GetFlags: Calling WS"

                DesactivateButton

            else

                xmlhttp.send ""

                set xmlDoc = createobject("Microsoft.XMLDOM")

                if  Err.Number <> 0  then

                    DisplayErrorInfo "GetFlags: Creating XMLDOM Object"

                    DesactivateButton

                else

                    xmlDoc.async = "false"

                    xmlDoc.load(xmlHttp.responseStream)

                    if  Err.Number <> 0  then

                        DisplayErrorInfo "GetFlags: Loading Response into XML Object"

                        DesactivateButton

                    else

                        set output=ActiveDocument.Variables("vFlagGEMS")

                        output.setContent xmlDoc.getElementsByTagName("GEMSFlag").Item(0).text, true

                        if  Err.Number <> 0  then

                            DisplayErrorInfo "GetFlags: Retrieving ElementTag <GEMSFlag> from XML"

                            DesactivateButton

                        else

                            set output=ActiveDocument.Variables("vFlagGMSI")

                            output.setContent xmlDoc.getElementsByTagName("GMSIFlag").Item(0).text, true

                            if  Err.Number <> 0  then

                                DisplayErrorInfo "GetFlags: Retrieving ElementTag <GMSIFlag> from XML"

                                DesactivateButton

                            end if 'Retrieving ElementTag <GMSIFlag> from XML

                        end if 'Retrieving ElementTag <GEMSFlag> from XML

                    end if 'Loading Response into XML Object

                end if 'Creating XMLDOM Object

            end if 'Calling WS

        end if 'Creating XMLHTTP Object

    end if 'ModuleSecurityMode <2

End sub

Sub SetFlag

    ModuleSecurityCheck

    if ActiveDocument.Variables("vModuleSecurityMode").GetContent.String =  2 then

        On Error Resume Next

        'Create xmlhttp opject

        Set xmlhttp = CreateObject("Microsoft.XMLHTTP")

        if  Err.Number <> 0  then

            DisplayErrorInfo "SetFlag: Creating XMLHTTP Object"

        else

            'Call HTTP Get method passing WS URL and parameters

            xmlhttp.open "GET", ActiveDocument.Variables("sEMAWS").GetContent.String & "/SetFlag?param=" & ActiveDocument.Variables("vFlagFired").GetContent.String & "&val=0&username=" & ActiveDocument.Evaluate("OsUser()"), false

            if  Err.Number <> 0  then

                DisplayErrorInfo "SetFlag: Calling WS"

            else

                xmlhttp.send ""

                set xmlDoc = createobject("Microsoft.XMLDOM")

                if  Err.Number <> 0  then

                    DisplayErrorInfo "SetFlag: Creating XMLDOM Object"

                else

                    xmlDoc.async = "false"

                    xmlDoc.load(xmlHttp.responseStream)

                    if  Err.Number <> 0  then

                        DisplayErrorInfo "SetFlag: Loading Response into XML Object"

                    else

                        set output=ActiveDocument.Variables("vFlagStatus")

                        output.setContent xmlDoc.getElementsByTagName("Status").Item(0).text, true

                        if  Err.Number <> 0  then

                            DisplayErrorInfo "SetFlag: Retrieving ElementTag <Status> from XML"

                        else

                            set output=ActiveDocument.Variables("vFlagMessage")

                            output.setContent xmlDoc.getElementsByTagName("Message").Item(0).text, true

                            if  Err.Number <> 0  then DisplayErrorInfo "SetFlag: Retrieving ElementTag <Message> from XML"

                        end if

                    end if

                end if

            end if

        end if

        GetFlags

        FireAlert "ALFlagEmailNotification"       

        FireAlert "ALFlagPopupSuccess"   

        FireAlert "ALFlagPopupFailure"   

        FireAlert "ALFlagPopupWarning"

        ActiveDocument.Variables("vFlagFired").setContent "", true

        ActiveDocument.Variables("vFlagStatus").setContent "", true

        ActiveDocument.Variables("vFlagMessage").setContent "", true

        ActiveDocument.Variables("vFlagError").setContent "", true

    end if

End sub