Netsuite Subscriptions Restlet -


i have restlet script updates customer. in customer want loop through subscription objects passed in have subscription names match them on.

does know how access subscriptions object in netsuite?

i got response netsuite cannot access subscriptions object in netsuite had write little bit of hack. did grab existing member , load them up. member should have array of active subscriptions.

i loop through them , create array object pass containing subscription name , internalid.

i can use array loop through customer subscriptions passed in names , matching internalid.

here code wrote. please feel free streamline if think can written better.

var campaigns = new array(); try {     // netsuite not expose campaign subscriptions     var filters = new array();     filters[0] = new nlobjsearchfilter('internalid', null, 'is', 26); //anon customer     var columns = new array();     columns[0] = new nlobjsearchcolumn('internalid');     //columns[1] = new nlobjsearchcolumn('campaign', null, null);     results = nlapisearchrecord('customer', null, filters, columns);     resultstotal = (results != null) ? results.length : 0;     if (resultstotal > 0) {         var customerid = results[0].getid();         var customer = nlapiloadrecord('customer', customerid, {             customform: -2         });         var mystring = json.stringify(customer); //convert string         var data = json.parse(mystring); //then parse json         (var node in data) { //for each node in data                         (attr in data[node]) { //for each attribute in node                 if (node == "subscriptions") {                     (var node2 in data[node][attr]) { //for each node in subscriptions                         if (node2 == 'subscription') { //get subscription nodes                              var campaign = new object();                             var name = '';                             var internalid = 0;                             (var node3 in data[node][attr][node2]) {                                 if (node3 == 'name') {                                     name = data[node][attr][node2][node3];                                 } else if (node3 == 'internalid') {                                     internalid = parseint(data[node][attr][node2][node3]);                                 }                             }                             //nlapilogexecution('audit', name, internalid); //name                               campaign[name] = internalid;                             if (!campaigns.hasobject()) {                                 campaigns.push(campaign);                             }                             //nlapilogexecution('audit', node2, json.stringify(data[node][attr][node2]));   //subscription                                                       }                         //nlapilogexecution('audit', node2, json.stringify(data[node][attr][node2]));                     }                     //nlapilogexecution('audit', node, json.stringify(data[node][attr])); //subscriptions                    }             }         }         nlapilogexecution('audit', 'campaigns', json.stringify(campaigns));     } } catch (e) {     nlapilogexecution('error', 'error', 'there error. ' + e.name + ' - ' + e.message + '.'); } return campaigns; 

Comments