This will create custom records using suitescript 2.0 when ever customer submit a form.
first you have to create custom record manually then you have to add those custom_record_id for below code to create custom recrods.
Javascript
View File
// @module jnj.Myaccount.Myaccount
define('jnj.Myaccount.Myaccount.View'
, [
'jnj_myaccount_myaccount.tpl','jnj.Myaccount.Myaccount.SS2Model', 'SC.Configuration'
,'Backbone','Backbone.FormView','Backbone.CompositeView',"jnj.Myaccount.Myaccount.Model", 'GlobalViews.Message.View', 'Utils'
]
, function (
jnj_myaccount_myaccount_tpl,Configuration
,MyaccountSS2Model, Backbone ,BackboneFormView , BackboneCompositeView, MyaccountModel, GlobalViewsMessageView, Utils
)
{
'use strict';
// @class jnj.Myaccount.Myaccount.View @extends Backbone.View
return Backbone.View.extend({
template: jnj_myaccount_myaccount_tpl
, initialize: function (options) {
/* Uncomment to test backend communication with an example service
(you'll need to deploy and activate the extension first)
*/
BackboneCompositeView.add(this);
this.application = options.application;
this.model = new MyaccountModel();
BackboneFormView.add(this);
}
, events: {
'click #form-submit-button' : 'submitPatentButton',
}
, bindings: {
'[name="Signature"]': 'Signature'
}
, childViews: {
},
submitPatentButton : function(e) {
try{
var objects = {
customerName: $('#customerName').val(),
imageType: $('#Signature').val().split(',')[0].split('/')[1].split(';')[0]
}
console.log(objects, objects.Signature.length);
var url = Utils.getAbsoluteUrl(
getExtensionAssetsPath(
"Modules/Myaccount/SuiteScript2/Myaccount.Service.ss"
),
true
);
debugger
console.log(url);
$('#errorMessage').hide();
$('#successMessage').hide();
$('#loadMessage').show();
jQuery.post(url, objects).done(function (e) {
$('#loadMessage').hide();
console.log(this);
window.location.href= 'https://www.sca-developer.ml/sca-dev-2022-1-0/my_account.ssp#/signature'
$('#successMessage').show();
})
.fail(function (e) {
window.location.href= 'https://www.sca-developer.ml/sca-dev-2022-1-0/my_account.ssp#/signature'
$('#loadMessage').hide();
$('#errorMessage').show();
})
}
catch(e) {
console.log('err@barcode2View',e)
}
}
//@method getContext @return jnj.Myaccount.Myaccount.View.Context
, getContext: function getContext()
{
//@class jnj.Myaccount.Myaccount.View.Context
this.message = this.message || 'Hello World!!'
return {
message: this.message
};
}
});
});
Suitescript2
/**
* @NApiVersion 2.x
* @NModuleScope Public
*/
define('N/record'],function ( record) {
"use strict";
function createRecord(data) {
log.error('data', data);
if (data.request.method === 'POST') {
var customerName = data.request.parameters.customerName;
var imageType = data.request.parameters.imageType;
var signatureRec = record.create({
type: 'customrecord860',//record id
isDynamic: true
});
var customerNameForRec = customerName.split('_')[0]
var customerId = customerName.split('_')[1]
signatureRec.setValue({
fieldId: 'name',//column id
value: customerNameForRec//column value
});
signatureRec.setValue({
fieldId: 'custrecord_customer_sign_name',
value: customerNameForRec
});
signatureRec.setValue({
fieldId: 'custrecord_customer_sign_id',
value: customerId
});
signatureRec.setValue({
fieldId: 'custrecord_customer_sign_signature',
value: id
});
var recordId = signatureRec.save();
}
}
return data.response.write(JSON.stringify({success: 'success'}));
}
return {
service: createRecord
};
});
the above code will create the custom record in netsuite👇
