Search by Keyword

Sense Excel the Add-In for Microsoft

If you miss something please send us an email. Thanks!

An easy and smart way to create an alert in your report

You are here:
<< Back to all topics

AnalyticsGate Reporting Suite

This example show you a way to create a script based logical with Qlik Sense script syntax and AnaylticsGate Reporting Suite

This example show you a way to create a script based logical with Qlik Sense script syntax and AnaylticsGate Reporting Suite

//*************************************************************************************************************************************
// Create Report Task
//*************************************************************************************************************************************

Sub Alerting(vContinent,vYear,vSumGDP_CURRENT,vSumGDP_Range,vsendAttachment, vText)

    SET task = ´{
      tasks:
      [
        {
          meta:
          {
            name: Job Name
            description: Job Description
          }
          reports:
          [
            {
              template:
              {
                input: content://analyticsgate/blank.xlsx   //can be empty (excel template)
                output: tmpAlerting
              }
              connections:
              {
                app: c604c78d-5f93-4d8b-a92b-b584d79bd4c1 //connected AppID
              }
              distribute:
              {
                mail:
                {
                  subject: ALERTING: from your BIP-Team: $(vText)
                  message: 
                    '''
                    <html>
                    	<body>       
                            <font face="arial" color="red" size="4"><b>ALERTING: BIP-Team!</b></font>                      
                            <br><br>
                            <font face="arial" color="black" size="2"><b>$(vContinent) $(vYear)</b> $(vText)
                            <br><br>
                            Current Value: $(vSumGDP_CURRENT) 
                            <br>
                            Threshold: $(vSumGDP_Range)
                            <br><br>
                            To the Analyse
                            </font> 
                    	</body>
                	</html>
                	'''
                  
                  mailType: html
                  sendAttachment: $(vsendAttachment)
                  to: your.name@yourserver.de
                  #cc: 
                  
                  mailServer:
                  {
                    host: mail.yourserver.com
                    from: qlik-alert@yourserver
                    port: "587"
                    username: xxxxxxx
                    password: xxxxxxx
                    useSsl: false
                  }
                  active: true
                }
              }
            }
          ]
        }
      ]
    }´;

	//Start reporting
    Let ResultWithTaskId = SER.START(task);
    Let TaskIdValue = TextBetween(ResultWithTaskId,'taskId":"','"');
    TRACE TaskId: $(TaskIdValue);

    //Show Versions
    Let versions = SER.STATUS('versions: all');
    Let MainVersion = TextBetween(versions,'version":"','"');
    TRACE Version: $(MainVersion);

    //Wait for finish
    Let Status = 0;
    Do while Status < 3 and Status > -1
      Let Result = SER.STATUS(ResultWithTaskId);
      Let LogMsg = TextBetween(Result,'log":"','"');
      Let Status = num(mid(Result,11,1));
      TRACE Status: $(Status) - $(LogMsg);
      Sleep 2000;
    Loop
    TRACE Status: $(Status) - Finished;

    //Read distibute results
    Let ResultText = SER.RESULT(ResultWithTaskId);
    Let FormatedResult = TextBetween(ResultText,'formatedResult":"','"');
    Let OutputText = Replace(FormatedResult, '\r\n', chr(13)&chr(10)); 
    TRACE $(OutputText);
    //End reporting

EndSub;


//*************************************************************************************************************************************
// Data
//*************************************************************************************************************************************


Data:
Load * Inline [
    Continent	 ,Year	,GDP		,lowThreshold	,heightThreshold
    Africa		 ,2020	,3592867	,2000000		,4000000
    Asia		 ,2020	,55312896	,50000000		,60000000
    Europe		 ,2020	,34941354	,32000000		,40000000
    Northamerica ,2020	,43047739	,49000000		,50000000
    Oceania		 ,2020	,2796840	,2000000		,2600000
    Southamerica ,2020	,6564345	,6000000		,8000000
];
//*************************************************************************************************************************************
// Create Alerting
//*************************************************************************************************************************************

LET vNoOfRows = NoOfRows('Data');
Trace vNoOfRows -> $(vNoOfRows);

For i=0 to vNoOfRows-1

	Trace ======================================;

	LET vContinent 		= Upper(Peek('Continent',i));
    LET vYear 			= Upper(Peek('Year',i));
    LET vSumGDP_CURRENT 	= Peek('GDP',i);
    LET vSumGDP_LT 	= Peek('lowThreshold',i);
    LET vSumGDP_HT 	= Peek('heightThreshold',i);
    LET vsendAttachment = 'false'; //if reportscript is in the same App like the data then paraemeter alywasy should be false
	
    Trace vContinent-> $(vContinent);
    
    // Trigger function Alerting()
    //If alert be sended or not
    If vSumGDP_CURRENT>vSumGDP_HT or vSumGDP_CURRENT<vSumGDP_LT then

    Trace ALERT;
    
    //cehck if below or above threshold
    If vSumGDP_CURRENT>vSumGDP_HT then
    	Call Alerting(vContinent,vYear,vSumGDP_CURRENT,vSumGDP_HT, vsendAttachment,'Sum of GDP greater then threshold.');
    Else
    	Call Alerting(vContinent,vYear,vSumGDP_CURRENT,vSumGDP_LT, vsendAttachment, 'Sum of GDP lower then threshold.');
    EndIf
    
    Else

         Trace No;

    EndIf
	
Next
Exit Script;

Was this article helpful?
4.5 out Of 5 Stars

1 rating

5 Sterne 0%
4 Sterne 100%
3 Sterne 0%
2 Sterne 0%
1 Sterne 0%
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Need help?
Tags:
No Comments

Post a Comment

Comment
Name
Email
Website