RE: Delete all entries from a custom record from UE Script

I have a UE script that saves entry from a custom record into rejection reason on vendor bill. This part is working fine and this script is able to save the rejection reason to overcome the limitations of the Employee Centre users that do not have write access on vendor bill. However, since I am fairly new to scripting, I am not able to delete all the records from the custom record every time before the script executes. If someone could help me with the related code to delete all the existing records in the custom record, that would be great. I am adding my existing code for your reference.


/**

* @NApiVersion 2.x

* @NScriptType UserEventScript

* @NModuleScope SameAccount

*/

define(['N/record'],
function(record) {
/**

* Function definition to be triggered before record is loaded.

*

* @param {Object} scriptContext

* @param {Record} scriptContext.newRecord - New record

* @param {string} scriptContext.type - Trigger type

* @param {Form} scriptContext.form - Current form

* @Since 2015.2

*/

function beforeLoad(scriptContext)

{
}
/**

* Function definition to be triggered before record is loaded.

*

* @param {Object} scriptContext

* @param {Record} scriptContext.newRecord - New record

* @param {Record} scriptContext.oldRecord - Old record

* @param {string} scriptContext.type - Trigger type

* @Since 2015.2

*/

function beforeSubmit(scriptContext)

{
}
/**

* Function definition to be triggered before record is loaded.

*

* @param {Object} scriptContext

* @param {Record} scriptContext.newRecord - New record

* @param {Record} scriptContext.oldRecord - Old record

* @param {string} scriptContext.type - Trigger type

* @Since 2015.2

*/

function afterSubmit(scriptContext)

{

// Get the value of the Reject reason

var rejReason = scriptContext.newRecord.getValue({

fieldId: 'custrecord165' // Change this according to the internal id of the Field Reject Reason in the Custom Record Created

});
// Get the ID of the Vendor Bill Reject reason

var venbillID = scriptContext.newRecord.getValue({

fieldId: 'custrecord166' // Change this according to the internal id of the Field Reject Reason in the Custom Record Created

});
// populate the Reject Reason in the Vendor Bill Rejection Reason field

var id = record.submitFields({

type: record.Type.VENDOR_BILL,

id: venbillID,

values: {

custbody_rt_vendbill_rej_reason: rejReason //'testMSG01'

//custrecord165: 'testMSG'//rejReason // Change custbody1 to the internal id of the custom field Reject Reason in the Vendor Bill Record

},

options: {

enableSourcing: false,

ignoreMandatoryFields : true

}

});

}

return {

beforeLoad: beforeLoad,

beforeSubmit: beforeSubmit,

afterSubmit: afterSubmit

};

});
VishalThoughts Beginner Asked on July 20, 2021 in SuiteScript.
Add Comment
1 Answers

Hi,

I’m not sure I 100% follow why you would need to delete everything and at what stage.

Could you please share some screenshots to give us an idea of what’s on the bill and what these custom records look like?

Thanks,

Chris

Intermediate Answered 5 days ago.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.