Requirement
We need to display the external Id to the custom field in Sales Channel record.
Solution
We need to create a custom field to store the external Id sourced from the standard External Id field.
Then the value is set to this custom field using a userevent script.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/currentRecord', 'N/record', 'N/search', 'N/redirect', 'N/ui/serverWidget'],
/**
* @param{currentRecord} currentRecord
* @param{record} record
* @param{search} search
* @param{redirect} redirect
* @param{serverWidget} serverWidget
*/
(currentRecord, record, search, redirect, serverWidget) => {
const beforeLoad = (scriptContext) => {
try {
if(scriptContext.type==="view" || scriptContext.type==="edit" ) {
var currentRecord = scriptContext.newRecord
var intId = currentRecord.id;
var externalId = currentRecord.getValue({
fieldId: 'externalid'
})
var custExtId = currentRecord.getValue({
fieldId: 'custrecord_jj_sc_externalid'
})
if ((custExtId == '') && (externalId != '')) {
record.submitFields({
type: 'customrecord_cseg_saleschannel',
id: intId,
values: {
custrecord_jj_sc_externalid: externalId
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
var checkValue = currentRecord.getValue({
fieldId: 'custrecord_jj_checkval'
})
if(!checkValue){
let setUrl = '<html><body><script type="text/javascript">window.location.reload();</script></body></html>'
var fieldValue = scriptContext.form.addField({
id: 'custpage_hiddenfield',
type: serverWidget.FieldType.INLINEHTML,
label: 'Text'
});
fieldValue.defaultValue = setUrl;
}
record.submitFields({
type: 'customrecord_cseg_saleschannel',
id: intId,
values: {
custrecord_jj_checkval: true
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
var checkValue1 = currentRecord.getValue({
fieldId: 'custrecord_jj_checkval'
})
}
} catch (e) {
log.debug('Error@BeforeLoad', e)
}
}
return {beforeLoad}
});