Looking to see if anyone has an example to pull Quantity Pricing from an item record with SuiteScript? I haven't been able to find anything online and don't even know how that would build out if it was SuiteScripted (since the qty is different per item). Anyone have anything that can show me how to do this?
Part of the issue with supplying sample code is that the code will be different depending on whether you also have multiple currencies available.
If you only have one currency you can get the prices for the price breaks as follows, The endpriceX values indicate the last quantity the associated price is applicable to:
strprice1 = myitem.getFieldValue('pricequantity1');
var valprice1 = myitem.getLineItemMatrixValue('price', 'price', lineno, 1);
valprice1 = parseFloat(valprice1);
var strprice2 = myitem.getFieldValue('pricequantity2');
var valprice2 = myitem.getLineItemMatrixValue('price', 'price', lineno, 2);
var endprice1 = parseInt(strprice2) - 1;
valprice2 = parseFloat(valprice2);
var strprice3 = myitem.getFieldValue('pricequantity3');
var endprice2 = parseInt(strprice3) - 1;
var valprice3 = myitem.getLineItemMatrixValue('price', 'price', lineno, 3);
valprice3 = parseFloat(valprice3);
var strprice4 = myitem.getFieldValue('pricequantity4');
var endprice3 = parseInt(strprice4) - 1;
var valprice4 = myitem.getLineItemMatrixValue('price', 'price', lineno, 4);
valprice4 = parseFloat(valprice4);
var strprice5 = myitem.getFieldValue('pricequantity5');
var endprice4 = parseInt(strprice5) - 1;
var valprice5 = myitem.getLineItemMatrixValue('price', 'price', lineno, 5);
valprice5 = parseFloat(valprice5);
Related
I have tried the below code, to split the latitude and longitude values, but its more complex. Is there any easy ways. Below shown is my code. I have used many replace functions as well split functions...
var data = [{"latitude":1.9,"longitude":103.57},{"latitude":1.338,"longitude":103.1},{"latitude":1.33,"longitude":103.7556}]
var re3 = /[\"\'\ ]+/g
data = data.replace(re3,'')
var re2 = /[\[\]\ ]+/g
data = data.replace(re2,'"')
var re1 = /[\'\r'\'\n'\{\ ]+/g
var data = data.replace(re1, '')
var re = /[\{\ ]+/g
var data = data.replace(re, '')
var re4 = /},/g
data = data.replace(re1, ';')
var re5 = /[\}\"\ ]+/g
data = data.replace(re, '')
let value = data.split(';');
console.log(value)
let valueArr = [];
value.forEach(geo => {
if (geo) {
let l = geo.split(',');
valueArr.push({
latitude: latLong[0],
longitude: latLong[1],
});
}
});
I would like to get output like
latitude: 1.9,
longitude: 1
and so on in the arr
03.57
That data seems to be in JSON format. Use JSON.parse().
var data = JSON.parse('[{"latitude":1.9,"longitude":103.57},{"latitude":1.338,"longitude":103.1},{"latitude":1.33,"longitude":103.7556}]');
console.log(data[0].latitude, data[0].longitude);
I have the following SuiteScript 2.0 code in a UserEvent where I would like to add an additional filter and columns to the loaded saved search.
A filter is working properly but how to get column value from Array which is added as an extra column in Saved search.
var filters = [];
filters.push(
['memo', 'is', 'Updated']
);
var filters = [];
filters.push(
['memo', 'is', 'Updated']
);
var columnsCust = [];
columnsCust.push(search.createColumn({
name: 'trandate'
}));
var mySearch = search.load({
id: 'customsearch_so_savedsearch'
});
//Add filters
mySearch.filterExpression = filters;
var filtersResult = mySearch.filterExpression;
//Add columns
mySearch.column = columnsCust;
var columnResult = mySearch.column;
var searchResult = mySearch.run().getRange({start: 0,end: 10});
for (var i = 0; i < searchResult.length; i++)
{
var date = searchResult[i].getValue({name: 'trandate'});
log.debug('date::' + date); //date::null
//it gives transactionnumber value Because this column exist in Saved
//search.
var transactionnumber = searchResult[i].getValue({name: 'transactionnumber'});
log.debug('transactionnumber::' + transactionnumber); //transactionnumber::112513
}
To add extra columns, filters or filterExpressions in a search object, firsrt you need to fetch the object from search-object and then update it.
For Search Columns
var searchColumns = mySearch.columns;
searchColumns.push(AdditionalColumns);
mySearch.columns = searchColumns;
For Search Filters
var searchFilters = mySearch.filters;
searchFilters.push(additionalFilters);
mySearch.filters = searchFilters;
For FilterExpressions
var searchFilterExpression = mySearch.filterExpression;
// push operator if searchObject contains filters
if (searchFilterExpression.length > 0) {
searchFilterExpression.push('and');
}
searchFilterExpression.push(additionalFilterExpression);
mySearch.filterExpression = searchFilterExpression;
Note: Check this out for further reading.
I've calculated the NDMI index based on the MCD43A4 (spatial resolution 500m) collection for an area where various water bodies exist.
What I want to do, is to mask out these water bodies from my collection, based on the Landsat Global Inland Water dataset (spatial resolution 30m),
but I have no idea how to do this.
The first thing I must do, is to change the spatial resolution of Landsat in order to match it with the MODIS one but I do not understand
how to this, should I use a type of Reduce?
Thanks
var geometry = /* color: #d63000 */ee.Geometry.Polygon(
[[[69.75758392503599, 50.151303763817786],
[71.60328705003599, 40.18192251959151],
[93.70777923753599, 41.54446477874571],
[91.86207611253599, 51.09912927236651]]]);
var dataset = ee.ImageCollection('GLCF/GLS_WATER')
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)}) ;
var water = dataset.select('water');
var imageCollection = ee.ImageCollection("MODIS/006/MCD43A4")
.filterBounds(geometry)
.map(function(image){return image.clip(geometry)})
.filter(ee.Filter.calendarRange(6,8,'month'));
var modNDMI = imageCollection.select("Nadir_Reflectance_Band2","Nadir_Reflectance_Band6","BRDF_Albedo_Band_Mandatory_Quality_Band2","BRDF_Albedo_Band_Mandatory_Quality_Band6");
/////////////////////////////////////////////////
var quality = function(image){
var mask1 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band2").eq(0);
var mask2 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band6").eq(0);
return image.updateMask(mask1).updateMask(mask2);
};
var clean_collection = modNDMI.map(quality);
var addNDMI = function(image) {
var ndmi = image.normalizedDifference(['Nadir_Reflectance_Band2', 'Nadir_Reflectance_Band6']).rename('NDMI');
return image.addBands(ndmi);
};
var ndmi = clean_collection.map(addNDMI);
var NDMI=ndmi.select('NDMI')
print(water)
//And from this point, I have no idea how to mask the water bodies based on the
//Landsat collection
It's not entirely obvious what you mean by "mask the waterbodies," but if this is not what you intend, then just use water_mask.not().
var gsw = ee.Image('JRC/GSW1_0/GlobalSurfaceWater');
var occurrence = gsw.select('occurrence');
// Create a water mask layer, and set the image mask so that non-water areas
// are opaque.
var water_mask = occurrence.gt(90).unmask(0);
Map.addLayer(water_mask)
var dataset = ee.ImageCollection('GLCF/GLS_WATER')
var water = dataset.select('water');
var imageCollection = ee.ImageCollection("MODIS/006/MCD43A4")
.filterDate('2017-01-01', '2018-12-31')
.filter(ee.Filter.calendarRange(6,8,'month'));
var modNDMI = imageCollection.select("Nadir_Reflectance_Band2","Nadir_Reflectance_Band6","BRDF_Albedo_Band_Mandatory_Quality_Band2","BRDF_Albedo_Band_Mandatory_Quality_Band6");
var quality = function(image){
var mask1 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band2").eq(0);
var mask2 = image.select("BRDF_Albedo_Band_Mandatory_Quality_Band6").eq(0);
return image.updateMask(mask1).updateMask(mask2);
};
var clean_collection = modNDMI.map(quality);
var addNDMI = function(image) {
var ndmi = image.normalizedDifference(['Nadir_Reflectance_Band2', 'Nadir_Reflectance_Band6']).rename('NDMI');
return image.addBands(ndmi).updateMask(water_mask);
};
var ndmi = clean_collection.map(addNDMI);
var NDMI=ndmi.select('NDMI')
Map.addLayer(NDMI)
See also this tutorial.
I have written a script which creates a billing schedule record for items on the creation of sales order using afterSubmit() user event script.
The billing schedule record gets created for every item,but it also should be set in line level field 'billing schedule' of the sales order.details in attachment
var rec =nlapiCreateRecord('billingschedule');
var res = itemname.substring(0, 40);
rec.setFieldValue('name',res);
rec.setFieldValue('initialamount',itemamount);
rec.setFieldValue('numberremaining','5');
rec.setFieldText('frequency','Daily');
var sub = nlapiSubmitRecord(rec,true);
if(sub!=null)
{
nlapiSetLineItemValue('item','billingschedule',i+1,sub);
}
You need to load the record in afterSubmit, otherwise it's read-only.
var salesOrderId = nlapiGetRecordId();
var soRec = nlapiLoadRecord('salesorder', salesOrderId);
// DO YOUR BILLING SCHEDULE CREATION LINE WORK
var soLines = soRec.getLineItemCount('item');
// SS1 indexes start at 1
for (var x = 1; x <= soLines; x++) {
var rec =nlapiCreateRecord('billingschedule');
var res = itemname.substring(0, 40);
rec.setFieldValue('name',res);
rec.setFieldValue('initialamount',itemamount);
rec.setFieldValue('numberremaining','5');
rec.setFieldText('frequency','Daily');
var sub = nlapiSubmitRecord(rec,true);
if(sub!=null) {
soRec.setLineItemValue('item','billingschedule', x, sub);
}
}
// Submit the record to save the values
nlapiSubmitRecord(soRec);
I have created vendor bill with nlapiCreateRecord, I can see the Bill record in the system with all items I want, but I can't relate it / link it to specific Purchase Order natively. When I'm using nlapiTransformRecord I'm deleting all records first from the PO and I'm adding new line items from CSV, but the native link/relationship between PO and Vendor Bill is missing. Here is my code created for the Bill Import from CSV:
function BillImport() {
var fromrecord;
var fromid;
var torecord;
var record;
var qty;
fromrecord = 'purchaseorder';
fromid = 23664;
torecord = 'vendorbill';
var loadedBillFile = nlapiLoadFile(5034);
var loadedBillString = loadedBillFile.getValue();
var BillLines = loadedBillString.split('\r\n'); //split on newlines
record = nlapiTransformRecord(fromrecord, fromid, torecord);
//trecord.setFieldValue('location', 1);
//trecord.setFieldValue('tranid', 'TEST!');
//var record = nlapiCreateRecord('vendorbill');
for (var j = record.getLineItemCount('item'); j>=1; j--)
{
record.removeLineItem('item',j);
}
for (var i = 1; i < BillLines.length; i++) {
var cols = BillLines[i].split(';');
var dsplit = cols[4].split(".");
var date = new Date(dsplit[2],dsplit[1],dsplit[0]);
currentDate = date.getMonth() + '/' + date.getDate() + '/' + date.getFullYear();
var entity = cols[0]; // OK HEAD
var currency = cols[1]; // OK LINE
var taxcode = cols[2]; // SKIP
var tranid = cols[3]; // OK HEAD
var trandate = currentDate; // OK HEAD FORMAT 11/3/2016
var location = 21;//cols[5]; // OK HEAD (ID of Location)
var item = cols[6]; // OK LINE
var quantity = cols[7];
var rate = parseFloat(cols[8]); // FLOAT
var amount = parseFloat(cols[9]);
var po = cols[10];
record.selectNewLineItem('item');
// Head Level
record.setFieldValue('createdfromstatus','');
record.setFieldValue('entity', entity);
record.setFieldValue('tranid', tranid);
record.setFieldValue('trandate', trandate);
record.setFieldValue('location', location);
// Line Level
record.setCurrentLineItemValue('item','item', item);
record.setCurrentLineItemValue('item','quantity', quantity);
record.setCurrentLineItemValue('item','rate', rate);
record.setCurrentLineItemValue('item','amount', amount);
//record.setCurrentLineItemValue('item','orderdoc', po);
//record.setCurrentLineItemValue('item','podocnum', po);
record.commitLineItem('item');
}
var id = nlapiSubmitRecord(record, true);
//trecord.setLineItemValue('item', 'amount', 1, 3 );
//var idl = nlapiSubmitRecord(trecord, true);
}
Here is the example CSV file:
Entity;Currency;Taxcode;Tranid;TranDate;Location;Item;Quantity;Rate;Amount;PO Internal ID
2449;USD;0.00 ;224676;11.3.2016;21;885;1;10;50;23664
2449;USD;0.00 ;224676;11.3.2016;21;870;2;10;120;23664
2449;USD;0.00 ;224676;11.3.2016;21;890;3;3;45;23664
2449;USD;0.00 ;224676;11.3.2016;21;948;4;4,66;38,5;23664
2449;USD;0.00 ;224676;11.3.2016;21;886;5;19,54;720;23664
I'm
If you don't want it to transform into a Vendor Bill (probably to avoid the PO from changing status) then you will need to create a custom relationship. You do this by:
Create a custom field on the Vendor Bill form of type "List/Record" and have the it be of "Transaction" type and check "Record is Parent". Save the Custom Field.
Go back to the custom field and edit it. Go to the display tab and select a "Parent Subtab", I usually select "Related Records". Save.
Now you just need to create a new Vendor Bill from scratch and save the record id of the PO in the Vendor Bill using the new custom field. Leave the "Created From" field blank, otherwise you would be linking them natively. The Bill should be listed under the "Related Records" tab or whichever subtab you selected on the PO.
Vendor bill import via CSV method is doable but you can bill the Purchase Order completely and not partially i.e. if you try to import a bill mentioning any referenced Purchase Order's link in it, it'll create a bill for all the remaining unbilled quantities of the Purchase Order rather than the quantity you have mentioned.
Actually if you mention any quantity AND Purchase Order link BOTH in the CSV file then it will throw an error.
Below is the part I found from the SuiteAnswers with answer id as 10020.
Refer the supporting image here