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

  • Author
    Posts
  • #21548 Score: 0

    mark petzold
    • Contributions: 0
    • Level 1

    Hi 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.

  • #21549 Score: 0

    Olivier Gagnon NC
    • Contributions: 0
    • Level 1

    At 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.

  • #21550 Score: 0

    erictgrubaugh
    • Contributions: 0
    • Level 1

    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?

  • #21551 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    That 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.

  • #21552 Score: 0

    mark petzold
    • Contributions: 0
    • Level 1

    Thanks everyone! I'll make some changes, test, and report back.

  • #21553 Score: 0

    mark petzold
    • Contributions: 0
    • Level 1

    Originally 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.

  • #21554 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    To 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.

  • #21555 Score: 0

    mark petzold
    • Contributions: 0
    • Level 1

    I'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?

  • #21556 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    Can you post your full script? If not, add some nlapiLogExecution(type, title, details) lines to find where the script is encountering errors.

  • #21557 Score: 0

    mark petzold
    • Contributions: 0
    • Level 1

    This 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);

    }
    }

  • #21558 Score: 0

    erictgrubaugh
    • Contributions: 0
    • Level 1

    I 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.

  • #21559 Score: 0

    mark petzold
    • Contributions: 0
    • Level 1

    There 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.

  • #21560 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    Try 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);
    }

  • #21561 Score: 0

    mark petzold
    • Contributions: 0
    • Level 1

    Here'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.

  • #21562 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    Glad 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.

You must be logged in to reply to this topic.