This topic contains 14 replies, has 0 voices, and was last updated by khultquist 7 years, 4 months ago.
-
AuthorPosts
-
June 23, 2017 at 3:52 am #21548
mark petzoldHi there. I'm trying to set up a scheduled script and I'm getting an error that reads "SSS_MISSING_REQD_ARGUMENT" when it runs.
I am not a script wizard like so many of you are. I took this from an existing script that does work and tried (and failed) to re-purpose it. Can any of you geniuses see what I'm doing wrong at a glance? I really appreciate the help.
Code:
function scheduledScript()
{var searchid = '2921';
var searchresults = nlapiSearchRecord('transaction', searchid);
for ( var i = 0; searchresults != null && i < searchresults.length; i++ )
{
var result = searchresults[i];
var customerid = result.getValue('id',null, 'group');
var amount = result.getValue('amount',null,'sum' );{
nlapiSubmitField('customer', customerid, 'custentity_2017_soup', amount );
}}
}
This is a cached copy. Click here to see the original post. -
June 23, 2017 at 5:44 am #21549
Olivier Gagnon NCAt a glance, I would say try switching to:
var customerid = result.getValue('internalid',null, 'group');
The 'id' field is not the same as Internal ID and your submit will fail because of that.
-
June 23, 2017 at 8:29 am #21550
erictgrubaughI second Olivier Gagnon NC 's suggestion as the only thing that jumps out at me. Do you have more information about the actual Error and which line it's occurring on?
-
June 23, 2017 at 9:32 am #21551
david.smithThat error usually occurs when you're using a variable that has no data. My guess is that your customerid is null or empty. This would be where the error is coming from. But if I'm correct, so are Olivier and Eric.
-
June 23, 2017 at 3:04 pm #21552
mark petzoldThanks everyone! I'll make some changes, test, and report back.
-
June 23, 2017 at 3:19 pm #21553
mark petzoldOriginally posted by erictgrubaugh
View Post
I second Olivier Gagnon NC 's suggestion as the only thing that jumps out at me. Do you have more information about the actual Error and which line it's occurring on?
I need to learn more about debugging scripts. Right now I'm making edits, uploading to our sandbox, rescheduling and then waiting for the next 30 minute trigger. It's making the process pretty tedious. Far more tedious than it needs to be I imagine.
-
June 23, 2017 at 4:22 pm #21554
khultquistTo speed up testing in a scheduled script, create a new deployment of that script, making sure the keep the status as Not Deployed. Save it. Then edit it, and click Save and Deploy. It will be immediately added to the queue of scripts, no longer a need to wait for the scheduled time.
-
June 23, 2017 at 4:38 pm #21555
mark petzoldI've make the suggested changes, editing the script and the saved search and I'm still getting the same error. Under details, the log reads "id" but I no longer have anything referencing "id" in the script. Thoughts?
-
June 24, 2017 at 3:52 pm #21556
khultquistCan you post your full script? If not, add some nlapiLogExecution(type, title, details) lines to find where the script is encountering errors.
-
June 25, 2017 at 3:11 am #21557
mark petzoldThis is the full script. I thought it was pretty simple
The script is supposed to run a transaction saved search which returns amount spent for specific items. There is a currency field on the customer record for the item that should get updated by the script. I added some lines for debugging at the end. Did I get that right at least?
This is the line on the saved search that returns the amount.
Code:
function scheduledScript()
{var searchid = '2921';
var searchresults = nlapiSearchRecord('transaction', searchid);
for ( var i = 0; searchresults != null && i < searchresults.length; i++ )
{
var result = searchresults[i];
var customerid = result.getValue('internalid','customer', 'group');
var amount = result.getValue('2017soupamount',null,'sum' );{
nlapiSubmitField('customer', customerid, 'custentity_2017_Soup', amount );
}var title = 'Succesfully update customer ' + customerid ;
var details = 'Amount updated = ' + amount;nlapiLogExecution('DEBUG', title, details);
}
} -
June 25, 2017 at 7:46 am #21558
erictgrubaughI would expect you would retrieve the value of `amount` by:
Code:
var amount = result.getValue("formulacurrency", null, "sum");
Provided that is the only formulacurrency in the Results.Also, you should be able to get the `customerid` directly from the `entity` field on the transaction, without the need to join to `customer`:
Code:
var customerid = result.getValue("entity", null, "group");
But I would need to see the Saved Search definition to confirm both of those. -
June 25, 2017 at 2:02 pm #21559
mark petzoldThere are multiple amount fields. Ideally I'd like to use the same script to update multiple amounts. If that's impossible I'll look for other options.
-
June 25, 2017 at 3:04 pm #21560
khultquistTry this code, and then you should be able to see if there are any variables that aren't getting the proper value, and you'll narrow down exactly which line is throwing the error
Code:
function scheduledScript() {
var searchid = '2921',
searchresults = nlapiSearchRecord('transaction', searchid);
if (searchresults !== null) {
debug('searchresults.length', searchresults.length);
for (var i = 0; i < searchresults.length; i++) {
debug('i', i);
var result = searchresults[i],
customerid = result.getValue('internalid', 'customer', 'group');
debug('customerid', customerid);
var amount = result.getValue('2017soupamount', null, 'sum');
debug('amount', amount);nlapiSubmitField('customer', customerid, 'custentity_2017_Soup', amount);
var title = 'Succesfully update customer ' + customerid,
details = 'Amount updated = ' + amount;
debug(title, details);
}
} else debug('no results', 'no results');
}function debug(a, b) {
nlapiLogExecution('DEBUG', a, b);
} -
June 26, 2017 at 12:24 am #21561
mark petzoldHere's what I've learned.
There doesn't seem to be a way to use multiple lines of the same type on a saved search to update multiple fields. That's a shame. I'll need to create a dozen saved searches and scheduled scripts instead of just one. I'd love it if someone could prove me wrong.
I also learned that field names are case sensitive (slaps forehead).
So, I went back to my search and made it very simple, with only one summed amount, removing the need for a formula. The script works perfectly now with the only consequence being that I have to do this 12 more times.
I really appreciate all the help. I'm overcoming ignorance, one problem at a time.
-
June 26, 2017 at 7:35 am #21562
khultquistGlad you figured this out. Adding in a bunch of debug lines will often help find the needle in the haystack!
As for scaling the script, there are ways to accomplish what you are trying to do. You could create 12 searches but use only a single script, by having the script id's, fieldnames, etc in arrays, then loop the script through each search. Alternately, you could have a single search and single script, by making use of nlobjSearchResult method getAllColumns(), and then loading, modifying, and submitting the full customer record.
-
AuthorPosts
You must be logged in to reply to this topic.