This topic contains 3 replies, has 0 voices, and was last updated by david.smith 8 years, 3 months ago.

  • Author
    Posts
  • #6237

    eschultz0

    I am in the process of writing a script to return a customers last transaction. As part of the Transaction there are two child records being included, ‘item’ and a custom record ‘custrecord1’ which is joined by field ‘custbody2’.

    as part of the columns required in the return I need the interalid for both ‘item’ and ‘custrecord1’. However which ever records field ‘internalid’ is added last, that is the once that is returned.

    Here are two code samples and data returned. Key Fields are Bolden

    Sample A:

    Code:
    var columns = new Array(
    new nlobjSearchColumn(“tranid”,null),
    new nlobjSearchColumn(“trandate”,null, null),
    new nlobjSearchColumn(“custbody7”),
    new nlobjSearchColumn(“memo”),

    // Fields for custrecord1
    new nlobjSearchColumn(“internalid”,”custbody2″, null),
    new nlobjSearchColumn(“name”,”custbody2″, null),
    new nlobjSearchColumn(“custrecord27″,”custbody2”, null),

    // Item Fields
    new nlobjSearchColumn(“itemid”,”item”, null),
    new nlobjSearchColumn(“internalid”, “item”, null),
    new nlobjSearchColumn(“class”,”item”),
    new nlobjSearchColumn(“custitem_itemtype”,”item”)
    );
    Data Sample Return: {“id”:”390814″,”recordtype”:”salesorder”,”colum ns” :{“tranid”:”23182″,”trandate”:”5/19/2015″,”custbody7″:{“name”:”Summer 2015″,”internalid”:”16″},”internalid”:{“name”:”803″,”internalid”:”803″},”name”:”Abigail”,”custrecord27″:”Schultz”,”ite mid “:”Extended Care Ranch PM Week 10″,”class”:{“name”:”Ranch”,”internalid”:”46″}}}

    Sample B:

    Code:
    var columns = new Array(
    new nlobjSearchColumn(“tranid”,null),
    new nlobjSearchColumn(“trandate”,null, null),
    new nlobjSearchColumn(“custbody7”),
    new nlobjSearchColumn(“memo”),

    // Item Fields
    new nlobjSearchColumn(“internalid”, “item”, null),
    new nlobjSearchColumn(“class”,”item”),
    new nlobjSearchColumn(“custitem_itemtype”,”item”),

    // Fields for custrecord1
    new nlobjSearchColumn(“internalid”,”custbody2″, null),
    new nlobjSearchColumn(“name”,”custbody2″, null),
    new nlobjSearchColumn(“custrecord27″,”custbody2”, null),
    new nlobjSearchColumn(“itemid”,”item”, null)
    );
    Data Sample Return: {“id”:”390814″,”recordtype”:”salesorder”,”colum ns” :{“tranid”:”23182″,”trandate”:”5/19/2015″,”custbody7″:{“name”:”Summer 2015″,”internalid”:”16″},”itemid”:”Extended Care Ranch PM Week 10″,”internalid”:{“name”:”14188″,”internalid”:”141 88″},”class”:{“name”:”Ranch”,”internalid”:”46″},”na me” :”Abigail”,”custrecord27″:”Schultz”}}

    Any input on how to get the internalId for both item and custrecord1 is appreciated.
    This is a cached copy. Click here to see the original post.

  • #6238

    khultquist

    The syntax for column search is

    nlobjSearchColumn(name, join, summary)

    so I think your code should be

    Code:
    var columns = new Array(
    new nlobjSearchColumn(“tranid”,null),
    new nlobjSearchColumn(“trandate”,null, null),
    new nlobjSearchColumn(“custbody7”),
    new nlobjSearchColumn(“memo”),

    // Fields for custrecord1
    new nlobjSearchColumn(“internalid”,”custrecord1″, null),
    new nlobjSearchColumn(“name”,”custrecord1″, null),
    new nlobjSearchColumn(“custrecord27″,”custrecord1”, null),

    // Item Fields
    new nlobjSearchColumn(“itemid”,null ,null),
    new nlobjSearchColumn(“internalid”,null ,null),
    new nlobjSearchColumn(“class”,null, null),
    new nlobjSearchColumn(“custitem_itemtype”,null, null)
    );

  • #6239

    MChammaTX

    How are you getting the data? Are you simply converting the result to a JSON or are you getting the values from the search result using SuiteScript API? If you are simply converting the result to a JSON that might be your problem. Instead get the values and set in your own json using the API to get values from a search result. An example:

    Code:
    var data = {};

    if(searchRes)
    {
    for(var i=0;i<searchRes.length;i++)
    {
    data["iteminternalid"] = searchRes[i].getValue("internalid","item");
    data["custominternalid"] = searchRes[i].getValue("internalid","custbody2");
    }
    }


    eschultz0 replied on 08/11/2016, 10:43 AM: Thats the winner!

    I was converting the result row to a json object, in which case would overwrite the previous internal id.

    when using getValue as you suggested, I can get each internal id correctly.

    So now instead of taking a short cut to just return search results as json, i now need to build my own json object.

  • #6240

    david.smith

    MChammaTX is correct.

You must be logged in to reply to this topic.