This topic contains 5 replies, has 0 voices, and was last updated by chanarbon 7 years, 5 months ago.

  • Author
    Posts
  • #1444

    seamanjeff

    Anyone have some sample code to create the simplest possible search of a custom record, and run it ad hoc?
    This is a cached copy. Click here to see the original post.

  • #1445

    david.smith
  • #1446

    chanarbon

    Hi @seamanjeff,

    You just have to set the type on the search as the script id of the search that you are about to create

    Code:
    search.create({
    type : “customrecord_mycustrecord”,
    filters : [],
    columns : [
    “custrecord_field1”,
    “custrecord_field2”
    ]
    })

  • #1447

    ialan

    Could you show the sample code to retrieve the results as well?

  • #1448

    david.smith

    Use of the Chrome extension will give you this.

    There are multiple ways of running the search but the easiest would look something like this:

    Code:
    var searchObj = search.create({
    type : “customrecord_mycustrecord”,
    filters : [],
    columns : [
    “custrecord_field1”,
    “custrecord_field2″
    ]
    });

    var searchResultCount = searchObj.runPaged().count;

    searchObj.run().each(function(result){
    // .run().each has a limit of 4,000 results

    var field1 = result.getValue({name:”custrecord_field1″});
    var field2_text = result.getText({name:”custrecord_field2”});

    return true; // return must be true in order to iterate all results.
    });

  • #1449

    chanarbon

    ialan

    the result object has functions getValue() for general purpose and getText() to get the text presentation of an list/record field.

You must be logged in to reply to this topic.