I have a text field (popup list of items) "Ingredients"
I create a simple Auto-assign rule for "Ingredients": AME: #onion
When I change the Ingredients field the onion Tag is properly checked.
I then change the Auto-assign rule for "Ingredients" to use a function: AME: SetIngredientsTags([Ingredients])
with the function in the VB editor:
Function SetIngredientsTags(Ingredients)
SetIngredientsTags="#onion"
end function
However, when I change the Ingredients field, I get an error.
IQ doesn't recognize SetIngredientsTags([Ingredients]) as a function. I believe that it thinks that it is a field?
How should I write the Auto-assign rule so that the function is recognized, executed, returns #onion and sets the onion Tag?
How do I ?
Comments
Hi viking, VBScript…
Hi viking,
VBScript equations work with fields, not tags
I am sorry, but I don't…
I am sorry, but I don't understand.
"Ingredients" is a field, and the Auto-assign rule works fine to set the Tag (when I use AME: #onion).
I think that my syntax is wrong because it doesn't recognize my function: AME: SetIngredientsTags([Ingredients])
The function is just supposed to return the string #onion.
OK, got it. In the next…
OK, got it. In the next version:
Great, Thanks Pierre!
Great, Thanks Pierre!
@Pierre, thanks for v.121pr1…
@Pierre, thanks for v.121pr1 !
Unfortunately, I can still not get the Auto-assign rule to work .
For the text Field "Ingredients", I have the rule:
AME:SetIngredientsTags([Ingredients])
In User Code, I have:
Function SetIngredientsTags([Ingredients])
SetIngredientsTags="#onion"
end function
When I change the Ingredients Field I get the same error as before (that the Field does not exists)
p.s. I E-mailed you my test file. I hope that the user code is stored in the SNDB file. Last time, when I closed and opened the file, the code was not saved...
The VBScript function…
The VBScript function arguments do not need square brackets
I removed the brackets so…
I removed the brackets so that it now reads:
Function SetIngredientsTags(Ingredients)
SetIngredientsTags="#onion"
end function
However, still same error.
I just tested it here, it…
I just tested it here, it works fine. We can discuss it at the next Coffee Shop
Did you test it on the…
Did you test it on the database that I sent you?
p.s. I may arrive late to the next CS.
Yes and it works fine (I had…
Yes and it works fine
(I had to enter the VBScript as it was not entered in the Database tab)
I got it working. I realized…
I got it working.
I realized that validating the code doesn't save it, nor does it make it work.
I must click on save after validation for the function to work.
Or close the VBScript editor…
Or close the VBScript editor window!
I need some help with my…
I need some help with my VBScript and I was hoping to discuss at the CS today, but it seems that it was cancelled?
I have tried several versions. Here is a simple one that gives the popup error:
Try1
Function SetIngredientsTags(Ingredients)
if Ingredients ="{Onion}" then SetIngredientsTags="#onion"
end Function
Here is another simple version that is closer to what I want (it also gives the error)
Try2
Function SetIngredientsTags(Ingredients)
if Ingredients.Contains("Onion") then SetIngredientsTags="#onion"
end Function
Slightly more complicated but even closer to what I want (it also gives the error)
Try3
Function SetIngredientsTags(Ingredients)
dim Tagstring
if Ingredients.Contains("Onion") then Tagstring="#onion"
SetIngredientsTags=Tagstring
end Function
p.s. I get a compilation error when I declare Tagstring as a string using "dim Tagstring As String"
Hi viking, The issue here is…
Hi viking,
The issue here is that if Ingredients is not equal to "{Onion}" then function returns empty which IQ interprets as an error
So simply set SetIngredientsTags="" at the start of the function
Also the function was converted to upper case so you must test for {ONION}. This is fixed in v121Pre2.
Lastly, VBScript strings functions are case-sensitive, so "if s="onion" will return false when the input is "Onion". You can use compare fonctions (such as compare or instr) and specify how to compare string (link)
I am not following. If I set…
I am not following. If I set Ingredients to "{Onion}", I still get the error.
Anyway, I am also not sure if I understood your solution. I tried this and still got the error.
Function SetIngredientsTags(Ingredients)
SetIngredientsTags=""
if Ingredients ="{Onion}" then SetIngredientsTags="#onion"
end Function
EDIT:
I tried this:
Function SetIngredientsTags(Ingredients)
if Ingredients ="{Onion}" then
SetIngredientsTags="#onion"
else SetIngredientsTags="#Pepper"
end if
end Function
This doesn't give the error, but always returns "#Pepper". Thus when I set Ingredients to {Onion}, it is not recognized.
This will be fixed in…
This will be fixed in v121Pre2
Thanks!
Thanks!
Thanks, v121Pre2 fixes it so…
Thanks, v121Pre2 fixes it so that this function now works!:
Function SetIngredientsTags(Ingredients)
if Ingredients ="{Onion}" then
SetIngredientsTags="#onion"
else SetIngredientsTags="#Pepper"
end if
end Function
I now also need a way to remove #Onion Tag
This works fine as Auto-assignment for "Ingredients" to remove the #Onion Tag
AME: #Onion="" - two double quotes
(AME:#Onion='' - two single quotes also works)
However, this function:
Function SetIngredientsTags(Ingredients)
if Ingredients ="{Onion}" then
SetIngredientsTags="#Onion"
else SetIngredientsTags="#Onion="""
end if
end Function
The #Onion Tag is not removed..
(I also tried
else SetIngredientsTags="#Onion=''" - that is using 2 single quotes followed by a double quote after the =)
Is there another way to remove the #Onion Tag by the function?
In the next version, #Onion=…
In the next version, #Onion= or #Onion=0 will remove the tag
Thanks!. Sorry to keep…
Thanks!. Sorry to keep bothering, but this command also does not work:
SetIngredientsTags="#Onion | #Pepper"
Only the "Pepper" Tag is set...
(both the Onion and Pepper Tags are set with this rule: AME: #Onion | #Pepper)
AME: #Onion | #Pepper There…
There are 2 rules ( | separates rules), so the second rule is #Pepper, which if it works, does not have the proper syntax and may not work in the future
Yes, I am aware that |…
Yes, I am aware that | separates the rules and that is why I used
Is there another way to set both the Onion and Pepper Tags using a single rule?
Can the function return something to set both the Onion and Pepper Tags?
Maybe the only way is to create a separate function for each Tag? If I have 10 Tags in my multi-select text Field "Ingredients", I would need to have 10 functions where each functions checks for each Tag?
If so, I guess that it would need:
AME:SetIngredientsTags01([Ingredients])
AME:SetIngredientsTags02([Ingredients])
.
.
AME:SetIngredientsTags10([Ingredients])
(and then repeat this for each multi-select text Tag - I will probably end up with close to 100 functions)
You can do it with a single…
You can do it with a single function, with the tag as a second parameter, but you'll need separate rules for each tag.
As you know, from the start, I didn't find your approach to be very "elegant" 😮, though you're correct that it "works" 👍
Could you give an example on…
Could you give an example on how to use a single function to set both the Onion and Pepper Tags?
(I don't understand what you mean by using the Tag as a second parameter)
p.s. I 100% agree that my approach is not "elegant". However, it is the only way that I can think of to be able to use Forms to set Tags....
(to manually set the Tags using the Tags Pane is not using a Form)
I can't figure out how to do…
I can't figure out how to do it with a single function if returning "#Onion | #Pepper" fails.
Is it correct that I will need to do the following to make it work (in the next version)?
A. For each multi-select text Field, I will need these Equations (e.g. if I have 10 Ingredients Tags):
AME:SetIngredientsTags1([Ingredients])
AME:SetIngredientsTags2([Ingredients])
.
.
AME:SetIngredientsTags10([Ingredients])
B. I will then need 10 VB scripts, one for each Ingredient Tag:
Function SetIngredientsTags1(Ingredients)
SetIngredientsTags1="#Onion=0"
If Instr(Ingredients,"Onion") then SetIngredientsTags1="#Onion"
end Function
Function SetIngredientsTags2(Ingredients)
SetIngredientsTags2="#Pepper=0"
If Instr(Ingredients,"Pepper") then SetIngredientsTags2="#Pepper"
end Function
.
.
etc
p.s. For some reason, I get a compilation error with an else statement:
If Instr(Ingredients,"Onion") then SetIngredientsTags1="#Onion"
else SetIngredientsTags1="#Onion=0"
End If
we'll discuss it during the…
we'll discuss it during the next Coffee Shop
OK. BTW, I was thinking that…
OK.
BTW, I was thinking that maybe there could be an option to automatically convert the Multi-select pop-up lists to Tags (http://infoqubeim.com/drupal5/node/3272 - see section 5.)...? Then there would be no need to add functions for this purpose (although the new function support to return a string is still very valuable).