Badly need help..
I am trying to add a condition inside my nlapiSearchRecord API but the condition is not being followed. Though it is running fine with no errors, the suitelet is looking at the first parameter even if it should follow the else statement.
Please refer at the line: var arrSearchResults = nlapiSearchRecord(searchRecordType, null, arrSearchFilters, (searchRecordType = 'transaction') ? arrSearchColumnsTrans : arrSearchColumnsCustomers) || [];
Even though the searchRecordType is 'customers', it still follows the arrSearchColumnsTrans, not the arrSearchColumnsCustomers
var searchRecordType = request.getParameter ('custpage_rectype');
var searchLookupText = request.getParameter ('custpage_lookuptext');
var searchLookupField = request.getParameter ('custpage_lookupfield');
var searchParameter = request.getParameter ('custpage_searchparam');
var arrSearchFilters = [new nlobjSearchFilter(searchLookupField, null, searchParameter, searchLookupText)];
var arrSearchColumnsTrans = [new nlobjSearchColumn('internalid'),
new nlobjSearchColumn('type'),
new nlobjSearchColumn('entity')];
var arrSearchColumnsCustomers = [new nlobjSearchColumn('internalid'),
new nlobjSearchColumn('entityid'),
new nlobjSearchColumn('companyname')];
var arrSearchResults = nlapiSearchRecord(searchRecordType, null, arrSearchFilters,
(searchRecordType = 'transaction') ? arrSearchColumnsTrans : arrSearchColumnsCustomers) || [];
var objVal = {};
for (var i = 0, ii = arrSearchResults.length; i < ii; i++)
{
var val = arrSearchResults[i];
objVal[val.getId()] = {};
objVal[val.getId()].tranid = val.getValue('tranid');
objVal[val.getId()].internalid = val.getValue('internalid');
objVal[val.getId()].type = val.getValue('type');
objVal[val.getId()].entityid = val.getValue('entityid');
objVal[val.getId()].entity = val.getText('entity');
}
Your ternary statement doesn't actually have a conditional:
(searchRecordType = 'transaction') ? ...
Because you're using =, you're just assigning the value of 'transaction' to searchRecordType. If you want to compare the two values instead, you'll want to use == or ===.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality
Thank you!
All good now..
var arrSearchResults = (searchRecordType === 'transaction') ? nlapiSearchRecord(searchRecordType, null, arrSearchFilters, arrSearchColumnsTrans) : (searchRecordType === 'item') ? nlapiSearchRecord(searchRecordType, null, arrSearchFilters, arrSearchColumnsItems) : nlapiSearchRecord(searchRecordType, null, arrSearchFilters, arrSearchColumns) || [];
Related
I'm doing a while loop to get records in a categorised view.
I want to return only the first record that meet the if condition and not the whole category.
The code below returns all the records in the category that passed the 'if' condition.
var vView:NotesView = database.getView("Document");
var doc:NotesDocument = vView.getFirstDocument();
while(doc != null){
if(doc.getItemValueString("Status") == 'Live'){
//get the first in the category here where condition is met
var pVersion = doc.getItemValueString("Version");
var pPro = doc.getItemValueString("Pro");
}
var tmpDoc:NotesDocument = vView.getNextDocument(doc);
doc.recycle();
doc = tmpDoc;
}
View below:
The arrow shows the records that I would like to return.
Your graphic suggest you want the first document in each category that meets a condition?
For the question as asked:
var continueSearch = true
while(doc != null && continueSearch) {
if(...) {
...
continueSearch = false;
}
...
}
That should do it
Try breaking out of the loop once the doc is found:
var vView:NotesView = database.getView("Document");
var doc:NotesDocument = vView.getFirstDocument();
var done = false;
while(doc != null && !done){
if(doc.getItemValueString("Status") == 'Live'){
//get the first in the category here where condition is met
var pVersion = doc.getItemValueString("Version");
var pPro = doc.getItemValueString("Pro");
done = true;
}
var tmpDoc:NotesDocument = vView.getNextDocument(doc);
doc.recycle();
doc = tmpDoc;
}
Did you look at the notesviewnavigator class ?
var vView:NotesView = database.getView("Document");
var doc:NotesDocument = vView.getFirstDocument();
var product;
while(doc != null){
if(product != doc.getItemValueString("Product")){
//get only the first in the category
var pVersion = doc.getItemValueString("Version");
var product = doc.getItemValueString("Product");
}
var tmpDoc:NotesDocument = vView.getNextDocument(doc);
doc.recycle();
doc = tmpDoc;
}
I am trying to create within knockout mapping some computed variables. The problem is when adding new elements to the children's children after the mapping, my computed variables don't update with new elements added to the observableArray
Please could you help?
Here is the code, also attached a jsFiddle
Thanks
https://jsfiddle.net/r3pasftb/18/
var data = {id: 45, Name: "Whatever Name",
Stages: [{stageID: 1, StageName: "Stage1", Team: [{Name: "Team1", FeesAllocated: 500}, {Name: "Team2", FeesAllocated: 200}]}, {stageID: 1, StageName: "Stage1", Team: []}]};
mappingTeam = function(options){
var teamSelf = options != null ? options : this;
teamSelf.Name = ko.observable(options != null ? options.Name : 0);
teamSelf.FeesAllocated = ko.observable(options != null ? options.FeesAllocated : 0);
return teamSelf;
};
mappingStages = function(options){
var stageSelf = options != null ? options : this;
stageSelf.StageID = ko.observable(options != null ? options.StageID : 0);
stageSelf.StageName = ko.observable(options != null ? options.StageName : 0);
stageSelf.Team = ko.observableArray(ko.utils.arrayMap(stageSelf.Team, mappingTeam ));
stageSelf.Length = ko.computed(function(){
return stageSelf.Team().length;
});
//I need this value to be updated, but do nothing with new elements created after the mapping
stageSelf.TotalStageFees = ko.computed(function(){
var total = 0;
ko.utils.arrayForEach(stageSelf.Team(), function (team) {
total += team.FeesAllocated();
});
return total;
});
return stageSelf;
};
var mappingOptions = {
create: function (options) {
return new function () {
var self = options.data;
//Here map Stage Array
self.Stages = ko.observableArray(ko.utils.arrayMap(self.Stages, mappingStages ));
ko.mapping.fromJS(self, {}, this);
};
}
};
//Map my object with child and subchild
var self = ko.mapping.fromJS(data, mappingOptions);
console.log(self.Stages()[0].TotalStageFees())
console.log(self.Stages()[0].Length())
//Add new TeamMember to first Stage
self.Stages()[0].Team.push(new mappingTeam({Name: "Team3", FeesAllocated: 50}));
//As you see, non TotalStageFees or Lenght are updated
console.log(self.Stages()[0].TotalStageFees())
console.log(self.Stages()[0].Team())
console.log(self.Stages()[0].Length())
var stAccNum = '1013320075';
var stAccName = 'ABC SINGAPORE PTE LTD';
var arrRecItem = new Array();
for (var x = 0; x < 3; x++) {
arrRecItem[x] = [];
}
;
arrRecItem[0][0] = '2';
arrRecItem[0][1] = 'DBSSSGSGXXX';
arrRecItem[0][2] = '301234567';
var arrParams = {
custparam_jason_my_acc_num : stAccNum,
custparam_jason_my_acc_name : stAccName,
***custparam_jason_rec_item_arr : arrRecItem*** };
nlapiSetRedirectURL('SUITELET', 'customscript_jason_ss_bulk_payment_file',
'customdeploy_jason_ss_bulk_payment_file', null, arrParams);
As shown in code above, I failed to pass the array arrRecItem in arrParams. Is there any ways to pass this array as custparam and pass to suitelet?
Thank you.
Sure, just use JSON.stringify(arrRecItem) and then parse it on the suitelet with JSON.parse(arrRecItem)
I have create a group in phaserjs
this.fruitsOutline = this.game.add.group();
After that I have added few sprites in it. Everything is working correctly. Now if want to access this.fruitsOutline, from inside of a onDragStart event handler, it is giving undefined
var GameState = {
init:function(){
this.physics.startSystem(Phaser.Physics.ARCADE);
},
create: function () {
var innerImgPos = {x:150,y:200};
var outlineImgPos = {x:460,y:200};
var FIXED_DISTANCE_Y = 150;
var gameData = [
//...some data
];
this.background = this.game.add.sprite(0, 0, 'background');
this.overlapHappen = false;
this.startPos = {x:150,y:197};
this.fruitsOutline = this.game.add.group();
this.fruitsInner = this.game.add.group();
for(var i=0; i<gameData.length; i++){
fruitOuter = this.fruitsOutline.create(outlineImgPos.x,((outlineImgPos.y+25)*i)+FIXED_DISTANCE_Y,gameData[i].fruit_outline.img);
fruitOuter.name = gameData[i].fruitName;
fruitOuter.anchor.setTo(.5);
fruitOuter.customParams = {myName:gameData[i].fruit_outline.name};
this.game.physics.arcade.enable(fruitOuter);
fruitOuter.body.setSize(100,100,50,50);
fruitInner = this.fruitsInner.create(innerImgPos.x,((innerImgPos.y+25)*i)+FIXED_DISTANCE_Y,gameData[i].fruit_inner.img);
fruitInner.name = gameData[i].fruitName;
fruitInner.anchor.setTo(0.5);
fruitInner.inputEnabled = true;
fruitInner.input.enableDrag();
fruitInner.input.pixelPerfectOver = true;
fruitInner.originalPos = {x:fruitInner.position.x,y:fruitInner.position.y};
this.game.physics.arcade.enable(fruitInner);
fruitInner.body.setSize(100,100,50,50);
fruitInner.customParams = {myName:gameData[i].fruit_inner.name,targetKey:fruitOuter,targetImg:gameData[i].fruit_outline.name};
fruitInner.events.onDragStart.add(this.onDragStart);
fruitInner.events.onDragStop.add(this.onDragStop,this);
}
},
update: function () {
},
onDragStart:function(sprite,pointer){
console.log(this.fruitsInner) //this gives undefined I expect an array
},
onDragStop:function(sprite,pointer){
var endSprite = sprite.customParams.targetKey;
console.log(endSprite);
this.stopDrag(sprite,endSprite)
},
stopDrag:function(currentSprite,endSprite){
var currentSpriteRight = currentSprite.position.x + (currentSprite.width / 2);
if (!this.game.physics.arcade.overlap(currentSprite, endSprite, function() {
var currentSpriteTarget = currentSprite.customParams.targetImg;
var endSpriteName = endSprite.customParams.myName;
console.log(currentSpriteTarget,endSpriteName);
if(currentSpriteTarget === endSpriteName){
currentSprite.input.draggable = false;
currentSprite.position.copyFrom(endSprite.position);
currentSprite.anchor.setTo(endSprite.anchor.x, endSprite.anchor.y);
}
console.log(currentSprite.width);
})) {
//currentSprite.position.copyFrom(currentSprite.originalPosition);
currentSprite.position.x = currentSprite.originalPos.x;
currentSprite.position.y = currentSprite.originalPos.y;
}
},
render:function(){
game.debug.body(this.fruitsInner);
//game.debug.body(this.orange_outline);
}
}
You're missing the context when adding the drag callback.
Try that (adding this as the second argument):
fruitInner.events.onDragStart.add(this.onDragStart, this);
Oh, and inside the callback (or anywhere in the state) this.fruitsInner will be an instance of Phaser.Group, not an array like that comment says. The array you're looking for is probably this.fruitsInner.children.
Re-entering the code as follows, with combined suggestions from #bknights & #prasun
function main_GetVendorItems(request, response) {
response.write(JSON.stringify(getVendorItems(request)));
}
function getVendorItems(request) {
var vendorid = request.getParameter('vendor');
nlapiLogExecution('DEBUG', 'searchRes', 'Searching For Vendor ID: '+vendorid );
var filters = new Array();
var columns = new Array();
filters[0] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0);
filters[1] = new nlobjSearchFilter('othervendor', null, 'is', [vendorid] );
columns[0] = new nlobjSearchColumn('itemid');
columns[1] = new nlobjSearchColumn('entityid', 'vendor');
columns[2] = new nlobjSearchColumn('vendorcost');
columns[3] = new nlobjSearchColumn('vendorcode');
columns[4] = new nlobjSearchColumn('vendorpricecurrency');
var searchresults = nlapiSearchRecord('item', null, filters, columns );
//for test test each element of the array
(searchresults || []).forEach(function(res){
nlapiLogExecution('DEBUG', 'searchRes', res instanceof nlobjSearchResult);
})
return searchresults;
}
The calling function as below:
function test () {
var vendorID = nlapiGetFieldValue('custrecordvpr_supplier'); alert('searching for vendor ID: '+vendorID );
var url = nlapiResolveURL('SUITELET', 'customscriptls_getvendoritems', 'customdeployls_getvendoritems', true);
var params = {}
params['vendor'] = vendorID;
var response = nlapiRequestURL(url, params);
var VendorItemsSublist = response.getBody();
nlapiSetFieldValue('custrecordvpr_comment',VendorItemsSublist );
}
I've got a comment field on my custom record/form which shows the returned object. On the code above, what's really strange, is I'm not getting any information being added to the execution log,even the first entry where it should post the vendor id being searched for.
I've checked the script and deployment records, and there is nothing untoward or amiss there... I have got to be missing something extremely simple.
Incidentally, the code is being called by a "Test" button on my custom form.
It looks like you are not writing properly to the response object in Suitelet.
function main_GetVendorItems(request, response) {
response.write(JSON.stringify(getVendorItems(request)));
}
function getVendorItems(request) {
var vendorid = request.getParameter('vendorid');
var filters = new Array();
var columns = new Array();
filters[0] = new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0);
//filter should be on vendor
filters[1] = new nlobjSearchFilter('vendor', null, 'anyof', vendorid );
columns[0] = new nlobjSearchColumn('itemid');
columns[1] = new nlobjSearchColumn('entityid', 'vendor');
columns[2] = new nlobjSearchColumn('vendorcost');
columns[3] = new nlobjSearchColumn('vendorcode');
columns[4] = new nlobjSearchColumn('vendorpricecurrency');
var searchresults = nlapiSearchRecord('item', null, filters, columns );
//for test test each element of the array
(searchresults || []).forEach(function(res){
nlapiLogExecution('DEBUG', 'searchRes', res instanceof nlobjSearchResult);
})
return searchresults;
}
Also, make sure vendor id is specified in request parameter
var url = nlapiResolveURL('SUITELET', 'customscriptls_getitemvendors', 'customdeploy_getitemvendors', true);
var params = {}
params['itemid'] = itemID ; // itemID is passed to this function.
params['vendorid'] = vendorID ; // vendorID is passed to this function.
var response = nlapiRequestURL(url, params);
var itemVendorSublist = response.getBody();
If you're trying to query on item vendor then simply try
filters[1] = new nlobjSearchFilter('vendor', null,'anyof', vendorid );
This works in a console window. I suspect you are not supplying the numeric internal id in your parameter:
var vendorid = 43; // or 32 values from my test account. Want to confirm that the code works whether vendor is item's preferred vendor or not.
nlapiSearchRecord('item', null, [
new nlobjSearchFilter('vendorcost', null, 'greaterthan', 0),
new nlobjSearchFilter('internalid', 'vendor', 'anyof', [vendorid]), //numeric value
new nlobjSearchFilter('internalid', null, 'is', '42') // limit results for testing
], [
new nlobjSearchColumn('itemid'),
new nlobjSearchColumn('entityid', 'vendor'),
new nlobjSearchColumn('vendorcost'),
new nlobjSearchColumn('vendorcode'),
new nlobjSearchColumn('vendorpricecurrency')
]).forEach(function(it) {
console.log("%s from %s", it.getValue('itemid'), it.getValue('entityid', 'vendor'));
});
Although I've been working with Netsuite since 2002 I've never returned a set of search results directly from a Suitelet. I've seen that a couple of times recently in people's answers on this forum but I still find it a bit amusing.
If I were writing this I'd have tended to do the following:
var results = (nlapiSearchRecord(...) || []).map(function(res){
return { id:res.getId(), vendorName: res.getValue('entityid', 'vendor')...};
});
response.setContentType('JAVASCRIPT');
response.write(JSON.stringify(results));
Actually there's generally a little more. I have a sublime text snippet that I use for suitelet responses that handles a couple of common JSONP patterns (e.g. if you were calling this from a website):
function _sendJSResponse(request, response, respObject){
response.setContentType('JAVASCRIPT');
var callbackFcn = request.getParameter("jsoncallback") || request.getParameter('callback');
if(callbackFcn){
response.writeLine( callbackFcn + "(" + JSON.stringify(respObject) + ");");
}else response.writeLine( JSON.stringify(respObject) );
}