This topic contains 2 replies, has 0 voices, and was last updated by rob@harkness 7 years, 3 months ago.

  • Author
    Posts
  • #21514

    rob@harkness

    The below updates all line item descriptions from the body memo field using a client script with a 'field changed function' and is deployed on the sales order. I would like to change this to trigger on save instead. I have tried to change to 'save record function' but it doesnt work. I have also tried to change the script type to an event script with no joy.

    Code:
    function description(type,name){
    if (name == 'memo'){
    var description = nlapiGetFieldValue('memo');
    var count = nlapiGetLineItemCount('item');
    if (count > 0){
    for (var x = 1; x <= count; x++){
    nlapiSelectLineItem('item', x);
    nlapiSetCurrentLineItemValue('item', 'description', memo.value, false, true);
    nlapiCommitLineItem('item');
    }
    }
    }
    }
    Any help appreciated
    This is a cached copy. Click here to see the original post.

  • #21515

    jejacob

    This works on my end:

    Code:
    var memoInit;
    var memoSave;

    function clientPageInit(type){
    if(type == 'edit'){
    memoInit = nlapiGetFieldValue('memo');
    }
    }

    function clientSaveRecord(){
    memoSave = nlapiGetFieldValue('memo');
    if(memoInit !== memoSave){
    var itemsListCount = nlapiGetLineItemCount('item');
    for (var x = 1; x <= itemsListCount ; x++ ){
    nlapiSetLineItemValue('item', 'description', 1, memoSave);
    }
    }
    return true;
    }

  • #21516

    rob@harkness

    This is great thanks Jejacob. Behaviour works to update the line item 'memo' on save. However this only seems to be working for the first line. I cant seem to get this to work for multiple lines on creation or edit


    erictgrubaugh replied on 08/21/2017, 07:51 AM: I’m assuming you copied this line exactly then:

    nlapiSetLineItemValue(‘item’, ‘description’, 1, memoSave);

    You can see it is always setting the first line. Change the index parameter of nlapiSetLineItemValue to match your loop iterator variable x, and it will set the value for all lines.

You must be logged in to reply to this topic.