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

  • Author
    Posts
  • #1039

    starlingMark

    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 This is a cached copy. Click here to see the original post.

  • #1040

    khultquist

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

  • #1041

    starlingMark

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

  • #1042

    khultquist

    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

    erictgrubaugh

    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

    starlingMark

    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

    khultquist

    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

    starlingMark

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

  • #1047

    seamanjeff

    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

    starlingMark

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

You must be logged in to reply to this topic.