This topic contains 8 replies, has 0 voices, and was last updated by bradsimpson 7 years, 2 months ago.

  • Author
    Posts
  • #21535

    bradsimpson

    I'm deploying a script that will stop a user from saving a new opportunity without a primary sales rep identified. It seems simple enough but I am getting an error I'm not familiar with.

    Script/Deployment Details:

    Type: Client

    Name: cs_SalesRepCheck

    Save Record Function: clientSaveRecord

    Deployed: True

    Status: Testing

    Event Type: Create

    Script Code:

    Code:
    function clientSaveRecord(){
    var salesrep = nlapiGetFieldValue(salesrep);
    if (!(salesrep)){
    alert("No Primary Sales Rep Identified. Please choose a primary sales rep before saving.");
    return false;
    } else {
    return true;
    }
    }
    The error being returned on save is:

    An unexpected error occurred in a script running on this page.

    clientSaveRecord(saveRecord)

    customscript_opp_cs_salesrepcheck

    JS_EXCEPTION

    TypeError Cannot read property 'toLowerCase' of undefined.
    This is a cached copy. Click here to see the original post.

  • #21536

    david.smith

    You're missing your quotes around the salesrep field in nlapiGetFieldValue("salesrep")

  • #21537

    bradsimpson

    Thank you david.smith , that was what I was missing. It uncovered a larger issue in my design in that if I deploy that script to the Opportunity Record, clientSaveRecord function, it always runs because before the save, the sales rep field will always be blank. I don't think I'll be able to accomplish what I'm trying to with such a simple script.

  • #21538

    k_dunc

    Where do you want to source the Primary Sales Rep from – i.e., is it the user creating / saving the Opportunity record? Or do you perhaps use Sales Territories etc.?

  • #21539

    bradsimpson

    k_dunc The primary sales rep is stored on the Sales Team sublist of the opportunity. Ideally, that list is pulled from the Customer record that the opportunity is tied to, which works 90% of the time.

    What I'm trying to script for is the other 10%. When someone forgets to mark the primary sales rep, either on the customer record or during creation of the opportunity, I want to pop an alert that will stop that person from saving the Opportinity. We have other processes relying on that primary sales rep that break if it's not set properly.

  • #21540

    k_dunc

    Thanks bradsimpson, but what then is your issue? Upon the user saving the Opportunity record, your code checks to see if the 'salesrep' field is empty. If so, it displays your pop-up message and does not allow the user to save the record. If there is something in the 'salesrep' field, then it allows the user to save the record.

    Is this not precisely what you're after?

  • #21541

    bradsimpson

    k_dunc Coming back around to this. The problem seems to be that script is still allowing the opportunity to be saved. Then when I go to edit the opportunity record, another script does a check for a sales rep, error's out with an "id" error and I'm stopped from setting a primary sales rep. I have to turn off the deployment of the script causing the "ID" error just to edit my record.

  • #21542

    k_dunc

    Just checking, 2 things:

    Originally posted by bradsimpson

    View Post

    var salesrep = nlapiGetFieldValue(salesrep);

    You are using quotes around 'salesrep' right?
    Given that the script's Status = Testing, you are the script owner and the one doing the testing right?

    If the quotes around 'salesrep' doesn't fix your script, maybe do an 'alert' call to show what value is in the salesrep field before you save it.

    Cheers,

    Kirk.

  • #21543

    bradsimpson

    Yes I did add the quotes around sales rep. Yes I am the script owner and testing the creation of and saving of the opportunity.

You must be logged in to reply to this topic.