Using Javascript IF function to create Google Tag Manager Variable - if-statement

I'm trying to create a custom variable in Google Tag Manager. I need it to show a 0 value when...
A customer purchases using a discount code which contains the words 'Gift Voucher'
AND
It generates negative revenue.
Else it should just appear standard revenue (there are times when negative revenue is needed, hence why it should only appear as 0 when a gift voucher is used)
Ive tried the following
function () { if ({{Discount Code Used}} = str.includes("Gift Voucher") && {{Revenue}}<0 ) {return 0; } else { return {{Revenue}}; }}
But this is returning a undefined value
Is anyone able to help?

The first half of your if condition is a bit off:
{{Discount Code Used}} = str.includes('Gift Voucher')
The right way to use the .includes() method of a string is like this:
{{Discount Code Used}}.includes('Gift Voucher')
I would recommend using .indexOf() instead of .includes(), since it is supported by more browsers.
{{Discount Code Used}}.indexOf('Gift Voucher') !== -1
If it is still returning undefined, double check that Discount Code Used and Revenue are set to the correct values.

Related

How to also populate "N/A" with If AND function in Google Sheets

My current formula populates Missed, Meets, Nearly Meets, and Exceeds. But I can't seem to figure out how to include "N/A" or create a blank cell in the formula.
My forumla so far:
=if(AND(L40>=14.5, L40<=16.4),"Nearly Meets", if(AND(L40>=4.5, L40<=14.4),"Meets", if(AND(L40>=15.5),"Missed","Exceeds")))
So, if L40 has any range of these number, M40 populates any of these Texts. How can I add to the formula so a blank cell populates "N/A" . Or, entering "TBD" in a cell leaves it blank or populates "N/A"
I'd rather use IFS formula or VLOOKUP here. It's short and clear.
=ifna(vlookup(B2,F2:G6,2,true),"value not found")
On a side you make a table of requirements and go through it using vlookup.
If you have no space anywhere in your sheet, you can also include value table into your formula using curly brackets:
=ifna(vlookup(B2,{0,"Missed";4.5,"Nealry Meets";14.4,"Meets";15.5,"Exceeds";"","Empty"},2,true),"value not found")
For values outside the set you can use IFNA formula.
If you use indentation before writing the final formula, it looks like this:
if(AND(L40>4.4; L40<=16.4){
"Nearly Meets";
}
else if(AND(L40>=4.5; L40<=14.4){
"Meets";
}
else if(L40>16.4){
"Missed";
}
else if(L40 = ""){
"N/A";
}
else {
"EXCEEDS"
}
Notice that I didn't use the condition if(L40<4.5), because a blank cell can be interpreted as 0, which is always less than 4.5, so you would never reach the N/A condition. By better determining your ranges, it gets easier to escape the exceeds case. It may not be your case, but if you had 2 or more digits after the decimal point, it could give you an unexpected result.
That said, you can now use the formula as
=if(AND(L40>4.4, L40<=16.4), "Nearly Meets", if(AND(L40>=4.5, L40<=14.4), "Meets", if(L40>16.4, "Missed", if(L40 = "", "N/A", "EXCEEDS"))))

How to give if condition for propercase and uppercase in sap crystal report

I am getting two values one is printing Cash and other is printing CASH in sap crystal report. Now, I want that wherever Cash is showing at that time value should be false while if CASH is printing then the value should show true. So, for that I added the formula but didnt work,
here is my formula,
if(ProperCase({TmpSalesBillInstallmentReport.PaymentType}) = true)
then {TmpSalesBillInstallmentReport.PaymentType}= '0'
else if(UpperCase({TmpSalesBillInstallmentReport.PaymentType}) = true)
{TmpSalesBillInstallmentReport.PaymentType} = '1'
This formula is not working, even getting error i.e. A Boolean Is Required Here(indicating on the first line)
I surfing in net but didnt get related question also.
IF {TmpSalesBillInstallmentReport.PaymentType} = "CASH" Then True ELSE False;
Note: A Crystal formula cannot assign a value to a database field. The field value is Read Only!
UpperCase() function is not a test that returns true or false. It simply returns the text argument after converting it to all upper case.
You might have a setting causing comparisons to be case insensitive.
See: http://www.plumblineconsulting.com/crystal-reports-and-case-sensitivity-of-database-records/

calculate range of values entered by user Custom function Google Appscript

I want to use arrayformula for my custom function if possible because I want to input a range of values
I also get this error: TypeError: Cannot read property "0" from null.
Also, this: Service invoked too many times in a short time: exec qps. Try Utilities.sleep(1000) between calls
var regExp = new RegExp("Item: ([^:]+)(?=\n)");
var matches=new regExp(input);
return matches[0];
}
Really appreciated some help
Edit:
Based on the second picture, I also try using this regex formula to find word start with "Billing address"
But for the first picture, I used regex formula to find word start with "Item"
The error appears the same for both custom function.
If you want to use a custom function which finds all the strings that start with Item or item and extracts the contents from after the finding, you can use the code provided below. The regular expression is checked by using the match() function and returns the desired result; otherwise, it will return null.
function ITEM(input) {
var regEx = /(?:I|i)tem\s*(.*)$/;
var matches = input.match(regEx);
if (matches && matches.length > 1) {
return matches[1];
} else {
return null;
}
}
If you want to use the RegExp like you did in the code you have shared, you should use \\ instead of \.
For checking and verifying the regular expressions you can use this site.
The Service invoked too many times in a short time: exec qps. Try Utilities.sleep(1000) between calls. error message you are getting is due to the fact that you are trying to call the custom function on too many cells - for example dragging the custom function on too many cells at once. You can check more about this error message here.

Jmeter Regular Expression Extractor. How to save all returned values to a single variable?

I'm quite new to Jmeter and already spent numerous hours to figure it out.
What i'm trying to achieve:
Using Post Processor Regex Extractor I wrote a regex that returns me several values (already tested it in www.regex101.com and it's working as expected). However, when I do this in Jmeter, I need to provide MatchNo. which in this case will only return to me one certain value. I sort of figured it out that negative digit in this field (Match No) suppose to return all values found. When I use Debug Sampler to find out how many values are returned and to what variables they are assigned, I see a lot of unfamiliar stuff. Please see examples below:
Text where regex to be parsed:
some data here...
"PlanDescription":"DF4-LIB 4224-NNJ"
"PlanDescription":"45U-LIP 2423-NNJ"
"PlanDescription":"PMH-LIB 131-NNJ"
some data here...
As I said earlier, at www.regex101.com I tested this with regex:
\"PlanDescription\":\"([^\"]*)\"
And all needed for me information are correct (with the group 1).
DF4-LIB 4224-NNJ
45U-LIP 2423-NNJ
PMH-LIB 131-NNJ
With the negative number (I tried -1, -2, -3 - same result) at MatchNo. field in Jmeter Regex Extractor field (which Reference Name is Plans) at the Debug Sampler I see the following:
Plans=
Plans_1=DF4-LIB 4224-NNJ
Plans_1_g=1
Plans_1_g0="PlanDescription":"DF4-LIB 4224-NNJ"
Plans_1_g1=DF4-LIB 4224-NNJ
Plans_2=45U-LIP 2423-NNJ
Plans_2_g=1
Plans_2_g0="PlanDescription":"45U-LIP 2423-NNJ"
Plans_2_g1=45U-LIP 2423-NNJ
Plans_3=PMH-LIB 131-NNJ
Plans_3_g=1
Plans_3_g0="PlanDescription":"PMH-LIB 131-NNJ"
Plans_3_g1=PMH-LIB 131-NNJ
I only need at this particular case - Jmeter regex to return 3 values that contain:
DF4-LIB 4224-NNJ
45U-LIP 2423-NNJ
PMH-LIB 131-NNJ
And nothing else. If anybody faced that problem before any help will be appreciated.
Based on output of the Debug Sampler, there's no problem, it's just how RegEx returns the response:
Plans_1,Plans_2,Plans_3 is the actual set of variables you wanted.
There should also be Plans_matchNr which should contain the number of matches (3 in your example). It's important if you loop through them (you will loop from 1 to the value of this variable)
_g sets of variables refer to matching groups per matching instance (3 in your case). Ignore them if you don't care about them. They are always publish, but there's no harm in that.
Once variables are published you can do a number of things:
Use them as ${Plans_1}, ${Plans_2}, ${Plans_3} etc. (as comment above noticed).
Use Plans_... variables in loop: refer to the next variable in the loop as ${__V(Plans_${i})}, where i is a counter with values between 1 and Plans_matchNr
You can also concatenate them into 1 variable using the following simple BeanShell Post-Processor or BeanShell Sampler script:
int count = 0;
String allPlans = "";
// Get number of variables
try {
count = Integer.parseInt(vars.get("Plans_matchNr"));
} catch(NumberFormatException e) {}
// Concatenate them (using space). This could be optimized using StringBuffer of course
for(int i = 1; i <= count; i++) {
allPlans += vars.get("Plans_" + i) + " ";
}
// Save concatenated string into new variable
vars.put("AllPlans", allPlans);
As a result you will have all old variables, plus:
AllPlans=DF4-LIB 4224-NNJ 45U-LIP 2423-NNJ PMH-LIB 131-NNJ

how to match a input value with the regular expression in dynamics crm 2011?

At the contact form I have a field name as Extension (new_ext). and at the onChnage event I want to do check weather the user has enter the number or anything else. I have the following piece of code.
function formatPhone(phonenum)
{
var ext =phonenum.getEventSource().getValue();
var reg = /^[0-9]$/;
if(ext.match(reg))
{
alert("Valid");
}
else
{
alert("invalid");
}
}
It returns me always invalid even if I enter a letter or a number or both.
I want to seek your kind suggestions and help regarding this.
Try this one "^\d+$", just check for null values before if you need to.
Already asked here Regex allow a string to only contain numbers 0 - 9