This topic contains 9 replies, has 0 voices, and was last updated by starlingMark 7 years ago.

  • Author
    Posts
  • #1039 Score: 0

    starlingMark
    • Contributions: 0
    • Level 1

    I am trying to change the components on a Work Order via script. When I run the following code through the console, it works as expected:

    Code:
    var workOrder = record.load({ type: record.Type.WORK_ORDER, id: 213, isDynamic: true });

    while (workOrder.getLineCount({ sublistId: ‘item’ }) > 0) {
    workOrder.removeLine({ sublistId: ‘item’, line: 0 });
    }

    var allComponents = [];
    allComponents.push({ item: 51, quantity: 800 });
    allComponents.push({ item: 65, quantity: 200 });

    for (var j = 0; j < allComponents.length; j++) { workOrder.selectLine({ sublistId: 'item', line: j }); workOrder.setCurrentSublistValue({ sublistId: 'item', fieldId: 'item', value: allComponents[j].item }); workOrder.setCurrentSublistValue({ sublistId: 'item', fieldId: 'quantity', value: allComponents[j].quantity }); workOrder.commitLine({ sublistId: 'item' }); } workOrder.save(); However, when I run the exact same code block (copied and pasted) in a Suitelet, I get "An unexpected SuiteScript error has occurred". It points me to the line where I am setting the item. I have tried loading the record in standard mode and using the "setSublistValue" methods, but no dice. Same error on the same line. Any thoughts?
    This is a cached copy. Click here to see the original post.

  • #1040 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    I would try using workOrder.setLineItemValue(group, name, linenum, value) instead of workOrder.setCurrentSublistValue()

  • #1041 Score: 0

    starlingMark
    • Contributions: 0
    • Level 1

    I believe that is a SS 1.0 call – not a 2.0 call.

  • #1042 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    Right, sorry about that. That should say workOrder.setSublistValue(), but in re-reading your post you already tried that. Selecting lineitems/sublists server side has caused my scripts to crash, but that’s not the problem you’re having.

    Here’s another thought, is kind of a long shot… try removing the extra sublist lines at the end of your script. It shouldn’t matter until the line is committed, but since this sublist is required to have at least one line it might be causing a server side problem.

    Edited to add: in your original script you probably need to use workOrder.selectNewLine() instead of workOrder.selectLine()

    Code:
    var workOrder = record.load({ type: record.Type.WORK_ORDER, id: 213, isDynamic: true });

    var allComponents = [];
    allComponents.push({ item: 51, quantity: 800 });
    allComponents.push({ item: 65, quantity: 200 });

    for (var j = 0; j 1) {
    workOrder.removeLine({ sublistId: ‘item’, line: 2 });
    }

    workOrder.save();

  • #1043 Score: 0

    erictgrubaugh
    • Contributions: 0
    • Level 1

    I have noticed 2.0 being very finnicky about Strings v Numbers with internal IDs. Perhaps try making your item properties Strings instead.

    Everything else looks correct with your code.

  • #1044 Score: 0

    starlingMark
    • Contributions: 0
    • Level 1

    Thanks for the suggestions all. I just tried breaking out the “remove extra line items” to right before I save the record. Unexpected error.

    Eric – Thanks for your thoughts as well. I tried .toString(), all of the format.format and format.parse variations I could think of. Unexpected error.

    For the time being I have written a second suitelet in SS 1.0 that is called from this one. It works perfectly – but is not really the desired methodology.

  • #1045 Score: 0

    khultquist
    • Contributions: 0
    • Level 1

    Did you try workOrder.selectNewLine() instead of workOrder.selectLine() — I edited my last post, not sure if you saw it. Since line 0 doesn’t exist, you may not be able to select it.

  • #1046 Score: 0

    starlingMark
    • Contributions: 0
    • Level 1

    That, too, returns “Unexpected Error”. But, since this is SS 2.0, line 0 does exist.

  • #1047 Score: 0

    seamanjeff
    • Contributions: 0
    • Level 1

    There’s a defect on this that is supposed to be fixed in 2017.1. It’s Defect 423850. I had SS1 code that worked but in SS2 it gave me problems.

  • #1048 Score: 0

    starlingMark
    • Contributions: 0
    • Level 1

    Thanks for this Jeff – I thought it was just me!

You must be logged in to reply to this topic.