I have a UE script that saves entry from a custom ...
# suiteflow
r
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 }; });
b
i would recommend not doing deleting the record that you are creating. Standard behavior of created records is to view the newly created record
that will throw an error if that record was deleted
r
sorry maybe I was not clear in my question. I wanted to clear all the previous entries in the custom before creating a new one, as my script updates the same on vendor bill, after which, I do not want to keep the custom record entry to clear the clutter. Maybe a deletion piece at the beginning is something I am looking for so that every time the records are wiped clean before creating a new one. Thank you
b
again, probably dont want to do so in a usesr event script
honestly your first choice should probably be not to create the custom record in first place
if you dont want to create custom records, then just create a suitelet that displays a form with fields and do your update on submit of the form
if you are dead set on creating custom records, i would say to use a scheduled script to delete the records on a schedule