I wrote the following script:
def testStep = testRunner.testCase.testSteps["3D Secure Call"]
def str = new StringBuilder();
for (prop in testStep.getPropertyList()){
if(prop.getName() != "K" && prop.getName() != "RawRequest" && prop.getName() != "Domain" && prop.getName() != "Password" && prop.getName() != "ResponseAsXml" && prop.getName() != "Request" && prop.getName() != "RawRequest" && prop.getName() != "Response" && prop.getName() != "Username" && prop.getName() != "Endpoint"){
str.append(prop.getName() + "=" + testStep.getPropertyValue(prop.getName()) + "&" )
}
}
str.append("K=1473942615907cuwmviz")
And i am getting the following (As expected):
K M=10000330&PKey=c74737d2a1e27d2efec56cf8148bc6e2b68eac48a8daed17e795421c4acc51&a4=50000&a5=EUR&XID=12345678912345678912&K=1473942615907cuwmviz
Now what i am trying to achieve is sending this string to MD5 hashing function suggested here:
import java.security.MessageDigest
def generateMD5_A(String s){ MessageDigest.getInstance("MD5").digest(s.bytes).encodeHex().toString() }
I cannot achieve passing the generated string into this function and getting a new result.
Any suggestions?
achieved by doing:
def generateMD5_A(String s){ MessageDigest.getInstance("MD5").digest(s.bytes).encodeHex().toString() }
generateMD5_A(str.toString());
Related
I'm trying to make a simple function in dart to test on which should remove all vowels from an input string but its seems my code never changes the from the original input. Could anyone help me with this? thanks
String removeVowel( str) {
var toReturn = "";
for (var i = 0; i < str.length; i++) {
var temp = str.substring(i,i+1);
if (temp != 'a' || temp != 'e' || temp != 'i' || temp != 'o' || temp!= 'u')
{
toReturn = toReturn + temp;
}
}
return toReturn;
}
and what my tests shows:
00:02 +0 -1: dog --> dg [E]
Expected: 'dg'
Actual: 'dog'
Which: is different.
Expected: dg
Actual: dog
^
Differ at offset 1
Good first try but there is a much easier way of doing this.
replaceAll should do the trick
String removeVolwels(String s){
return s.replaceAll(RegExp('[aeiou]'),'');
}
https://api.flutter.dev/flutter/dart-core/String/replaceAll.html
To make your code work you should change the || to &&
String removeVowel( str) {
var toReturn = "";
for (var i = 0; i < str.length; i++) {
var temp = str.substring(i,i+1);
if (temp != 'a' && temp != 'e' && temp != 'i' && temp != 'o' && temp!= 'u')
{
toReturn = toReturn + temp;
}
}
return toReturn;
}
I'm trying to get the min and max values based on queries.
I'm using the following logic,
if(req.query.max_price && req.query.max_price != '' && req.query.max_price != 'any'){
qry.price = { $lte: req.query.max_price};
}
// and
if(req.query.min_price && req.query.min_price != '' && req.query.min_price != 'any'){
qry.price = { $gte: req.query.min_price};
}
but I can't seem to get the right response make a request something like the following,
http://localhost:5000/api/ads/list?offset=0&limit=2&min _price=200&max_price=3000
I think there's something wrong with logic, but I can't seem to pin where the problem is.
you are overwriting the qry.price. It should be,
qry.price = {}
if(req.query.max_price && req.query.max_price != '' && req.query.max_price != 'any'){
qry.price = { ...qry.price, $lte: req.query.max_price};
}
if(req.query.min_price && req.query.min_price != '' && req.query.min_price != 'any'){
qry.price = { ...qry.price, $gte: req.query.min_price};
}
I keep getting an error message in my if statement:
fun someFunction(){
if (requestCode == 0 && resultCode = Activity.RESULT_OK && data != null) {
// Do stuff
}
}
It should be resultCode == Activity.RESULT_OK
I created a script and deployed it to automatically populate web store fields when new inventory items are created in our system.
The code works when a new item is created through the interface, but does not when a new item is uploaded via csv.
This is the code:
function userEventAfterSubmit(type) {
if (type == 'create') {
var newItem = nlapiLoadRecord('inventoryitem', nlapiGetNewRecord().getId());
var storeDisplayImage = nlapiGetFieldValue('storedisplayimage');
if (storeDisplayImage == '' || storeDisplayImage == null)
newItem.setFieldValue('storedisplayimage', 620128);
var storeDisplayThumbnail = nlapiGetFieldValue('storedisplaythumbnail');
if (storeDisplayThumbnail == '' || storeDisplayThumbnail == null)
newItem.setFieldValue('storedisplaythumbnail', 620127);
var urlComponent = nlapiGetFieldValue('urlcomponent');
if (urlComponent == '' || urlComponent == null)
newItem.setFieldValue('urlcomponent', nlapiGetFieldValue('storedisplayname'));
var pageTitle = nlapiGetFieldValue('pagetitle');
if (pageTitle == '' || pageTitle == null)
newItem.setFieldValue('pagetitle', nlapiGetFieldValue('storedisplayname'));
var storeDescription = nlapiGetFieldValue('storedescription');
if (storeDescription == '' || storeDescription == null)
newItem.setFieldValue('storedescription', nlapiGetFieldValue('salesdescription'));
var storeDetailedDescription = nlapiGetFieldValue('storedetaileddescription');
if (storeDetailedDescription == '' || storeDetailedDescription == null)
newItem.setFieldValue('storedetaileddescription', nlapiGetFieldValue('salesdescription'));
var metaTagHtml = nlapiGetFieldValue('metataghtml');
if (metaTagHtml == '' || metaTagHtml == null)
newItem.setFieldValue('metataghtml', '<meta name="description" content="' + nlapiGetFieldValue('salesdescription') + '">');
nlapiSubmitRecord(newItem);
}
}
And then this function is called as the "After Submit Function". Am I not calling in this in the right place for it to run for csv uploads?
This is my script deployment:
Goto "Setup > Import/Export > CSV Import preferences"
Make sure " RUN SERVER SUITESCRIPT AND TRIGGER WORKFLOWS" is checked.
How can I simply the below if statements?
if ( isset(var1) & isset(var2) ) {
if ( (var1 != something1) || (var2 != something2) ) {
// ... code ...
}
}
Seems like this could be condensed to only one IF statement but am not certain if I'd use an AND or OR
Boolean varsAreSets = isset(var1) & isset(var2); // or some other name that indicates what this is doing
Boolean someMeaningfulName = (var1 != something1) || (var2 != something2); // would suggest a meaningful name but don't know what this is accomplishing
if ( varsAreSets && someMeaningfulName ) {
// ... code ...
}
This makes the code very readable and helps you and whoever reads the code understand what these checks are actually doing.
if (isset(var1) && ((var1 != something1) || (var1 != something2)))
// ... code ...
}
You would use an and because you can only get to the // ... code ... part if both if-statements are true.
You can do:
if(isset(var1) && isset(var2) && ( (var1 != something1) || (var1 != something2) ) ){
//..code
}
As a general example:
if( cond1 && cond2 ) {
if( cond3 || cond4) {
// ...code..
}
}
The code will be executed only when both cond1 and cond2 are true and either of cond3 or cond3 is true.
It's a question of in what order your computer interprets boolean logic:
Take for example the following conditions:
A: False
B: True
if you were to write if (A && B) what your computer actually does is think:
Is A true? No.
Well, A and B can't be true because A isn't true. Therefore this statement is false. [computer ignores the rest of the logic]
Because of this, when you evaluate the statement isset(var1) && ( (var1 != something1) || (var1 != something2) ) it first checks isset(var1) and if that's false, then it skips the rest of the condition, just like your double-if statement.
if ( isset(var1) && isset(var2) && ( (var1 != something1) || (var2 != something2) ) ) {
// ... code ...
}
if (isset(var1) && isset(var2) && ((var1 != something1) || (var2 != something2)))
{
// ... code ...
}
Another option:
if (isset(var1) && isset(var2)
&& !(var1 == something1 && var2 == something2)) {
...
I think most of the examples above that have 1 IF may spit out an error if var1 or var2 is NOT set
(isset($var1) && isset($var2)) ? ($var1!='something1' && $var2!='something2') ? $go=TRUE : $go=FALSE : $go = FALSE;
if ($go){
echo 'hello';
}