I am in need of getting the text (display) value of a field to compare date ranges on the posting period. I have the formula below I am pushing in to a filter array with other filters I need to run
var columns = [];
columns.push(new nlobjSearchColumn('transactionnumber'));
columns.push(new nlobjSearchColumn('line'));
columns.push(new nlobjSearchColumn('item'));
columns.push(new nlobjSearchColumn('account'));
columns.push(new nlobjSearchColumn('amount'));
columns.push(new nlobjSearchColumn('vsoeallocation'));
columns.push(new nlobjSearchColumn('postingperiod'));
columns.push(new nlobjSearchColumn('srctranpostperiod','revrecschedule'));
columns.push(new nlobjSearchColumn('recuramount','revrecschedule'));
columns.push(new nlobjSearchColumn('jedoc', 'revrecschedule'));
columns[0].setSort();
columns[1].setSort();
var filter = [];
var formula = "case when TO_DATE({postingperiod.displayname}, 'MON YYYY') >= " + newselectedDate.getFullYear() + " then 1 else 0 end";
filter.push(new nlobjSearchFilter('revrecenddate', null, 'after', newselectedDate));
filter.push(new nlobjSearchFilter('type', null, 'anyof', ['CustInvc', 'CashSale']));
filter.push(new nlobjSearchFilter('templatename','revrecschedule','isnotempty'));
filter.push(new nlobjSearchFilter('deferredamount','revrecschedule','isnot', 0));
filter.push(new nlobjSearchFilter('formulanumeric', null, 'equalto', 1).setFormula(formula));
var search = nlapiCreateSearch('transaction', filter, columns);
var searchresult = search.runSearch();
Which in theory would work except that it gets the value of that field instead of the text (it turns out to be a non date value). I know there are ways once you have ran a search to get the text instead of the value (nlobjSearchResult.getText) but I have not found a way to do this within a formula.
Any ideas?
It seems that posting period might actually contain additional information that is apparently only used in functions like TO_DATE(). This may be because of the internal hierarchy of accounting periods. Or it might be because periods are List/Record fields in a single select box, so there is an ID for every posting period. To get around this, I've done the following (applied to your code):
var formula = "case when TO_DATE(SUBSTR({postingperiod},-8,8), 'MON YYYY') >= " + newselectedDate.getFullYear() + " then 1 else 0 end";
Which is basically adding a SUBSTR function to pick up the last 8 characters in the string to pass onto the date function.
Related
I am executing nlapiSearchRecord function on itemfulfillment record and the search is working fine but its return result with repetition/duplicate.
Below is the my working code i just want to know that which filter should i use to avoid repetition/duplicate record.
var filters = [
new nlobjSearchFilter('internalid', null, 'is',id),
new nlobjSearchFilter('mainline', null, 'is', 'F'),
new nlobjSearchFilter('shipping', null, 'is', 'F'),
new nlobjSearchFilter('taxline', null, 'is', 'F')
], columns = [
new nlobjSearchColumn('trandate'),
new nlobjSearchColumn('tranid'),
new nlobjSearchColumn('item'),
new nlobjSearchColumn('quantity'),
new nlobjSearchColumn('location')
];
var searchresults = lapiSearchRecord('itemfulfillment',null, filters, columns);
Below is the search result for your understanding and you can see that there is one item but it's is duplicated two times with positive quantity and one time with negative quantity.
[{"id":"123","recordtype":"itemfulfillment",
"columns":{"trandate":"2/1/2222","tranid":"xx-xxxx","status":{"name":"xxxx","internalid":"xxxx"},"item":{"name":"Test-1","internalid":"1111"},"quantity":1,"location":{"name":"xxxx","internalid":"xxx"}}},
{"id":"123","recordtype":"itemfulfillment",
"columns":{"trandate":"2/1/2222","tranid":"xx-xxxx","status":{"name":"xxxx","internalid":"xxxx"},"item":{"name":"Test-1","internalid":"1111"},"quantity":1,"location":{"name":"xxxx","internalid":"xxx"}}},{"id":"123","recordtype":"itemfulfillment",
"columns":{"trandate":"2/1/2222","tranid":"xx-xxxx","status":{"name":"xxxx","internalid":"xxxx"},"item":{"name":"Test-1","internalid":"xxxx"},"quantity":-1,"location":{"name":"xxxx","internalid":"xx"}}},{"trandate":"2/1/2222","tranid":"xx-xxxx","status":{"name":"xxxx","internalid":"xxxx"},"item":{"name":"XXXXX","internalid":"1111"},"quantity":1,"location":{"name":"xxxx","internalid":"xxx"}}},
{"id":"123","recordtype":"itemfulfillment",
"columns":{"trandate":"2/1/2222","tranid":"xx-xxxx","status":{"name":"xxx","internalid":"xxxx"},"item":{"name":"Test-2","internalid":"xyz"},"quantity":2,"location":{"name":"xxx","internalid":"xxxx"}}},{"id":"123","recordtype":"itemfulfillment","columns":{"trandate":"2/1/2222","tranid":"xx-xxxx","status":{"name":"xxxx","internalid":"xxxx"},"item":{"name":"Test-2","internalid":"xyz"},"quantity":2,"location":{"name":"xxxx","internalid":"10"}}},{"id":"123","recordtype":"itemfulfillment",
"columns":{"trandate":"2/1/2222","tranid":"xx-xxxx","status":{"name":"xxxx","internalid":"xxxx"},"item":{"name":"Test-2","internalid":"xyz"},"quantity":-2,"location":{"name":"xxxx","internalid":"xxxx"}}}]
Can you please guide me that how can i get items without any repetition/duplication.
The positive and negative quantities relate to the G/L entries created by the fulfillment.
Choose the G/L account for the side of the transaction you are interested in as another filter.
I am very new to NoSQL. My usecase is related to this.... Many users post messages and we store it in cloudant as different documents
{
id:random,
userid:xxx,
timestamp: 1449216912282,
msg: "Hi..."
}
I want to find out users who have not posted anything for last 5 days - Additionally I want to know if they have posted anything between last five and 10 days. If they have, then send a reminder mail to user to be active.
Which option would be better - views, search, cloudant query? Assume we will be having 1000s of posts per hour
I though of creating view - map(userid,timestamp) reduce as _stats and get max timestamp of each user. Then iterating through this list - we get users who did not post in last 5 days.
Other option was to use search index, get all userids between required timestamps. Compare both lists in application.
Is there any way to do it in a single query without overloading the application? Would Changing data format or creating appropriate index or view help?
If your data looked like this:
{
"_id": "abcdefghijklmon1234",
"userid" : "user1",
"timestamp": 1449739485035,
"msg": "Hi"
}
You could create a MapReduce view that created an index with a key consisting of [ 2015, 50, "user1" ], where "2015" is the year, "50" is the week number and "user1" is the document's userid. This can be achieved with a Map function like this:
function (doc) {
var getWeek = function(t) {
var date = new Date(t);
date.setHours(0, 0, 0, 0);
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
var week1 = new Date(date.getFullYear(), 0, 4);
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
};
if (typeof doc.timestamp == "number") {
var d = new Date(doc.timestamp);
var weeknum = getWeek(d.getTime());
var year = d.getFullYear();
emit( [ year, weeknum, doc.userid], null);
}
}
with a reduce of "_count". This allows queries such as ?startkey=[2015,49]&endkey=[2015,50]&group_level=3 to get a list of users who DID post last week. The list of users who didn't are the users who don't appear in the above list.
This isn't a solution to your problem in terms of "in the last 5 days", but uses week numbers instead.
I'm running into problems getting aging information for a customer record via a Restlet. Specficially I'm looking to get the aging, aging1, aging2, aging3, and aging4 fields from the Customer form for a given customer.
In the UI those values are found on the Customer form under the "Financial" section and look something like:
Current 1-30 Days 31-60 Days 61-90 Days Over 90 Days
1200.00 800.00 720.37 423.23 42.00
My Restlet code looks something like this:
…
cols[6] = new nlobjSearchColumn('aging');
var result = nlapiSearchRecord(data.record_type, null, filter, cols);
return result;
It works great with other fields such as "balance", but when I include the "aging" field and run my GET I see this error:
"error": {
"code": "SSS_INVALID_SRCH_COL",
"message": "An nlobjSearchColumn contains an invalid column, or is not in proper syntax: aging."
}
Clearly I'm not doing something right. Are those fields special in some way? How do I retrieve those values?
As far as I recall there is no search column for customers called 'aging'. This is the cause for the Invalid Search column error.
Also those fields might not be exposed either to the searches or suitescript which is why you are getting the error.
I actually contacted Netsuite and the previous comments are correct, those fields are not exposed, so I simply can't use them.
There is currently an enhancement request #238854 to expose these fields.
Easy enough to add in a suitescript context. e.g.
var aging = nlapiSearchRecord('invoice', null, [
new nlobjSearchFilter('daysoverdue', null, 'greaterthan', 0),
new nlobjSearchFilter('mainline', null, 'is', 'T'),
new nlobjSearchFilter('amountremaining', null, 'greaterthan', 0)
//for your RESTLet maybe you need this: , new nlobjSearchFilter('entity', null, 'is', data.customer_id)
], [
new nlobjSearchColumn('entity', null, 'group'),
new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('case when {daysoverdue} < 31 then {amountremaining} else 0 end'),
new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('case when {daysoverdue} between 31 and 60 then {amountremaining} else 0 end'),
new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('case when {daysoverdue} between 61 and 90 then {amountremaining} else 0 end'),
new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('case when {daysoverdue} > 90 then {amountremaining} else 0 end')
]);
aging.forEach(function (inv) {
var cols = inv.getAllColumns();
console.log(inv.getText('entity', null, 'group') +
' 0-30: ' + inv.getValue(cols[1]) +
' 31-60: ' + inv.getValue(cols[2]) +
' 61-90: ' + inv.getValue(cols[3]) +
' > 90: ' + inv.getValue(cols[4]));
});
Just a followup note on this: After almost three years Netsuite has still not acted on that enhancement request even though it has been voted for 30 times. Also the solution above results in numbers that are usually, but not always, in line with what is displayed by Netsuite.
I have a multivalue field called freeDaysPool which has multiple dates as strings. With the following code, the search does not return anything. If I leave that field out, the search works just fine with the two other fields. I read that I should use CONTAINS with multivalue fields but then I got query not understandable.
I've tried the back-end field as a date field and as a text field and tested all kinds of query combinations and date formats but no luck. Any help is really appreciated.
This is the search button code:
var query = new Array("");
var cTerms = 0;
// Field 1
var search01 = getComponent("searchcustomReservationField01").getValue();
if (#Contains(#Text(search01),"any city")){"";}
else {query[cTerms++] = '[customReservationField01]="' + search01 +'"'};
// Field 2
var search02 = getComponent("searchcustomReservationField02").getValue();
if (#Contains(#Text(search02),"any city")){"";}
else {query[cTerms++] = '[customReservationField02]="' + search02 + '"'};
// Date 1
var formatter = new java.text.SimpleDateFormat("d.M.yyyy");
query[cTerms++] = 'FIELD freeDaysPool = ' + formatter.format(getComponent("searchcustomDateField01").getValue());
// if query is still empty, we fill it with asterisk
if(query == "" || query == null){
query[cTerms++] = "*";
}
// make all as string
qstring = query.join(" AND ").trim();
sessionScope.searchString = qstring;
It will return query as:
[customReservationField01]="Oslo" AND [customReservationField02]="Oslo" AND FIELD freeDaysPool = 6.2.2015
AFAIK date values in formulas (and a query is a formula) have to be noted like
[06.02.2015]
to compare them. Just try to use your formular in the Notes Client to do a fulltext search. If you get results and no errors you found the correct format. That's at least the way I test queries as I'm not able to remind the syntax for years :-D
Thank you for all the help! Seems that Domino keeps the field type as date field even if you change it back to text field (noticed that from the notes FTsearch). I created completely new text field and added the days as strings in dd.MM.yyyy format. I also search them as strings and it works fine.
The changed code bit now looks like this:
// Date 1
var formatter = new java.text.SimpleDateFormat("dd.MM.yyyy");
query[cTerms++] = '[freeDays] CONTAINS "' + formatter.format(getComponent("searchcustomDateField01").getValue())+'"';
I have a fetch xml query and I would like to filter records with a date & time field.
I use the expression on or before but this seems to filter only date (without time).
FetchXml= ...
'<filter type="and">'+
'<filter type="or">'+
'<condition attribute="scheduledend" value="'+ currentdate +'" operator="on-or-before"/>'+
'<condition attribute="scheduledend" operator="null"/>'+
'</filter>'+
'</filter>'+
You can build the date and affect 0 to the time part. It's that you want?
var date = Xrm.Page.getAttribute("createdon").getValue();
var d = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);