MyApi call to an export with data

I have created 2 exports.  One that retrieves all of the Customer records from NetSuite (export 1).  A second one (export 2) that uses a key (custId in the search criteria ) to retrieve only the customer record that is passed in. (I tested the 2nd one by hard coding in the custId in the search criteria and works)

Using exports.run({id:'623**************dea'}); for the export 1 that returns all records works fine.

When trying to pass in the custId (export 2), I attempted to send it in a few ways, both generating error responses.

the code i am using to pass custId in is
 const myData = [{
    custId:"C100597"
  }];
 
Ver 1:
invokeExportResponse = exports.run({_id:'62434a42363bdb71132d8311', data : myData});   
 
{
    "exportResponse": "{\"code\":\"handlebars_template_parse_error\",\"message\":\"Failed to generate criteria.3.searchValue from template: {{custId}}. Details: \\\"custId\\\" not defined in the model. - 1:2.\"}"
}
 
Ver 2:
    invokeExportResponse = exports.run({_id:'62434a42363bdb71132d8311', listenerData : myData});   
 
{
    "exportResponse": "{\"message\":\"Error response from API.\"}"
}
 
Can I pass a play-load to an export so that the search criteria can use the data to construct a search, and if so what is the correct way/format?
 
thank you
bill
 
0

Comments

6 comments
Date Votes
  • Official comment

    Thanks bill budwitz for reaching out. Glad to know that you were able to solve the issue by recreating the export as an object. About passing the extra data in Payload such as search criteria, we will consider this as an enhancement. We will keep you posted around this once this enhancement is available. 

  • I was able to solve by using export.runVirtual and getting the export document and recreating the export as an object. 

    it would still be interesting to know if using export.run to reference the export directly and pass in a payload/parameters for the search  criteria. 

    thanks

    0
  • I want to do the same thing.  I can get the data, but not being able to pass it through the export itself, I lost the array.  How did you do it?

    0
  • Todd, maybe this example here in the docs will help shed some light on how to do this. At a very high level, the 'export.runVirtual' function allows you to define the export configuration that you want to run in your code directly, and you can parameterize it however you like.

    For sure it is tedious to define the export objects in your code directly, because then you need to configure all the right fields that the UI does on your behalf already. The way I always do this is first create the export that I want to run in the UI, and then I use something like Postman to GET '/exports/_id' for the export that I created so I can see the JSON, and then i copy and paste the JSON for the export into my JavaScript code, and then simply change the parts that I want to be dynamic.

    We have plans for R1/R2 next year to make all of this much much easier where you can easily pass parameters to your existing exports in your JavaScript (i.e. without having to use virtual exports at all). I know this does not help you right now, but there is a better UX on the near term horizon.

     

    1
  • Scott, I know this topic is 9 months old, but I wanted to thank you for your helpful answer. Your tip on using Postman to get the JSON for the export and then modifying it in my code was brilliant. It saved me a lot of time and hassle. I tried it and it worked like a charm! I’m excited for the new UX that will make this even easier. I really appreciate your time and expertise.

    0
  • Happy to help!

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post