I am new into using Velocity but this is what I am attempting to do.
Based on a issue type "service request" and custom field option 'a' set description to display 'x'
Based on a issue type "service request" and custom field option 'b' set description to display 'y'
Based on a issue type "service request" and custom field option 'c' set description to display 'z'
I have used the following for this
if (($issue.key == '') & ($issue.type().getname == 'service request') & ($customfieldmanager().getcustomfieldoption = '11504') & ($id == 'a'))
set ($description = 'x')
elseif ($id == 'b')
set ($description = 'y')
else ($id == 'c')
set ($description = 'z')
Seems not to recognise the the custom field id or the custom field selection id.
Anyone recommend what could be going wrong here, I have had no luck and have tried a few different ways and have spent a few days attempting to work this out.
Help would be appreciated.
For logical "AND" use "&&" instead "&". Please see here: http://velocity.apache.org/engine/devel/user-guide.html#relationalandlogicaloperators
if, else, set should have "#" in front.
if else need "end": https://click.apache.org/docs/velocity/user-guide.html#conditionals
In your sample, issue and customfieldmanager should be in velocity scope. So JIRA (or your JIRA plugin) action should have appropriate getIssue() and getCustomFieldManager() methods and you can access them in velocity as $issue and $customFieldManager (or $getIssue() and $getCustomFieldManager()). Pay attention to cases and brackets. Similar situation with getname and getcustomfieldoption. Please see here: https://stackoverflow.com/a/17069545/1537800
I am not sure about lower/upper cases in method names, but corrected version may look like:
#if ($issue.key == '' && $issue.getType().getName() == 'service request' && $customFieldManager.getCustomFieldOption() == '11504' && $id == 'a')
#set ($description = 'x')
#elseif ($id == 'b')
#set ($description = 'y')
#else ($id == 'c')
#set ($description = 'z')
#end
Related
I am working on a multi-lingual project. Which has 3 locales en-SG, en-VN, and vi-VN. Among them, en-SG is a default locale.
Is this possible to query the docs in a way so that when there is no doc for any locale(especially en-VN) the site shows the default locale doc?
I have achieved something similar with this query.
*[_type == "cardPage" && (__i18n_lang == $locale || __i18n_lang == $defaultLocale ) && !(_id in path('drafts.**'))]
But it's not working properly when the $locale doc available, it's querying the $locale doc and $defaultLocale doc at the same time. And showing the $defaultLocale doc instead of the actual $locale doc on some pages.
I am using nextjs for front end and sanity-plugin-intl-input plugin for localization.
You can add your default document to your result and return the first match.
[(
*[ _type == "something" && the_one_you_want ] +
*[ _type == "something" && fallback_or_default ]
)[0]]
There are different flavors of concatenation. Here is another with Spread syntax.
[
...*[ _type == "something" && the_one_you_want ],
...*[ _type == "something" && fallback_or_default ]
][0]
I've got below case condition which works well.
case params[:event_type]
when 'publish'
StoreActivityWorker.perform_async(params)
when 'delete'
DeleteActivityWorker.perform_async(params)
end
But I want to add another conditions to each when - name == %w[Text Video Audio] so the code should be like:
case params[:event_type]
when 'publish' && name == %w[Text Video Audio]
StoreActivityWorker.perform_async(params)
when 'delete' && name == %w[Text Video Audio]
DeleteActivityWorker.perform_async(params)
end
but it won't work, it shows false every time.
name is just:
params.dig('entity', 'relationships', 'item_type', 'data', 'name')
Currently you're checking if
('publish' && name == %w[Text Video Audio]) === params[:event_type]
or if
('delete' && name == %w[Text Video Audio]) === params[:event_type]
The left side of === can be either true or false and I don't think params[:event_type] is going to be either of those two values, so neither of your two cases are going to be executed.
What you probably want is something like:
if name == %w[Text Video Audio]
case params[:event_type]
when 'publish'
StoreActivityWorker.perform_async(params)
when 'delete'
DeleteActivityWorker.perform_async(params)
end
end
Even that seems a bit off since you're checking if name is equal to %w[Text Video Audio] which I don't think is going to be the case. Perhaps you want:
%w[Text Video Audio].include?(name)
A nested case inside of an if statement is also not the best option. I might suggest a guard clause but without knowing the entire method it's hard to tell.
The expression 'publish' && name == %w[Text Video Audio] does not make sense. Remember that && is a shortcut operator: (E1) && (E2) evaluates E1, and if the result is falsy, returns this value (i.e. nil or false), without even looking at E2. If E1 is trueish, it evaluates and returns E2. In your case, 'publish' is trueish, and hence E2 is returned.
Your E2 is
name == %w[Text Video Audio]
and this expression evaluates to either be true or false, and neither can match your params[:event_type], because the event type is likely not truenor false, but a string, and therefore the condition does not fire.
I have this simple condition in my ruby code:
if user.text != ("Empty" || "Damaged")
do something...
the thing is that when it is "Damaged" it still enters the loop, so I have to use this:
if user.text != "Empty"
if user.text != "Damaged"
...
..
What is the correct syntax to make the first one work?
Thanks!
Use this:
unless ["Empty", "Damaged"].include?(user.text)
...
end
The problem with your first approach is that a || b means that: if a != nil then it is a, else it is b. As you can see it is good for variables, not constants as they are rarely nil. Your expression ("Empty" || "Damaged") simply equals "Empty".
You want to use the this as a binary operator, the correct form would be:
if (user.text != "Empty") && (user.text != "Damaged")
The upper solution is just shorter. It consists of an array of elements you want to avoid, and you just simply check is the user.text is not present in it.
#Matzi has the right answer, for sure. But here's why what you're doing is failing:
Your statement ("Empty" || "Damaged") evaluates to "Empty"
You're saying return either one of these, whichever non-false thing you find first. In Ruby, any string, number or Object returns true, so you return "Empty" every time.
A better way to lay it out if you really want to use an if statement:
if user.text != "Empty" && user.text != "Damaged"
...
end
I assume, by the way, that you're trying to say "If the user text is neither Damaged nor Empty".
Hope that helps.
if ((text != "Empty") && (text != "Damaged"))
Edit: I was able to go one step further :)
PSEUDO CODE (what I want)
if (CurrentTabURL == empty Tab) and (Tab.Count == 1)
{close Firefox}
else
{close Tab}
MY CODE (only the if statements don't work. Both actions are working)
if (gBrowser.currentURI == "")
and (tabbrowser.browsers.length == 1)
then
goQuitApplication();
else
gBrowser.removeTab(gBrowser.mCurrentTab);
end
This link helped me a lot.
gBrowser.currentURI is an nsIURI instance. If you want to compare the URL to a string you should look at gBrowser.currentURI.spec. The URL of an "empty tab" is about:blank by the way. Also, I guess that you want to use JavaScript? Corrected code:
if (gBrowser.currentURI.spec == "about:blank" && gBrowser.browsers.length == 1)
goQuitApplication();
else
gBrowser.removeTab(gBrowser.selectedTab);
I am using IBM-Informix for my school project as part of "Informix on-campus" ativity conduted by IBM.
however it is giving me error as "(USE31) - Too few points for geometry type in ST_LineFromText.", in the second linefromtext function.
The problem in the second call to ST_LineFromText() is that you are attempting to pass parameters into it, which isn't possible. You have:
ST_LineFromText('linestring (0 0,v1.pre 0,v1.pre v1.post,0 v1.post,0 0 )',5)
The string contains 'v1.pre' which is not a valid number, etc. If you need to parameterize your query, you either need to generate the string with those values in place, or you need to use a different method. One crude but possible solution is:
ST_LineFromText('linestring (0 0,' || v1.pre || ' 0,' || v1.pre || ' ' ||
v1.post || ',0 ' || v1.post || ',0 0 )', 5)
This may not do the job - but illustrates the problem.