First a nickname field was created by adding the following code in the jj_customrecord_bpau.tpl file and defining this template file in the entry file.
<div class="creditcard-edit-form" data-input="ccnickname" data-validation="control-group">
<label class="creditcard-edit-form-label" for="ccnickname">
{{translate 'Nickname on Card'}} <span class="creditcard-edit-form-label-required">*</span>
</label>
<div class="creditcard-edit-form-controls" data-validation="control">
<input type="text" class="creditcard-edit-form-input" id="ccnickname" name="ccnickname" maxlength="26" value="{{ccnickname}}">
</div>
</div>
The nickname value given was stored into the netsuite by using the Suitescript file and suitelet mentioned below:
Suitescript file:
define('jj.Customrecord.BPAU'
, [
'SC.Model', 'SC.Models.Init', 'underscore', 'CreditCard.Model', 'jj.Customrecord.extend'
]
, function (
SCModel, ModelsInit, _, CreditCardModel, Customrecord
)
{
'use strict';
_.extend(CreditCardModel, {
update: _.wrap(CreditCardModel.update, function(fn) {
var originalupdate = fn.apply(this, _.toArray(arguments).slice(1));
var flag ='update';
var argument =JSON.parse(JSON.stringify(arguments[2]));
console.error("argument",(argument));
var nickname = argument?argument["ccnickname"]:"";
console.error("nickname_update",nickname);
var id = argument?argument.internalid:"";
var customerID = nlapiGetUser();
var url = nlapiResolveURL('SUITELET', 'customscript1463', 'customdeploy_bpau1158', true);
var postdata = {
customerId: customerID,
nickname: nickname,
id:id,
flag:flag
};
var response = nlapiRequestURL(url, postdata, null, "POST");
var body = response.getBody();
console.error("body2", body)
return originalupdate;
}),
create: _.wrap(CreditCardModel.create, function(fn) {
var createOrigin = fn.apply(this, _.toArray(arguments).slice(1));
console.error('createOrigin', JSON.stringify(arguments));
var flag ='update';
var argument =JSON.parse(JSON.stringify(arguments[1]));
var nickname = argument?argument["ccnickname"]:"";
console.error("nickname_update",nickname);
var id = createOrigin;
var customerID = nlapiGetUser();
var url = nlapiResolveURL('SUITELET', 'customscript1463', 'customdeploy_bpau1158', true);
var postdata = {
customerId: customerID,
nickname: nickname,
id:id,
flag:flag
};
var response = nlapiRequestURL(url, postdata, null, "POST");
var body = response.getBody();
console.error("body2", body)
return createOrigin;
})
});
});
Suitelet:
/*******************************************************************************
* * Jobin & Jismi IT Services | Bastion Pacific-AU-SCA | This script will save the value entered from the website to the memo field on credit card edit page in the Customer Record *
* **************************************************************************
*
* Author: Jobin & Jismi IT Services LLP
*
* Date Created : 09/03/2023
*
* Created By : Jobin & Jismi IT Services LLP
*
* SCRIPT ID: customscript1463
*
* DEPLOYMENT ID: customdeploy_bpau1158
*
*
*
*
*
******************************************************************************/
function CreditCardExtension(request, response) {
try {
var lineID = request.getParameter('id');
var memoArray = [];
var ccObj = {};
var CustomerID = request.getParameter('customerId');
var flag = request.getParameter('flag');
var nickname = request.getParameter('nickname');
var CustRecord = nlapiLoadRecord('customer', CustomerID);
nlapiLogExecution('ERROR', 'lineID', lineID);
nlapiLogExecution('ERROR', 'CustomerID', CustomerID);
nlapiLogExecution('ERROR', 'flag', flag);
var resultJSON = formatResponse("SUCCESS", lineID, null);
var findline = CustRecord.findLineItemValue('creditcards', 'internalid', lineID);
nlapiLogExecution('ERROR', 'findline', findline);
if (flag === "update") {
CustRecord.selectLineItem('creditcards', findline);
CustRecord.setCurrentLineItemValue('creditcards', 'ccmemo', nickname);
CustRecord.commitLineItem('creditcards');
nlapiSubmitRecord(CustRecord);
}
if (flag === "get") {
if (findline>-1) {
CustRecord.selectLineItem('creditcards', findline);
var nickname_memo = CustRecord.getCurrentLineItemValue('creditcards', 'ccmemo');
ccObj[lineID] = nickname_memo;
} else {
var ItemCount = CustRecord.getLineItemCount('creditcards')
nlapiLogExecution('DEBUG', 'ItemCount', ItemCount);
for (var i = 1; i <= ItemCount; i++) {
nlapiLogExecution('DEBUG', 'line', i);
CustRecord.selectLineItem('creditcards', i);
var nickname_memo = CustRecord.getCurrentLineItemValue('creditcards', 'ccmemo');
var id = CustRecord.getCurrentLineItemValue('creditcards', 'internalid');
ccObj[id] = nickname_memo;
}
}
resultJSON = formatResponse("SUCCESS", ccObj, null);
}
response.write(resultJSON);
// }
} catch (error) {
nlapiLogExecution('DEBUG', 'CreditCardExtension', error);
var resultJSON = formatResponse("FAILURE", "ERROR WHILE Updating Nickname", "@main.updateQuote", error.message);
response.write(resultJSON);
}
}
function formatResponse(SHORT_RESPONSE, LONG_RESPONSE, FAULT_POSITION, MORE_INFO) {
var responseObj = {};
responseObj.response = (SHORT_RESPONSE) ? SHORT_RESPONSE : "FAILURE";
responseObj.message = (LONG_RESPONSE) ? LONG_RESPONSE : null;
responseObj.position = (FAULT_POSITION) ? FAULT_POSITION : null;
responseObj.information = (MORE_INFO) ? MORE_INFO : null;
return JSON.stringify(responseObj);
}