Update Last Modified and By fields on Custom Record when a Note is Saved using a Script

Written by
Manuelito Macalinao
Published on
August 31, 2023 at 9:19:03 AM PDT August 31, 2023 at 9:19:03 AM PDTst, August 31, 2023 at 9:19:03 AM PDT

Scenario

On a Custom Record, when a Note is created and saved on the Notes tab, User Notes subtab, the Last Modified Date and By fields do not get updated.

Solution

AScriptmay be used to update theLast ModifiedandByfields to the Date, Time, and User that theNoteon aCustom Recordwas submitted on and by.

TheTypeofScriptthat may be used isUser Eventutilizing theAfter Record Submit Functiondeployed on theNoterecord.

ACustom Field(possibly ofHidden Display Type) can be set up on theCustom Record. This field will be updated on the record when theNoteis submitted and will result in theLast ModifiedandByfields also being updated.

  1. CreateCustom Field
    • Navigate toCustomization>Lists, Records, & Fields>Record Types
    • In theEditcolumn, click on the Name of theCustom Record Type
    • Notice values for the below fields:
      • ID
        Example:customrecord_test
      • Internal ID
        Example:123
    • On theFieldssubtab, clickNew Field. Once a New Custom field page opens up, enter the following details:
      • Label:EnterLabel
        Example:Note Saved
      • ID:_noteupdated
      • Type:Check Box
      • Store Value:EnterCheckmark
      • Displaytab:
        • Display Type:Hidden
      • Click Save

    1. CreateUser Event Script
      • Navigate toCustomization>Scripting>Scripts>New
      • ClickPlus-signbutton
        • Attach From:Computer
        • Folder:EnterFolder
          Example:SuiteScripts
        • Select File:ClickChoose File
      • Select JavaScript file saved on your Computer with below sample code (with relevant field IDs)
        Example JavaScript filename:updateLastModified_afterSubmit_UE.js
      • ClickSave
      • ClickCreate Script Record
      • ClickUser Event
      • Name: EnterName
      • Example:Update Last Modified after Note Saved
      • Scriptstab:
        • After Submit Function:updateLastModified_afterSubmit
      • Deploymentstab:
        • Applies To:Note
        • Deployed:EnterCheckmark
        • Status:Testing/Released
      • ClickAddon the line
      • ClickSaveon the Script

      Example JavaScript fileupdateLastModified_afterSubmit_UE.js:

      /**Check the Record Type on which the Note was saved, load the specific instance of that Custom Record, update the Hidden Custom Field, and submit the Custom Record. This results in the Last Modified and By fields on the instance of the Custom Record being updated according to when and by which User the Note was submitted (after the Custom Record is refreshed). **/functionupdateLastModified_afterSubmit(type){var recTypeNoteisAttachedto =nlapiGetFieldValue('recordtype');if(recTypeNoteisAttachedto =='123'){//where '123' is the Internal ID of the Custom Recordvar recIDNoteisAttachedto =nlapiGetFieldValue('record');var recNoteisAttachedto =nlapiLoadRecord('customrecord_test', recIDNoteisAttachedto);//where 'mycustomrecord' is the ID of the Custom Record recNoteisAttachedto.setFieldValue('custrecord_noteupdated','T');//where 'custrecord_noteupdated' is the ID of the Custom FieldnlapiSubmitRecord(recNoteisAttachedto);}}