I am trying to only display a button on a sales or...
# suitescript
y
I am trying to only display a button on a sales order, when I'm viewing it. When editing, or anything else, I want that to be hidden but for some reason when I hit the "edit" button on the SO I can still see it appearing, even though in the logs isHidden and isDisabled is true in both cases - is there something I am doing wrong down below, that the button isn't hiding when I hit "edit" on the SO?
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @appliedtorecord salesorder
 */
define([], function() {
  function beforeLoad(context) {
    log.debug({
      title: 'Context Type',
      details: context.type
    });

    var button = context.form.addButton({
      id: 'someButtonID',
      label: 'A Button',
      functionName: 'onButtonClick'
    });
    context.form.clientScriptModulePath = 'SuiteScripts/someJsFile.js';
    button.isHidden = context.type != context.UserEventType.VIEW;
    button.isDisabled = context.type != context.UserEventType.VIEW;

    log.debug({
      title: 'Button',
      details: button
    });
  }

  return {
    beforeLoad: beforeLoad
  };
});
e
Try not adding the button in the first place if
context.type != context.UserEventType.VIEW
if(context.type != context.UserEventType.VIEW) return;
👍 1
y
@ehcanadian I have tried this before with no luck as well, but will give it another try. Could it possibly be because var is not block scoping properly?
@ehcanadian yeah unfortunately it still seems to be showing up, even with adding in this right under where I log the context type - it just makes no sense to me 😞
Copy code
if(context.type != context.UserEventType.VIEW) return;
message has been deleted
Funnily enough, when I change the context type to EDIT, it seems to work (not quite how I want it, but for example: It doesn't show when I load the SO It shows when I hit "edit" on the SO) I wonder if when editing the SO, is there a possibility we are still somehow "viewing" it? Though, logging the context doesn't really seem to suggest that
Sorry this is my millionth message haha, I might just try and explicitly say NOT edit, and NOT xyz events, and see if that works instead
No luck 😞
e
Your button id must start with
custpage
and be all lover case as well. Is what you posted the full script?
y
@ehcanadian the code above is the full user event script, I've just gone and changed the names around for this post, but the actual button id starts with "custpage_" as well and is all lower case 🙂
e
How are you updating the file? If it's using sdf maybe you're getting a cache issue. Script looks fine
y
I had a feeling if maybe it was the cache, I'll try to clear it and see if that helps any, or maybe even ask my colleagues to try it on their end. I'm just uploading it through the actual script file in NS, apologies, not sure what SDF is 🙂
@ehcanadian Seems it's working for the others! But when clearing my cache, or even trying in incog it doesn't seem to work, but I think it should be alright. Thanks for that - it was driving me a little crazy why it wouldn't work!
n
FYI avoiding adding the button is better than adding it then hiding / removing it if context is the only consideration.