Suitescript 2.0 - Call customer record to remove sublist lines - mapreduce

I am running into an issue with calling the customer record from a passed value on my mapped section of my mapreduce script. It is sending me a debug error of "TypeError: Cannot find function load in object 262059". Where 262059 is the internal ID of the customer passed from the getInputData function.
NetSuite debug image...
Here is the coding of the function that is throwing this error.
function removeLine(r,recordId){
try{
log.audit({title:"removeLine"});
var customerRecord = r.Load({
"type": r.Type.CUSTOMER,
"id": recordId,
"isDynamic": true
});
log.debug({details:"recordId = " + recordId});
var index = rec.getLineCount('item');
log.debug({detaisl:"index = " + index});
for (var cnt = 0; cnt < lineCount; cnt++)
{
log.audit({details:"Round " + cnt})
rec.selectLine({
sublistId: "item",
line: cnt
});
rec.removeLine({
sublistId: "item",
line: cnt
});
}
log.debug(recordId + " Item Pricing has been removed.");
record.save();
}catch(exception){
log.debug("removeLine Error Message:",exception);
}
}
What am I missing or not understanding? I appreciate your guidance.
Brad

I believe the problem lies where you load the record:
var customerRecord = r.Load({
"type": r.Type.CUSTOMER,
"id": recordId,
"isDynamic": true
});
It should be r.load, not r.Load as JavaScript is case-sensitive.

Related

How to append an item to an array in DynamoDB

Hi im trying to append an item to a dynamoDB array.
exports.handler = (event,context,callback)=>{
let params = {
Key:{
"userName":event.userName,
},
UpdateExpression:"set #FutureTrips = list_append(if_not_exists(#FutureTrips,empty_list),country)",
ExpressionAttributeNames:{
"#FutureTrips" : "FutureTrips"
},
ExpressionAttributeValues: {
':country':["Japan"],
":empty_list":[]
},
TableName:"Users"
};
dynamoDB.updateItem(params,function(err,data){
if(err){
console.log(err);
callback(null,err);
}
else{
callback(null,data);
}
});
};
it returns me "message": "Unexpected key '0' found in params.ExpressionAttributeValues[':country']",
im trying to append an item to an array called FutureTrips
thanks for the help
Based on the code you share, currently the UpdateExpression is not referring to the specified ExpressionAttributeValues.
UpdateExpression:"set #FutureTrips = list_append(if_not_exists(#FutureTrips,empty_list),country)"
Correct UpdateExpression should be;
UpdateExpression: "set #FutureTrips = list_append(if_not_exists(#FutureTrips, :empty_list), :country)"

Unable to extract a value from a JSON response to use as an enviroment variable in Postman

Pre Request:
//Create random number
let randomNum =
Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
//Set Random # as the Random ID
pm.environment.set("randomNum", randomNum);
Body:
{
"AccountNumber": "AA{{randomNum}}",
"Name": "AA {{randomNum}}",
"Reference": "AA 01",
"VatCodeId": 1,
"UserCreated": "James"
}
Response:
{
"Id": 18,
"AccountNumber": "AA7e40",
"Name": "AA 7e40",
"Reference": "AA 01",
"VatCodeId": 1,
"DateCreated": "2022-01-27T09:53:43.6734454+00:00",
"UserCreated": "James"
}
Note: The Id field is being created when a 200 response is being returned, this is unique to the DB and increments by 1 for every new account created.
I am trying to extract the Id and use that as a Enviroment variable so it can be chained (for deletion of accounts). The Test script is:
var accountUniqueId = JSON.parse(responseBody);
pm.environment.set("accountId", json.result.data.Id);
Though I have tried variations of it such as:
var accountUniqueId = pm.response.json();
pm.environment.set("accountId", jsonData.Id);
var accountUniqueId = pm.response.json();
pm.environment.set("accountId", jsonData.response.Id);
The response in the Test is showing as:
There was an error in evaluating the test script: ReferenceError: json is not defined
The Enviroment Variable is being created with a current value of:
[object Object].
This should do it:
let jsonData= pm.response.json();
pm.environment.set("accountId", jsonData.Id);

AWS RDS Data API executeStatement not return column names

I'm playing with the New Data API for Amazon Aurora Serverless
Is it possible to get the table column names in the response?
If for example I run the following query in a user table with the columns id, first_name, last_name, email, phone:
const sqlStatement = `
SELECT *
FROM user
WHERE id = :id
`;
const params = {
secretArn: <mySecretArn>,
resourceArn: <myResourceArn>,
database: <myDatabase>,
sql: sqlStatement,
parameters: [
{
name: "id",
value: {
"stringValue": 1
}
}
]
};
let res = await this.RDS.executeStatement(params)
console.log(res);
I'm getting a response like this one, So I need to guess which column corresponds with each value:
{
"numberOfRecordsUpdated": 0,
"records": [
[
{
"longValue": 1
},
{
"stringValue": "Nicolas"
},
{
"stringValue": "Perez"
},
{
"stringValue": "example#example.com"
},
{
"isNull": true
}
]
]
}
I would like to have a response like this one:
{
id: 1,
first_name: "Nicolas",
last_name: "Perez",
email: "example#example.com",
phone: null
}
update1
I have found an npm module that wrap Aurora Serverless Data API and simplify the development
We decided to take the current approach because we were trying to cut down on the response size and including column information with each record was redundant.
You can explicitly choose to include column metadata in the result. See the parameter: "includeResultMetadata".
https://docs.aws.amazon.com/rdsdataservice/latest/APIReference/API_ExecuteStatement.html#API_ExecuteStatement_RequestSyntax
Agree with the consensus here that there should be an out of the box way to do this from the data service API. Because there is not, here's a JavaScript function that will parse the response.
const parseDataServiceResponse = res => {
let columns = res.columnMetadata.map(c => c.name);
let data = res.records.map(r => {
let obj = {};
r.map((v, i) => {
obj[columns[i]] = Object.values(v)[0]
});
return obj
})
return data
}
I understand the pain but it looks like this is reasonable based on the fact that select statement can join multiple tables and duplicated column names may exist.
Similar to the answer above from #C.Slack but I used a combination of map and reduce to parse response from Aurora Postgres.
// declarative column names in array
const columns = ['a.id', 'u.id', 'u.username', 'g.id', 'g.name'];
// execute sql statement
const params = {
database: AWS_PROVIDER_STAGE,
resourceArn: AWS_DATABASE_CLUSTER,
secretArn: AWS_SECRET_STORE_ARN,
// includeResultMetadata: true,
sql: `
SELECT ${columns.join()} FROM accounts a
FULL OUTER JOIN users u ON u.id = a.user_id
FULL OUTER JOIN groups g ON g.id = a.group_id
WHERE u.username=:username;
`,
parameters: [
{
name: 'username',
value: {
stringValue: 'rick.cha',
},
},
],
};
const rds = new AWS.RDSDataService();
const response = await rds.executeStatement(params).promise();
// parse response into json array
const data = response.records.map((record) => {
return record.reduce((prev, val, index) => {
return { ...prev, [columns[index]]: Object.values(val)[0] };
}, {});
});
Hope this code snippet helps someone.
And here is the response
[
{
'a.id': '8bfc547c-3c42-4203-aa2a-d0ee35996e60',
'u.id': '01129aaf-736a-4e86-93a9-0ab3e08b3d11',
'u.username': 'rick.cha',
'g.id': 'ff6ebd78-a1cf-452c-91e0-ed5d0aaaa624',
'g.name': 'valentree',
},
{
'a.id': '983f2919-1b52-4544-9f58-c3de61925647',
'u.id': '01129aaf-736a-4e86-93a9-0ab3e08b3d11',
'u.username': 'rick.cha',
'g.id': '2f1858b4-1468-447f-ba94-330de76de5d1',
'g.name': 'ensightful',
},
]
Similar to the other answers, but if you are using Python/Boto3:
def parse_data_service_response(res):
columns = [column['name'] for column in res['columnMetadata']]
parsed_records = []
for record in res['records']:
parsed_record = {}
for i, cell in enumerate(record):
key = columns[i]
value = list(cell.values())[0]
parsed_record[key] = value
parsed_records.append(parsed_record)
return parsed_records
I've added to the great answer already provided by C. Slack to deal with AWS handling empty nullable character fields by giving the response { "isNull": true } in the JSON.
Here's my function to handle this by returning an empty string value - this is what I would expect anyway.
const parseRDSdata = (input) => {
let columns = input.columnMetadata.map(c => { return { name: c.name, typeName: c.typeName}; });
let parsedData = input.records.map(row => {
let response = {};
row.map((v, i) => {
//test the typeName in the column metadata, and also the keyName in the values - we need to cater for a return value of { "isNull": true } - pflangan
if ((columns[i].typeName == 'VARCHAR' || columns[i].typeName == 'CHAR') && Object.keys(v)[0] == 'isNull' && Object.values(v)[0] == true)
response[columns[i].name] = '';
else
response[columns[i].name] = Object.values(v)[0];
}
);
return response;
}
);
return parsedData;
}

How to format hours in grouping summary result in igGrid 2013.2?

I have grid with grouping and I group by one column and then make hours summary on another column like that :
name: "GroupBy",
type: "local",
columnSettings: [
{
columnKey: "codeName",
isGroupBy: true,
},
{
columnKey: "hour",
isGroupBy: false,
summaries: [
{
summaryFunction: "custom",
text: "Hours :",
customSummary: function (valuesList) {
var sumOfHours = 0.0;
var sumOfMinutes = 0.0;
for (i = 0; i < valuesList.length; i++) {
var split = valuesList[i].split(':');
sumOfHours += parseInt(split[0]);
sumOfMinutes += parseInt(split[1]);
}
sumOfHours += parseInt(sumOfMinutes / 60);
var minutesLeft = sumOfMinutes % 60;
return sumOfHours + ":" + minutesLeft;
}
}
]
}
],
summarySettings: {
//summaryFormat: "HH:MM" // What should I write here to get proper formatiing?
}
Now the problem is that whenever I get :
36 hours it displays 360.00 instead of 36:00
165 hours it displays 1,650.00 instead of 165:00
8 hours and 15 minutes it displays 815.00 insted of 8:15
34 hours and 15 minutes it displays as 3,415.00 instead of 34:15
I could not find anywhere in the docs how to display that properly. Can anybody help?
igGridGroupBy summary functions are expected to always return number type, which is not your case. That's why you see this behavior.
What you can do is to override the $.ig.formatter function (before initializing igGrid) which is used in Ignite UI and GroupBy feature for formatting values and inject your logic.
Here is an example:
var origFormatter = $.ig.formatter;
$.ig.formatter = function (val, type, format) {
if (format === "myFormat") {
return val;
}
return origFormatter.apply(arguments);
}
// Initialize igGrid here
And then set the summarySettings.summaryFormat = "myFormat" so that your logic kicks in.

Smartclient ListGrid RestDataSource not Populating

Code:
isc.RestDataSource.create({
ID: "restDS",
dataFormat: "xml",
fetchDataURL: "http://192.168.1.21:8282/uom/username=vikash%7C214057357158656/password=gbadmin/ModifiedOn=0",
fields: [
{name:"UOMId"},
{name:"UOMCode"},
{name:"UOMName"}
,
{name:"UOMType"},
{name:"UOMNoOfDecimals"},
{name:"UOMStatus"}
]
});
isc.ListGrid.create({
ID: "restList",
width:800, height:224, alternateRecordStyles:true,
dataSource: restDS,
fields:[
{name:"UOMId"},
{name:"UOMCode"},
{name:"UOMName"}
,
{name:"UOMType"},
{name:"UOMNoOfDecimals"},
{name:"UOMStatus"}
],
autoFetchData:true,
autoDraw: true
});
This Error I'm getting in browser
XML Parsing Error: no element found Location: moz-nullprincipal:{bc0868f9-b8df-4acd-b155-e58c50373d1b} Line Number 1, Column 1:
WebService Content
<ResponseJSON><Body><Datalist><UOMId>-1499999999</UOMId><UOMCode>MPM</UOMCode><UOMName>Meters Per Minute</UOMName><UOMType>2</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999997</UOMId><UOMCode>MM</UOMCode><UOMName>Milli Metres</UOMName><UOMType>0</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999996</UOMId><UOMCode>GSM</UOMCode><UOMName>Grammes per Square Metre</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999994</UOMId><UOMCode>LPM</UOMCode><UOMName>Litres Per Minute</UOMName><UOMType>2</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999993</UOMId><UOMCode>GRADE</UOMCode><UOMName>Grade</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999992</UOMId><UOMCode>GRAM</UOMCode><UOMName>Gram</UOMName><UOMType>1</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999991</UOMId><UOMCode>Degree</UOMCode><UOMName>Degree</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999990</UOMId><UOMCode>SET</UOMCode><UOMName>Set</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999989</UOMId><UOMCode>VOLT</UOMCode><UOMName>Volts</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999988</UOMId><UOMCode>AMPERE</UOMCode><UOMName>Ampere</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999987</UOMId><UOMCode>CELSIUS</UOMCode><UOMName>Celsius</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999986</UOMId><UOMCode>HZ</UOMCode><UOMName>Hertz</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999985</UOMId><UOMCode>HRS</UOMCode><UOMName>Hours</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999984</UOMId><UOMCode>LITERS</UOMCode><UOMName>Liters</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999983</UOMId><UOMCode>KWh</UOMCode><UOMName>KiloWatt Per Hour</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999982</UOMId><UOMCode>GRAVITY</UOMCode><UOMName>Gravity</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999981</UOMId><UOMCode>PRSR</UOMCode><UOMName>Pressure</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999980</UOMId><UOMCode>KVARh</UOMCode><UOMName>KVARh</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999979</UOMId><UOMCode>KVAh</UOMCode><UOMName>KVAh</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999978</UOMId><UOMCode>kVA</UOMCode><UOMName>kVA</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999977</UOMId><UOMCode>KW</UOMCode><UOMName>Kilo Watt</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999976</UOMId><UOMCode>VL</UOMCode><UOMName>V Line</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999975</UOMId><UOMCode>IL</UOMCode><UOMName>I Line</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999974</UOMId><UOMCode>TR</UOMCode><UOMName>TR</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999973</UOMId><UOMCode>PSIG</UOMCode><UOMName>PSIG</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999972</UOMId><UOMCode>FH</UOMCode><UOMName>Fahrenheit</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999971</UOMId><UOMCode>Y/N</UOMCode><UOMName>Y/N</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999970</UOMId><UOMCode>KL</UOMCode><UOMName>KL</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999969</UOMId><UOMCode>INR</UOMCode><UOMName>INR</UOMName><UOMType>1</UOMType><UOMNoOfDecimals>2</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999968</UOMId><UOMCode>RKVAH</UOMCode><UOMName>RKVAH</UOMName><UOMType>1</UOMType><UOMNoOfDecimals>2</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999967</UOMId><UOMCode>UNITS</UOMCode><UOMName>UNITS</UOMName><UOMType>1</UOMType><UOMNoOfDecimals>2</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999966</UOMId><UOMCode>SQFT</UOMCode><UOMName>SQFT</UOMName><UOMType>1</UOMType><UOMNoOfDecimals>2</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999965</UOMId><UOMCode>MTS</UOMCode><UOMName>Minutes</UOMName><UOMType>1</UOMType><UOMNoOfDecimals>2</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>269758049027601</UOMId><UOMCode>rt</UOMCode><UOMName>rt12</UOMName><UOMType>2</UOMType><UOMNoOfDecimals>1</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1500000000</UOMId><UOMCode>NOS</UOMCode><UOMName>Numbers</UOMName><UOMType>6</UOMType><UOMNoOfDecimals>3</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999998</UOMId><UOMCode>PPM</UOMCode><UOMName>Parts Per Million</UOMName><UOMType>3</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>-1499999995</UOMId><UOMCode>%</UOMCode><UOMName>Percentage</UOMName><UOMType>3</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>301246830151381</UOMId><UOMCode>cccc</UOMCode><UOMName>cccc</UOMName><UOMType>0</UOMType><UOMNoOfDecimals>1</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>306495824922361</UOMId><UOMCode>sd</UOMCode><UOMName>sd</UOMName><UOMType>1</UOMType><UOMNoOfDecimals>4</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>301243241629396</UOMId><UOMCode>asdf</UOMCode><UOMName>aaaa</UOMName><UOMType>0</UOMType><UOMNoOfDecimals>2</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist><Datalist><UOMId>545196525553078</UOMId><UOMCode>YTY</UOMCode><UOMName>QYRDY</UOMName><UOMType>1</UOMType><UOMNoOfDecimals>3</UOMNoOfDecimals><UOMStatus>1</UOMStatus></Datalist></Body><Status>200</Status><Total>41.0</Total></ResponseJSON>
plz help
Thank You
Your webservice returns incorrect response for RestDataSource. Example of expected response you can see in documentation here: RestDataSource
Another option that you have is to override response parsing. In your case it will be something like this:
isc.RestDataSource.create({
ID: "restDS",
dataFormat: "xml",
fetchDataURL: "http://192.168.1.21:8282/uom/username=vikash%7C214057357158656/password=gbadmin/ModifiedOn=0",
xmlRecordXPath:"/ResponseJSON/Body/*",
fields: [
{name:"UOMId"},
{name:"UOMCode"},
{name:"UOMName"},
{name:"UOMType"},
{name:"UOMNoOfDecimals"},
{name:"UOMStatus"}
] ,
transformResponse : function (dsResponse, dsRequest, data) {
var totalRows = data.selectNumber("//Total");
if (totalRows != null) dsResponse.totalRows = totalRows;
var startRow = data.selectNumber("//startRow");
if (startRow != null) dsResponse.startRow = startRow;
var endRow = data.selectNumber("//endRow");
if (endRow != null) dsResponse.endRow = endRow;
return dsResponse;
}
});
Note that I overwritten xmlRecordPath property and transformResponse method.