Skip to content

Instantly share code, notes, and snippets.

@rs77
Last active March 11, 2023 02:56
Show Gist options
  • Save rs77/24919e08d1ec9a21d2e1830284c91426 to your computer and use it in GitHub Desktop.
Save rs77/24919e08d1ec9a21d2e1830284c91426 to your computer and use it in GitHub Desktop.
This is the client script that needs to be uploaded to the File Cabinet. It does not need to be registered with a Script Record, but must satisfy the location of the User Event Script `clientScriptModule` (or the User Event Script's `clientScriptFileId`). More details here: http://scripteverything.com/update-record-with-button-when-viewing-in-br…
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/currentRecord', 'N/url'],
/**
* @param {record} record
* @param {currentRecord} currentRecord
* @param {url} url
*/
function (record, currentRecord, url) {
/**
* Updates the record's fields
* @param {String} someText
* @param {Number} someValue
*/
function myClientScript(someText, someValue) {
/** @type {CurrentRecord} */
const cr = currentRecord.get();
/** @type {String} */
const cType = cr.type;
/** @type {Number} */
const id = cr.id;
// Update the necessary fields...
record.submitFields({
type: cType,
id: id,
values: {
'custrecord_my_field1': someText,
'custrecord_my_field2': someValue
}
});
// Refresh the page, get URL of page then refresh...
/** @type {String} */
const myUrl = url.resolveRecord({
recordType: cType,
recordId: id,
isEditMode: false
});
window.location.replace(myUrl);
}
return {myClientScript}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment