This topic contains 8 replies, has 0 voices, and was last updated by bradsimpson 7 years, 2 months ago.
-
AuthorPosts
-
July 5, 2017 at 10:24 am #21535
bradsimpsonI'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. -
July 5, 2017 at 10:47 am #21536
david.smithYou're missing your quotes around the salesrep field in nlapiGetFieldValue("salesrep")
-
July 31, 2017 at 11:36 am #21537
bradsimpsonThank 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.
-
July 31, 2017 at 2:58 pm #21538
k_duncWhere 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.?
-
July 31, 2017 at 3:17 pm #21539
bradsimpsonk_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.
-
July 31, 2017 at 4:29 pm #21540
k_duncThanks 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?
-
August 28, 2017 at 8:50 am #21541
bradsimpsonk_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.
-
August 28, 2017 at 3:02 pm #21542
k_duncJust 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.
-
September 1, 2017 at 10:21 am #21543
bradsimpsonYes I did add the quotes around sales rep. Yes I am the script owner and testing the creation of and saving of the opportunity.
-
AuthorPosts
You must be logged in to reply to this topic.