How to write script on Currency Revaluation Record?
Hi there,
Netsuite have many limitations and there are some work around for them also. Most of time solutions are too simple to implement but too tough to find.
In this post, we are going to discuss about one of such limitation and how to overcome it.
During Currency Revaluations , Class , Department and Location greyed out if "Include Children" checkbox is checked. Once submitted , it will create "Currency Revaluation" record with "Class", "Location" and "Department" empty.
Netsuite does not allow writing script and workflows on Currency Revaluation record, so one person can not write user event script or Workflow on create mode to update location, department and class.
Solution:
To fix this issue, write a saved search on Currency Revaluation . Use this saved search in Scheduled Script .Use submit Fields to populate field on record.
Step 1: Create Saved Search on Currency Revaluation Record.
Step 1a: Add Filter "Main Line is True" and "Department or Class or Location is not populated"
Step 1b: Add column in Saved Search if you want to use values from columns.
Step 2: Write Scheduled Script and Use saved search from Step 1.
Step 3: Inside Results, populate field using submitFields() method.
Code:
/***@NApiVersion 2.x
*@NScriptType ScheduledScript
*/
define(['N/search', 'N/record'],
function (search, record){
function myScript(context){
try
{
var useSearch = search.load({
id: 'useSavedSearchIdHere'
});
var mResultsSet = useSearch.run();
var useSearchResult = mResultSet.getRange({
start: 0,
end: 1000
});
for(var abc=0; abc < useSearchResult.length; abc++)
{
try
{
var results = useSearchResult[abc];
var useId = results.id;
var useRecType = results.recordType;
var useColumns = results.columns;
//var column0 = results.getValue(useColumns[0]);
record.submitFields({
type: useRecordType,
id: useId,
values: {
department: 1,
class: 1,
location: 1
}
});
}
catch(exp2)
{
log.error({
title: 'error inside loop Reason: ' ,
details: exp2
});
}
}
}
catch(exp)
{
log.error({
title: 'Error in Script Reason: ' ,
details: exp2
});
}
}
return {
execute: myScript
};
});
If you like our solution, comment below, share with your friends and colleague.
Let us know if you find any issue.
Thanks
Netsuite Guru
Download Netsuite Guru Android App
Follow Us on Linkedin
Our FB Page
Hello, I tried the method outlined above and received an error when attempting to submitFields. It looks like the fxreval record type does not support this operation.
ReplyDelete{
"type": "error.SuiteScriptError",
"name": "INVALID_OPERATION",
"message": "That operation is not supported for this record type: fxreval",
"stack":
[
"createError(N/error.js)",
"(adhoc$-1$debugger.user:35)",
"(adhoc$-1$debugger.user:1)",
],
"cause":
{
"type": "internal error",
"code": "INVALID_OPERATION",
"details": "That operation is not supported for this record type: fxreval",
"userEvent": null,
"stackTrace":
[
"createError(N/error.js)",
"(adhoc$-1$debugger.user:35)",
"(adhoc$-1$debugger.user:1)",
],
"notifyOff": false,
},
"id": "",
"notifyOff": false,
"userFacing": false,
}
Try without mentioning record type as we did here
Deletevar useSearch = search.load({
id: 'useSavedSearchIdHere'
});
Hello
ReplyDeleteI try to use your script but its not working to update department. Ican update smemo but anaytical field seems to be not modified
Help me