Hi Geeks,
i want to add button on a custom form of a Custom Record type using User Event script. and when the button is pressed i am trying to Resolve a URL on client script which will give me the current record id which i will fetch on the User event Script and will load the record with that id and will fetch the values of that record and will pass it to the new record which is opened with nlapiGetNewRecord(). This approack is giving me an suiteScript Error of Invalid Record Type. But the Same approach worked properly for me on the Standard Record type of employee. Could you please help me in solving out this problem.
Even in this approcah on the custom record type i am not able to fetch value through request.getParameter but the same returns a value on Standard record.
User Event Script:
function beforeLoad(type, form, request)
{
// This dynamically adds a client-side button. It is
// analogous to the static definition of client-side
// buttons through form customization or script records.
// However, this operation will also add a button in view
// mode, and it won't work, so operation is filtered here.
if (type == 'edit') {
form.addButton('custpage_copy_contract', 'Copy CONTRACT','copyContract' );
}
// Contract data on current record
var NewContract = nlapiGetNewRecord();
var copyFrom = request.getParameter('custparam_sdr_copy_from');
nlapiLogExecution('DEBUG','RecordID',copyFrom);
// request from clicking Copy CONTRACT button
if (copyFrom != null && type =='create')
{
var OldContract = nlapiLoadRecord('customrecordcustrecord_new_contract',copyFrom);
nlapiLogExecution('DEBUG','Recordname',OldContract.getFieldValue('name'));
NewContract.setFieldValue('name', OldContract.getFieldValue('name'));
var name = NewContract.getFieldValue('name');
nlapiLogExecution('DEBUG','Name',name);
}
}
Client Script:
function copyContract()
{
// Return URL to contract "new" form.
var ContractURL = nlapiResolveURL('RECORD','customrecordcustrecord_new_contract');
// Add URL param to identify source contract.
// The param is retrieved in Before Load
ContractURL = ContractURL + '?custparam_sdr_copy_from=' + nlapiGetRecordId();
alert(ContractURL);
window.open(ContractURL, '_blank');
}