Suitescript 2.0 MapReduce Script - mapreduce

I am very new to SuiteScript so I might be posting a lot of questions out here and hope you can all help.
My first question is why is my saved search not passing values on my MapReduce script? My code is below.
function getInputData() {
try{
log.debug("Get Input", "Initiated");
//Customer Search
var customerSearch = search.load({
id: 'customsearch_brad_itemprice'
});
log.debug("customerSearch", customerSearch);
log.debug("GetInputData", "Completed");
return [customerSearch];
}catch(exception){
log.debug("GetInputDate Error Message:",exception);
}
}
Here is an image of the debug log that shows the variables are null.
Suitescript 2.0 Debug Log:
Your insights are greatly appreciated!
Brad

You are returning an array of searches. You need to return a search object
Change this:
return [customerSearch];
to this:
return customerSearch;

Related

Flutter/Dart - Suggestions for how to Troubleshoot a Future?

Though it was working previously, for some reason my code has now stopped working. Though it fetches the required json data, the build doesn't render. The error on my app page which is supposed to display a page view was;
type String is not a subtype of 'Map<String,dynamic>'
But after some tweaks, now the error is;
invalid arguments(s)
I think I may have narrowed it down to the Future;
FutureBuilder<List<SpeakContent>> futureStage() {
return new FutureBuilder<List<SpeakContent>>(
future: downloadJSON(),
builder: (context, snapshot) {
if (snapshot.hasData) {
print("Snapshot has data.");
List<SpeakContent> speakcrafts = snapshot.data;
return new CustomPageView(speakcrafts);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
return new CircularProgressIndicator();
},
);
}
Future<List<SpeakContent>> downloadJSON() async {
final jsonEndpoint =
"http://example.com/getContent.php?";
final response = await get(jsonEndpoint);
if (response.statusCode == 200) {
List speakcrafts = json.decode(response.body);
debugPrint(speakcrafts.toString());
return speakcrafts
.map((speakcraft) => new SpeakContent.fromJson(speakcraft))
.toList();
} else
throw Exception('We were not able to successfully download the json data.');
}
Although it doesn't throw an error, I've noticed that it doesn't print my test statement after the "if (snapshot.hasData)" line.
Shouldn't I see "Snapshot has data." appear in my Android Studio console?
Based on what you provided, this
type String is not a subtype of 'Map<String,dynamic>'
must be this:
return Text('${snapshot.error}');
which means that your downloadJSON() threw an exception. In that case, print('Snapshot has data.'); never executes and the next case that I quoted above is executed.
Please put a breakpoint in the body of downloadJSON(), run it line by line and see what's thrown where.
ALSO, you are making an irrelevant but big mistake here. Do not call downloadJSON() like this. This function is executed at every re-render, which can be many times. You are initiating a JSON download at every redraw of your widget. This may stack up your backend bills... I explain it in this talk in more detail: https://youtu.be/vPHxckiSmKY?t=4771
After performing the troubleshooting tips as suggested by Gazihan Alankus and scrimau, I've found the culprit which was a single null entry in the MYSQL Database. Scary... gotta find out how to prevent that problem in the future.

Create a {if} statement in WHMCS

Im trying to create a specific IF statement on the clientareaproductdetails.tpl file in WHMCS - bottom line i'm trying to display some text on a page depending on the product the customer is looking at.
So this is what I tried (which does not work)
{if $id == '17'} something {else} nothing {/if}
So if the product ID = 17 then display 'something' otherwise display 'nothing.
Any ideas if/how this is possible?
Thanks in advance.
H
If by product id, you mean the package id, then it explains why your code didn't work. $id variable is for service id.
To achieve what you want, Add a hook file (say: custom_product_message.php) to includes/hooks/ folder.
Then add the following code:
<?php
add_hook('ClientAreaProductDetailsOutput', 1, function($service) {
if (!is_null($service)) {
if ($service['service']->packageId == 17) {
return "something";
} else {
return 'nothing';
}
}
return '';
});
The idea is to use ClientAreaProductDetailsOutput hook to display a text in the clientarea productdetails page.

Increment Number Property in AWS DynamoDB

How do I increment a number in AWS Dynamodb?
The guide says when saving an item to simply resave it:
http://docs.aws.amazon.com/mobile/sdkforios/developerguide/dynamodb_om.html
However I am trying to use a counter where many users may be updating at the same time.
Other documentation has told me to use and UpdateItem operation but I cannot find a good example to do so.
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html
However, I cannot find a method to implement the expression. In the future I will be adding values to arrays and maps. Will this be the same? My code is in Obj C
Currently my code looks like:
AWSDynamoDBUpdateItemInput *updateItemInput = [AWSDynamoDBUpdateItemInput new];
updateItemInput.tableName = #"TableName";
updateItemInput.key = #{
UniqueItemKey:#"KeyValue"
};
updateItemInput.updateExpression = #"SET counter = counter + :val";
updateItemInput.expressionAttributeValues =#{
#":val":#1
};
It looks like you're missing the last bit of code that actually makes the update item request:
AWSDynamoDB *dynamoDB = [AWSDynamoDB defaultDynamoDB];
[[dynamoDB updateItem:updateItemInput]
continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(#"The request failed. Error: [%#]", task.error);
}
if (task.exception) {
NSLog(#"The request failed. Exception: [%#]", task.exception);
}
if (task.result) {
//Do something with result.
}
return nil;
}];
In DynamoDB if you want to increment the value of the any propertie/field you can use the UpdateItemRequest with action option ADD. I used in android this method would update the existing value of the field. Let me share the code snippet. You can use any actions such like add,delete,put etc.
.....
AttributeValue viewcount = new AttributeValue().withS("100");
AttributeValueUpdate attributeValueUpdate = new AttributeValueUpdate().withAction(AttributeAction.ADD).withValue(viewcount);
updateItems.put(UploadVideoData.FIELD_VIEW_COUNT, attributeValueUpdate);
UpdateItemRequest updateItemRequest = new UpdateItemRequest().withTableName(UploadVideoData.TABLE_NAME)
.withKey(primaryKey).withAttributeUpdates(updateItems);
UpdateItemResult updateItemResult = amazonDynamoDBClient.updateItem(updateItemRequest);
....
You can see the above code will add 100 count into the existing value of that field.
This code is for android but the technique would remain the same.
Thank you.

Jenkins Job DSL, view creation not working properly

I am trying to create a list view via Groovy code for the Jenkins Job DSL plugin. After the run, the view is created, but no jobs are ever added. The code before the following snippet creates the build and deploy jobs, and I have verified that they are properly created before calling the view creation code. My code looks like the following. What am I missing?
def viewName = "${appName}"
listView(viewName) {
jobs {
name(buildJobName)
name(deployJobName)
}
}
Actually, I finally figured it out: Apparently, if you do not include the columns list, it will create the view with your jobs you added, but NOT DISPLAY THEM. Seems like a bug, because the view is useless, until you edit and check the columns you want to display. Adding the columns list fixed this.
listView(viewName) {
jobs {
names(buildJobName, deployJobName)
}
columns {
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
// ...
}
}
looking at the syntax for listView you aren't allowed a repeating name tag.
Something like this should work.
def viewName = "${appName}"
listView(viewName) {
jobs {
names("myDeployJob", "myBuildJob")
}
}

list database, collection and the number of document in batch mode

I started my MongoDB journey with the follow questions:
How to list all databases in MongoDB?
How to list all collections in a specific database?
How to list the number of documents in a specific collection?
The answers I found are as below:
show dbs
use <db name>
show collections
use <db name>
db.<collection name>.count()
All commands above were run in MongoDB shell manually. I would like to find a way to run these commands in a batch mode and get the results formatted like:
Would anyone like to share any ideas implementing it?
Any specific snippet would be greatly appreciated.
Well you can basically just create a JavaScript file and run it through the mongo shell if you want:
var db = db.getSiblingDB("admin");
var output = [];
db.runCommand({ listDatabases: 1 }).databases.map(
function(x){ return x.name }
).forEach(function(dbname) {
var cdb = db.getSiblingDB(dbname);
cdb.getCollectionNames().forEach(function(coll) {
var count = cdb.getCollection(coll).count();
output.push({
db: cdb,
collection: coll,
count: count
});
})
});
printjson( output );
And then just invoke it. I called the file "lister.js":
mongo lister.js
So you can use the print() or printjson() methods that are available to the shell to produce output how you want.
Otherwise consult the MongoDB driver for your favorite scripting language and implement something along the lines of what is shown above. All the basic methods and principles will be available.