This topic contains 4 replies, has 0 voices, and was last updated by pcutler 6 years, 11 months ago.

  • Author
    Posts
  • #21401 Score: 0

    mushrush
    • Contributions: 0
    • Level 1

    I need a piece of script to fire off when a Role change is made to a contact record. Is it possible to detect this role change? I cannot get the User Event script or the Client script to fire off when a user updates the primary contact or changes the role at all. Does anyone have any ideas or suggestions? Right now I am having the user change the name, save, then change the name back, then save again to get the script to trigger after they make the role change.

    Thanks!
    This is a cached copy. Click here to see the original post.

  • #21402 Score: 0

    pcutler
    • Contributions: 0
    • Level 1

    I haven't tested this, but assuming you're right and no user event scripts fire when the contact role is changed how about this:

    A user event script that hides the "Update Primary" button on the contacts sublist and creates a new custom "Update Primary" button.

    A client script that opens a suitelet popup when clicking the custom "Update Primary" button.

    A suitelet that replicates the behavior of the native functionality and triggers your custom logic.

    Ordinarily I'd recommend against replicating native NetSuite functionality, but the update primary screen is so trivial that this seems like a reasonable work-around.

  • #21403 Score: 0

    mushrush
    • Contributions: 0
    • Level 1

    pcutler thank you for your response and idea. I am not sure it will work as I do not believe we have access to edit the contact role field on the sublist of the customer record. Nor do we have access to the role field from the contact record. Not sure how to go about creating a workaround.

    All I need to do is have the ability to detect the change and fire off my already created script….

  • #21404 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    You might have to use a scheduled script and suffer the 15 minute lag.

  • #21405 Score: 0

    pcutler
    • Contributions: 0
    • Level 1

    mushrush Your request is simple, but unfortunately NetSuite doesn't run any triggers in that context, so the solution is more complicated.

    Here's my suggestion in code, deployed as a user event script on the customer record. khultquist has a good suggestion too if you're ok with waiting for a scheduled script to run.

    Code:
    function beforeCustomerLoad(type, form, request)
    {
    if(form)
    {
    // get the contact sublist
    var sublist = form.getSubList('contact');
    if(sublist)
    {
    // get the update contact button
    var btn = sublist.getButton('updatecontact');
    if(btn)
    {
    // hide the update contact button
    btn.setVisible(false);

    // add our own custom button instead
    var customBtn = sublist.addButton('custpage_update_contact_role', 'Update Contact Role', '(' + myClientScript.toString().replace(/"/g, "'") + ')()');
    }
    }
    }

    function myClientScript()
    {
    // update the contact role in a way that you can do a better job keeping track of
    alert('hello world');
    }
    }

You must be logged in to reply to this topic.