This topic contains 4 replies, has 0 voices, and was last updated by abarylak 7 years, 9 months ago.
-
AuthorPosts
-
February 15, 2017 at 2:49 pm #21852
abarylakLooking 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. -
February 15, 2017 at 3:21 pm #21853
abarylakI 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
-
February 15, 2017 at 3:28 pm #21854
michoelThe 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. -
February 15, 2017 at 4:18 pm #21855
michoelOriginally 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.
-
February 16, 2017 at 7:13 am #21856
abarylakI 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
-
AuthorPosts
You must be logged in to reply to this topic.