Qlikview iterate result set of temp table using forloop - qlikview

I want to iterate the ResultSet of a TempTable.
For eg:
MyTmpTable:
set emails = 'abc#xyz.com','qwe#xyz.com','asd#xyz.com';
for each mail in $(emails)
//Api call with Id https://myapiurl/$(mail)
next
This works fine. We tested with hard-coded emails
MyTmpTable:
Load emails from Employee;
for each mail in $(emails)
//Api call with Id https://myapiurl/$(mail)
next
But we want to iterate with dynamic emails. So tried the above code but its throwing QVD UNEXPECTED END OF DATA Error
Again tried with the below code
MyTmpTable:
Load emails from Employee;
for each mail in FieldValueList('emails')
//Api call with Id https://myapiurl/$(mail)
next
This time loop works fine but getting the same error QVD UNEXPECTED END OF DATA Error on API call
Whats wrong with this implementation?

Try building the list in the variable first, then it sould behave like the hardcoded list. chr(39) is just a trick to insert ' without creating a text escape in the initial declaration
EMAIL_LIST:
load
concat(emails,chr(39)&','&chr(39)) as Email_List
Resident employees
;
let zEmailList = chr(39)&fieldvalue('Email_List',1)&chr(39)
;
drop table EMAIL_LIST
;
for each mail in $(zEmailList)
trace $(mail);
//Api call with Id https://myapiurl/$(mail)
next mail

Related

Is there a way to convert my old data macros from table to vba after a database split?

I recently split my ms access database into a front, and back end. I didn't know that the data macros that were on the table wouldn't be able to work anymore. I was wondering if there is any way to convert these to vba.
if IsNull([prmQuoteID])
RaiseError
Error Number 10
Error Description Please specify quote details.
end if
RunDataMacro
Macro Name Quotes.GetNextQuoteNumber
SetLocalVar
Name varNextQuoteNumber
Expression = [ReturnVars]![retNextQuoteNumber]
RunDataMacro
Macro Name Quotes.UpdateQuoteTotal
parameters
prmQuoteId = [prmQuoteId]
if [varNextQuoteNumber]=0
RaiseError
Error Number 20
Error Description Unable to retrieve next quote number!
stopmacro
end if
Look Up A Record In SELECT Quotes.ID, Quotes.StatusID, Quotes.QuoteNumber, Quotes.Submitted FROM Quotes;
Where Condition = [ID]=[prmQuoteID]
if [StatusID]>=10
RaiseError
Error 30
Error Description Quote has already been marked submitted.
End If
Edit Record
SetField
Name StatusId
Value = 10
SetField
Name QuoteNumber
Value = [varNextQuoteNumber]
SetField
Name Submitted
Value = Date()
Example of Data Macro
Data Macro Photo of above code
It connects to an form on click embedded macro in the front end database
On click embedded macro
OnError
go to Macro Name
ErrorHandler
SetTempVar
Name YesNoMessage
Expression = "Quote cannot be changed once it is submitted."
SetTempVar
Name YesNoMessage2
Expression = ""Do you want to continue?""
OpenForm
Form Name YesNoAlert
View Form
Window Mode Dialog
If [TempVars]![YesNoResponse]=False
stopmacro
End If
RunMenuCommand
command saveRecord
RunDataMacro
Macro Name Quotes.Submit
Parameters
prmQuoteId = [txtID]
RefreshRecord
RunMacro
Macro Name SetFromState
SetTempVar
Name AlertMessage
Expression "Quote #" & [txtQuoteNumber] & " is now submitted for approval."
OpenForm
Form Name Okalert
View Form
Window Mode Dialog
Submacro: ErrorHandler
RunMacro
Macro Name Utilities.ErrorAlert
End Submacro
I was wondering what the best way to convert these would be and still have them work for someone with limited VBA knowledge.

Automation error in global address list lookup

I'm trying to look up a person's email address using the Outlook global address list. Here is the VBA code I use to do it.
'Snip
If firstName <> "" Then
Dim o, AddressList, AddressEntry
Dim AddressName, Address, Address2 As String
Set o = CreateObject("Outlook.Application")
Set AddressList = o.Session.AddressLists("Global Address List")
AddressName = firstName
For Each AddressEntry In AddressList.AddressEntries
If AddressEntry.Name = AddressName Then
Address = AddressEntry.GetExchangeUser.PrimarySmtpAddress
Exit For
End If
Next AddressEntry
End If
'Snip
The variable "firstName" is in the format Last name, first name. This seemingly only works half of the time I try to use it. For example if I put my own name in it work perfectly fine every time but if I put in my co-worker's name I get a little pop up bubble from Outlook saying "outlook is trying to retrieve data from the Microsoft exchange server *.com" and then I get an automation error. I couldn't find anything in common between the names that don't work and the same for those that do. Any help would be very much appreciated.
EDIT: Another note I just thought of is that when I hit debug on the error window it highlights the "Next AddressEntry" line.
Do not loop through all items in GAL - some GALs contain tens of thousand of entries, and you will nto be able to loop through them.
Call Application.Session.CreateRecipient (returns Recipient object), call Recipient.Resolve, then use Recipient.AddressEntry.GetExchangeUser.
UPDATE:
if the name is ambiguous, you will get back an error from Recipient.Resolve - Outlook Object Model does not let you recover from that - there is no way to get the list of matches and select the one you want. If using Redemption (I am its author) is an option, you can use is RDOAddressBook.ResolveNameEx method - it returns a list of matches (of one entry if the name is not ambiguous). You can also use RDIAddressList.ResolveName / ResolveNameEx if you want to resolve against a particular container only (e.g. GAL).
Set o = CreateObject("Outlook.Application")
...
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = o.Session.MAPIOBJECT
set AdrrEntries = Session.AddressBook.ResolveNameEx("John")
MsgBox AdrrEntries.Count & " names were returned by ResolveNameEx:"
for each AE in AdrrEntries
MsgBox AE.Name
next

How to identify the item when using a script

I have generated a rule which then actions a SCRIPT.
I want to get details from the identified email message - i.e. the body then output to a file that can be read elsewhere.
My logic sort of works but I am currently retrieving the contents of the selected or highlighted email rather than the email identified by the rule.
INFO ONLY
[Specifically the email is a FOREX Signal with a defined Subject. I then want to get the contents of this email to a file that can subsequently be read by an Expert Advisor running on a MetaTrader 4 platform]
struggled to get meaningful tags accepted - i.e. script or OutlookRules
You pass the mailitem as a parameter.
If, for example, you pass Item then process Item.
Sub CustomMailMessageRule(Item As Outlook.MailItem)
MsgBox "Mail message arrived: " & Item.Subject
End Sub

Parameter query run hyperlink & open webpage, for tracking UPS package

I have a parameter query that looks up the tracking # for a given customer_order_ID and outputs the tracking# as a website link, as a single record. Please advise me how I can have the link run automatically when the user inputs the customer_order_ID into the parameter query , in order that the user can immediately track the package on the UPS Worldship website. I do not know VBA nor do I know SQL, but I can make macros.
Thank you very much in advance
SELECT T.order_ID, "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_us&InquiryNumber1=" & [T].[tracking_number] & "&track.x=0&track.y=0" AS link
FROM tblShipmentDataFromAllCarriers AS T
WHERE (((T.order_ID)=[Please enter customer order ID]));
If you don't need to parse the return data and just want to open the web page, you can use Application.FollowHyperlink. But you don't need to do the concatenation with the URL in the SQL:
SELECT T.order_ID, [T].[tracking_number]
FROM tblShipmentDataFromAllCarriers AS T
WHERE (((T.order_ID)=[Please enter customer order ID]));
Then you could store the rest of the URL as constants:
Const c_strURL1 = "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_us&InquiryNumber1="
Const c_strURL2 = "&track.x=0&track.y=0"
...and then execute it like this:
Public Sub DisplayTrackingNumber(ByVal strOrderID As String)
Dim strTrackingNumber As String
strTrackingNumber = DLookup("tracking_number", "tblShipmentDataFromAllCarriers", "[order_ID]=" & strOrderID)
Application.FollowHyperlink strUrl1 & strTrackingNumber & strUrl2
End Sub
You'd then have to have a UI to collect the OrderID from the user (I'd suggest a form with a combo box) and then call this sub.

Checkbox to SQL Database

I have a problem which I'm struggling to fix.
I have a form with many checkboxes containing email addresses, the result of which is sent to another page.
This page will send out newsletters.
This is working at the moment, but what I would like to do is include their name.
From the form received I get the results (xx#xx.com, yy#yy.com etc...)
I have managed to separate the results and put them into an array, but now I need to access the SQL db and find the names to the email address. This is where I'm struggling. Here is the code that I've tried to use:
name = request.form("list")
If name = "" Then
Response.redirect ("batchselect.asp")
End If
Dim your_name()
Dim mode
Dim mode_a
Dim i
mode=Request("list")
mode_a=split(mode,",")
For i=LBound(mode_a) to UBound(mode_a)
Next
i = i - 1
Redim PRESERVE your_name(i)
For t = 0 to i
Set conn = Server.CreateObject("ADODB.Connection")
conn.open connStr
strSQL = "SELECT name FROM emails WHERE emails = '" & mode_a(t) & "'"
Set rs = conn.Execute(strSQL)
your_name(t) = rs("name")
Next
If I try and run this I get this error:
Error Type:
ADODB.Field (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
I know the problem is in the SQL Query 'mode_a(t)', because if take out the for... next and change this to mode_a(0) or mode_a(1) it works no problem.
I'm using MS SQL and classic asp
Thanks in advance
Not sure why you are doing this:
For i=LBound(mode_a) to UBound(mode_a)
Next
i = i - 1
Surely this would be enough, and you get rid of any ambiguity in the value of i:
i = UBound(mode_a) - 1
If you are not dealing with too many email addresses I would consider trying to use an IN statement with sql and just bring back all the records for the emails. It would be so much quicker and save you a number of db calls.
If you did this then you could just return the email address with the name in the recordset row and use that to match up.
As for your actual question though I would check the value of i and make sure that it is not being set to -1 or some other value that doesn't actually point to an index. Because your error is happening because there are no results being returned. You should consider checking for EOF before you actually use the recordset.