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

  • Author
    Posts
  • #21620 Score: 0

    grygmpl
    • Contributions: 0
    • Level 1

    Hi,

    I'm a newbie on scripting and I would like to create a script that will populate the Location on the line items of a PO based on the Location on the main form.

    Any help is highly appreciated.

    Thanks,

    Gary
    This is a cached copy. Click here to see the original post.

  • #21621 Score: 0

    k_dunc
    • Contributions: 0
    • Level 1

    This certainly sounds achievable. So you'd want to probably write a Client Script for that purpose. Here's a link to SuiteAnswers.

    So what you could do, is use a Validate Line function that, upon the user 'adding' a new PO row, you simply populate the Location column with the value of what's in the Location body field. Once you get that working, you could potentially even hide the Location column so the user doesn't even have to interact with it.

  • #21622 Score: 0

    Vesku1980
    • Contributions: 0
    • Level 1

    Hi,

    I made this kind on functionality with postsourcing function in client script.

    function postSourcing(type, name){

    if(type === 'item' && name === 'item'){

    var loc = nlapiGetFieldValue('location'); // GET Location from main page

    nlapiSetCurrentLineItemValue('item', 'location', loc);

    }

    }

    This script is executed when item is added to line.

    Vesku

  • #21623 Score: 0

    grygmpl
    • Contributions: 0
    • Level 1

    Hi k_dunc and Vesku,

    Thank you for your responses Appreciate it a lot. Script is working like a charm.

    -Gary


    k_dunc replied on 04/27/2017, 09:50 PM: Great to hear.

  • #21624 Score: 0

    grygmpl
    • Contributions: 0
    • Level 1

    Hello again,

    I also wanted to apply this under the Expenses column ? Is this possible ?

    Thanks,

    Gary

  • #21625 Score: 0

    k_dunc
    • Contributions: 0
    • Level 1

    Hi Gary,

    That too should be achievable. Instead of linking to the 'item' sublist, you'd need to link to the 'expense' sublist. Something like this:

    Code:
    nlapiSetCurrentLineItemValue('expense', 'location', loc);
    Note, the first parameter in the Set Current Line Item Value API is the sublist to link to. May I also suggest that if you're going to be doing this sort of thing, you should bookmark the NetSuite Records Browser. In the Records Browser, you can then see all the fields and field IDs for each record type.

  • #21626 Score: 0

    grygmpl
    • Contributions: 0
    • Level 1

    Thanks again k_dunc. I'm actually trying to populate the Department this time.

    I've tried this one but doesn't work. Not sure what I am missing.

    function PopulateDept(type, name) {

    if(type === 'expense' && name === 'expense')

    { var deptmain = nlapiGetFieldValue('department');

    nlapiSetCurrentLineItemValue('expense', 'department', deptmain);

    }

    }

  • #21627 Score: 0

    k_dunc
    • Contributions: 0
    • Level 1

    I would guess because there is no "expense" field on a PO. The 'name' argument is the name (Internal ID) of the field that you're testing to see if it has changed. You'd need to change that second part of your 'if' to something like:

    Code:
    if(type === 'expense' && name === 'amount')
    So this means, that once the 'amount' field changes in the Expenses sublist, then it should set your department column. You could change the 'amount' to almost any other column field you wish to use instead (so long as it's part of the Expenses sublist).

  • #21628 Score: 0

    grygmpl
    • Contributions: 0
    • Level 1

    I actually tried to use other fields i.e. account. It's strange that when I am testing it the first time, it's not working.

    But now suddenly, the script is working.

    Not sure what happened but anyway, thanks again for your kind help. Appreciate it a lot. =)

You must be logged in to reply to this topic.