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

  • Author
    Posts
  • #5950 Score: 0

    abarylak
    • Contributions: 0
    • Level 1

    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 Score: 0

    abarylak
    • Contributions: 0
    • Level 1

    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

    <script>
    tags.

    Unchecked the “Formula” checkbox

    Hit Save

    Now, my javascript does run on view and does perform the changes i need.

    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.

    Code:

    <!-- <a href='http://www.google.com'>Google Link</a> -->
    <script>
    var attachedEvent = false;
    //alert('Javascript Loading');
    function masterFormChange(){
    removeItemVersionButton();
    var myElement = document.getElementById('recmachcustrecord_irel_version_layer');
    if(attachedEvent == false && myElement != null && window.addEventListener){
    //Normal Browsers
    myElement.addEventListener('DOMSubtreeModified', removeItemVersionButton, false);
    attachedEvent = true;
    }else if(attachedEvent == false && myElement != null && window.attachEvent){
    //IE
    myElement.attachEvent('DOMSubtreeModified', removeItemVersionButton);
    attachedEvent = true;        
    }
    }
    function removeItemVersionButton(){
    var myFirstElement = document.getElementById('newrecrecmachcustrecord_irel_version');
    if(myFirstElement != null)
    myFirstElement.setAttribute('value', 'Add Item to this Version');
    }
    masterFormChange();
    var myElement = document.getElementById('pageContainer');
    if(myElement != null && window.addEventListener){
    // Normal Browsers
    myElement.addEventListener('DOMSubtreeModified', masterFormChange, false);
    } else
    if(myElement != null && window.attachEvent){
    // IE
    myElement.attachEvent('DOMSubtreeModified', masterFormChange);
    }
    </script>

    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 Score: 0

    michoel
    • Contributions: 0
    • Level 1

    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 Score: 0

    michoel
    • Contributions: 0
    • Level 1

    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 Score: 0

    abarylak
    • Contributions: 0
    • Level 1

    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 Score: 0

    Bebeto
    Member
    • Contributions: 1
    • Level 1
    @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.