Created
November 14, 2018 17:47
-
-
Save iloveitaly/da9b88e318025ec53f5bc36ff4dafdcf to your computer and use it in GitHub Desktop.
Translate one field value on a NetSuite transaction to a value or record reference on another record. http://SuiteSync.io/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Author: <mike@suitesync.io> | |
Description: Maps an ID passed to a custom field on the NetSuite invoice to a | |
class record reference in Netsuite. | |
Link: https://gist.github.com/iloveitaly/da9b88e318025ec53f5bc36ff4dafdcf | |
Installation: | |
1. https://system.netsuite.com/app/common/scripting/uploadScriptFile.nl | |
2. User Event | |
3. Name: Map Custom Field to Class | |
4. ID: _suitesync_map_class | |
5. After Submit: afterSubmit | |
6. Deployments: Invoice on Create | |
*/ | |
// Utils | |
// https://gist.github.com/iloveitaly/db7d532e772b67f5b81d0199d094301f | |
var SOURCE_FIELD = 'memo'; | |
var DESTINATION_FIELD = 'class'; | |
var FIELD_MAPPING = { | |
"123":"101" | |
}; | |
function log(msg) { | |
nlapiLogExecution('DEBUG', msg); | |
} | |
function error(msg) { | |
nlapiLogExecution('ERROR', msg); | |
} | |
function isEmpty(obj) { | |
return obj === undefined || obj === null || obj === ""; | |
} | |
function afterSubmit() { | |
var recordType = nlapiGetRecordType(); | |
var recordId = nlapiGetRecordId(); | |
processAfterSubmit(recordType, recordId); | |
} | |
function processAfterSubmit(recordType, recordId) { | |
var sourceFieldValue = nlapiLookupField( | |
recordType, | |
recordId, | |
SOURCE_FIELD, | |
false | |
); | |
if(isEmpty(sourceFieldValue)) { | |
log("no value in source field"); | |
return; | |
} | |
var destinationFieldValue = FIELD_MAPPING[sourceFieldValue]; | |
if(isEmpty(destinationFieldValue)) { | |
log("no value in destination field"); | |
return; | |
} | |
nlapiSubmitField( | |
recordType, | |
recordId, | |
DESTINATION_FIELD, | |
destinationFieldValue | |
); | |
} | |
if(nlapiGetContext().getExecutionContext() == 'debugger') { | |
processAfterSubmit('invoice', 115); | |
} | |
'debug'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment