-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vendor_AfterSubmit_Script.ts
63 lines (56 loc) · 2.3 KB
/
Vendor_AfterSubmit_Script.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @NAPIVersion 2.0
* @NScriptType UserEventScript
*/
import * as http from 'N/http'
import * as record from 'N/record'
import * as log from 'N/log';
import { EntryPoints } from 'N/types';
export var afterSubmit: EntryPoints.UserEvent.afterSubmit = function sendProductData(context: EntryPoints.UserEvent.afterSubmitContext) {
const addressListId = "addressbook";
var prodNewRecord = context.newRecord;
var addresses = getSublistObjects(prodNewRecord, addressListId);
var defaultBilling = addresses.filter(function (a) { return a.defaultbilling; })[0];
// log.debug("BILLING ADDR", JSON.stringify(defaultBilling));
var vendorID = prodNewRecord.getValue("entityid");
var address = defaultBilling.addr1_initialvalue;
var city = defaultBilling.city_initialvalue;
var dropdownState = defaultBilling.displaystate_initialvalue;
var zip = defaultBilling.zip_initialvalue;
// log.debug("VALUES", "sfdcNum: " + JSON.stringify(sfdcNum) + ", poNum: " + JSON.stringify(poNum));
var postData: any = { "vendorID": vendorID, "address": address, "city": city, "dropdownState": dropdownState, "zip": zip, "source": "Netsuite", "object": "Vendors" };
postData = JSON.stringify(postData);
var header = [];
header['Content-Type'] = 'application/json';
header['Accept'] = 'application/json';
var apiURL = 'http://70.61.44.2:9090/ws/simple/executeGenericWebService';
try {
var response = http.post({
url: apiURL,
headers: header,
body: postData
});
var newSFID = response.body;
newSFID = newSFID.replace('\n', '');
} catch (er02) {
log.error('ERROR', JSON.stringify(er02));
}
}
function getSublistObjects(record: record.Record, sublistId: string) {
var subListFields = record.getSublistFields({ sublistId: sublistId });
var rowCount = record.getLineCount({ sublistId: sublistId });
var list = [];
for (var r = 0; r < rowCount; r++) {
var obj = {};
for (var f = 0; f < subListFields.length; f++) {
var value = record.getSublistValue({
sublistId: sublistId,
fieldId: subListFields[f],
line: r
});
obj[subListFields[f]] = value;
}
list.push(obj);
}
return list;
}