This topic contains 6 replies, has 3 voices, and was last updated by Adolfo Garza 5 years, 11 months ago.

  • Author
    Posts
  • #5950

    abarylak

    Looking for ideas on how to inject or run client side javascript on the View of a record. Currently NS Client Scripts only run on Edit, Create, Copy screens, and not on the View screen. However, there is something we would like to change on the page to be displayed a little differently, but we don’t want to re-write the entire record page into a suitelet. We would like to change the names or remove some of the sublist (child record) buttons to represent a better user experience. I’m able to write a simple javascript which will change the name of the button or remove it, but I’m not able to get the script to actually inject into the View page. I’ve been testing this with a simple alert message just to prove that the javascript is running, but have not been able to get it to work.

    Has anyone been successful at injecting some javascript onto the view page of a record? Please let me know. Thanks.
    This is a cached copy. Click here to see the original post.

  • #5951

    abarylak

    I think i just figured out my issue although it’s not really the nicest and cleanest way of doing this.

    I created a new “Inline HTML” field on the custom record in question.

    Set the Default Value to the Javascript i wanted wrapped in [js][/js]
    Hopefully this can help someone else with this issue.

    If someone else has a cleaner way to accomplish this, i'm open to suggestions and moving my code somewhere else. Let me know. Thanks.

    Adam

  • #5952

    michoel

    The way to do this is to create a User Event script that runs before load sets the client side script using form.setScript()

    Code:
    function beforeLoad(type, form) {
    if (type == ‘view’ && nlapiGetContext().getExecutionContext() == ‘userinterface’) {
    form.setScript(‘customscript_clientscript’); // show warning on form
    }
    }
    The client script needs to have a Script record, but not a Script Deployment Record.

  • #5953

    michoel

    Originally posted by abarylak

    View Post

    Here is the javascript which i use to attach javascript functions to the DOM in order for them to execute when the section of the page i need is updated and therefore forces my change to not get lost or overwritten. My code simply changes the label of the “New” button to something easier for the user to understand.

    Keep in mind that it is not supported or recommended to ever manipulate the DOM in Netsuite, and doing things like this can break on future updates.

  • #5954

    abarylak

    I thought that doing form.setScript was the same as adding a script directly to my form using the UI which i had tried previously and my script never ran. Apparently it is different when you use the before load and form.setScript. Using that did run my javascript the way i was expecting. Regarding attaching a function to the DOM: I completely understand that this may not work for future versions of NetSuite, and that is a risk we would have to take. Since NetSuite doesn’t give us a better way of making these modifications for more advanced data models, I must work within the confines of their platform. Therefore, it is either a little javascript to change the label or remove the button completely, or we need to write a full customized Suitelet UI for about 20 different records and how they relate to eachother. However, with our timeline, we must use most of the built in functionality in NS.

    Thanks for the tip about form.setScript. Seems like it is another inconsistency within the platform and my bad for assuming that it functioned the same as adding a script via the form edit UI. We will probably be going with this route since it would keep all our scripts in the file cabinet and easier to manage in the long run. Thanks again.

    Adam

  • #26081

    Bebeto
    Member
    @karl_lester_martinez

    Hi @michoel,

    what do you mean about this “<span style=”background-color: #fbfbfb; color: #606060; font-family: Montserrat; font-size: 12px;”>The client script needs to have a Script record, but not a Script Deployment Record.</span>”., i tried to apply your code but i failed to do it clearly. can you help me? thanks

You must be logged in to reply to this topic.