Last active
March 11, 2023 02:56
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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