# While Integrating NetSuite Sales Order I want to map only few items not all from Salesforce

**URL:** <https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346>\
**Category:** Integrator.io\
**Tags:** script, filter, javascript, salesforce, netsuite\
**Created:** [September 27, 2023, 5:44am UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346 "2023-09-27T05:44:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anilanwane](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@anilanwane](https://connective.celigo.com/u/anilanwane)\
**Post date:** [September 27, 2023, 5:44am UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/1 "2023-09-27T05:44:26Z")

</div>

I am trying to do it using preSavePageFunction as shown below

```
function preSavePageFunction(options) { for (var i = 0; i < options.data.length; i++) { var order = options.data[i]; var filteredOpportunityLineItems = []; for (var j = 0; j < order.OpportunityLineItems.length; j++) { var item = order.OpportunityLineItems[j]; if (item.DoNotSync__c == 'false') { filteredOpportunityLineItems.push(item); } } order.OpportunityLineItems = filteredOpportunityLineItems; } return { data: options.data, errors: options.errors };}
```

But it is not working.

Can someone please help me here

---

<div class="post-metadata">

**Author:** ![balasubramanianmahad](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@balasubramanianmahad](https://connective.celigo.com/u/balasubramanianmahad)\
**Post date:** [September 27, 2023, 8:21am UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/2 "2023-09-27T08:21:37Z")

</div>

@anilanwane Are you trying to do the preSavePageFunction in a custom flow or are you using any of the flows in the Salesforce - NetSuite integration app?

---

<div class="post-metadata">

**Author:** ![anilanwane](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@anilanwane](https://connective.celigo.com/u/anilanwane)\
**Post date:** [September 27, 2023, 8:25am UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/3 "2023-09-27T08:25:22Z")

</div>

Hi,

I have created a custom Standalone flow in Celigo for Salesforce to NetSuite Integration.

---

<div class="post-metadata">

**Author:** ![balasubramanianmahad](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@balasubramanianmahad](https://connective.celigo.com/u/balasubramanianmahad)\
**Post date:** [September 27, 2023, 9:49am UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/4 "2023-09-27T09:49:36Z")

</div>

Hi Anil,

Thanks for the information. Since you are using a custom flow to perform this operation, I am moving this to the **Troubleshoot custom flows** topic for better visibility.

---

<div class="post-metadata">

**Author:** ![basvanditzhuijzen](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/basvanditzhuijzen/32/4422_2.png) [@basvanditzhuijzen](https://connective.celigo.com/u/basvanditzhuijzen)\
**Post date:** [September 27, 2023, 11:04am UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/5 "2023-09-27T11:04:01Z")

</div>

Don't use for loops for iterating arrays, but use forEach. And then use filter() to remove things you dont need:

```
options.data.forEach(order => { order.OpportunityLineItems = order.OpportunityLineItems.filter(line => line.DoNotSync__c == 'false');});
```

---

<div class="post-metadata">

**Author:** ![anilanwane](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@anilanwane](https://connective.celigo.com/u/anilanwane)\
**Post date:** [September 27, 2023, 1:30pm UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/6 "2023-09-27T13:30:54Z")

</div>

Hi Bas Van,

I tried using For Each. I am getting same error as given below.

**Extension result doesn't contain the same number of elements as the request object. Expected 1, got . Extension returned statusCode 200.**

Can you please provide me if you have any such function used for removing few line items from SalesOrder.

Many thanks,

Anil

---

<div class="post-metadata">

**Author:** ![tylerlamparter](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/tylerlamparter/32/9204_2.png) [@tylerlamparter](https://connective.celigo.com/u/tylerlamparter)\
**Post date:** [September 28, 2023, 2:58am UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/7 "2023-09-28T02:58:19Z")

</div>

@anilanwane can you send what the JSON input of your script is? Can't help much without that.

---

<div class="post-metadata">

**Author:** ![anilanwane](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@anilanwane](https://connective.celigo.com/u/anilanwane)\
**Post date:** [September 28, 2023, 3:32am UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/8 "2023-09-28T03:32:09Z")

</div>

Hi Tyler Lamparter,

Please find the input JSON below.

```
{ "data": [{ "Id": "Id", "IsDeleted": "IsDeleted", "IsPrivate": "IsPrivate", "Name": "Name", "Description": "Description", "StageName": "StageName", "Amount": "Amount", "Probability": "Probability", "ExpectedRevenue": "ExpectedRevenue", "TotalOpportunityQuantity": "TotalOpportunityQuantity", "CloseDate": "CloseDate", "Type": "Type", "NextStep": "NextStep", "LeadSource": "LeadSource", "IsClosed": "IsClosed", "IsWon": "IsWon", "ForecastCategory": "ForecastCategory", "ForecastCategoryName": "ForecastCategoryName", "HasOpportunityLineItem": "HasOpportunityLineItem", "CreatedDate": "CreatedDate", "LastModifiedDate": "LastModifiedDate", "SystemModstamp": "SystemModstamp", "LastActivityDate": "LastActivityDate", "PushCount": "PushCount", "LastStageChangeDate": "LastStageChangeDate", "FiscalQuarter": "FiscalQuarter", "FiscalYear": "FiscalYear", "Fiscal": "Fiscal", "ContactId": "ContactId", "LastViewedDate": "LastViewedDate", "LastReferencedDate": "LastReferencedDate", "HasOpenActivity": "HasOpenActivity", "HasOverdueTask": "HasOverdueTask", "DeliveryInstallationStatus __c": "DeliveryInstallationStatus__ c", "TrackingNumber __c": "TrackingNumber__ c", "NetSuiteSalesOrder __c": "NetSuiteSalesOrder__ c", "CurrentGenerators __c": "CurrentGenerators__ c", "MainCompetitors __c": "MainCompetitors__ c", "Ammendment_Opportunity_Type __c": "Ammendment_Opportunity_Type__ c", "RA_Source_Document __c": "RA_Source_Document__ c", "Account": { "Id": "Account.Id" }, "OpportunityLineItems": [ { "Id": "Id", "SortOrder": "SortOrder", "ProductCode": "ProductCode", "Name": "Name", "Quantity": "Quantity", "TotalPrice": "TotalPrice", "UnitPrice": "UnitPrice", "ListPrice": "ListPrice", "ServiceDate": "ServiceDate", "Description": "Description", "CreatedDate": "CreatedDate", "LastModifiedDate": "LastModifiedDate", "SystemModstamp": "SystemModstamp", "IsDeleted": "IsDeleted", "LastViewedDate": "LastViewedDate", "LastReferencedDate": "LastReferencedDate", "DoNotSync __c": "DoNotSync__ c", "End_Date __c": "End_Date__ c", "Start_Date __c": "Start_Date__ c", "Product2": { "NetSuite_Item_ID __c": "Product2.NetSuite_Item_ID__ c" } }] } ], "_importId": "651125c1d6edd5374f92f456", "_connectionId": "6504237d52cd84685a218ae3", "_flowId": "650d5657fdc8375a68630ff6", "settings": { "integration": {}, "flowGrouping": {}, "flow": {}, "import": {}, "connection": {} }}
```

---

<div class="post-metadata">

**Author:** ![tylerlamparter](https://sea1.discourse-cdn.com/flex001/user_avatar/connective.celigo.com/tylerlamparter/32/9204_2.png) [@tylerlamparter](https://connective.celigo.com/u/tylerlamparter)\
**Post date:** [September 28, 2023, 2:09pm UTC](https://connective.celigo.com/t/while-integrating-netsuite-sales-order-i-want-to-map-only-few-items-not-all-from-salesforce/346/9 "2023-09-28T14:09:26Z")

</div>

@anilanwane what is not working with your script? It's working fine for me. I tested on the below sample and the output was only 1 line and not 2.

```
{ "Id": "Id", "IsDeleted": "IsDeleted", "IsPrivate": "IsPrivate", "Name": "Name", "Description": "Description", "StageName": "StageName", "Amount": "Amount", "Probability": "Probability", "ExpectedRevenue": "ExpectedRevenue", "TotalOpportunityQuantity": "TotalOpportunityQuantity", "CloseDate": "CloseDate", "Type": "Type", "NextStep": "NextStep", "LeadSource": "LeadSource", "IsClosed": "IsClosed", "IsWon": "IsWon", "ForecastCategory": "ForecastCategory", "ForecastCategoryName": "ForecastCategoryName", "HasOpportunityLineItem": "HasOpportunityLineItem", "CreatedDate": "CreatedDate", "LastModifiedDate": "LastModifiedDate", "SystemModstamp": "SystemModstamp", "LastActivityDate": "LastActivityDate", "PushCount": "PushCount", "LastStageChangeDate": "LastStageChangeDate", "FiscalQuarter": "FiscalQuarter", "FiscalYear": "FiscalYear", "Fiscal": "Fiscal", "ContactId": "ContactId", "LastViewedDate": "LastViewedDate", "LastReferencedDate": "LastReferencedDate", "HasOpenActivity": "HasOpenActivity", "HasOverdueTask": "HasOverdueTask", "DeliveryInstallationStatus __c": "DeliveryInstallationStatus__ c", "TrackingNumber __c": "TrackingNumber__ c", "NetSuiteSalesOrder __c": "NetSuiteSalesOrder__ c", "CurrentGenerators __c": "CurrentGenerators__ c", "MainCompetitors __c": "MainCompetitors__ c", "Ammendment_Opportunity_Type __c": "Ammendment_Opportunity_Type__ c", "RA_Source_Document __c": "RA_Source_Document__ c", "Account": { "Id": "Account.Id" }, "OpportunityLineItems": [{ "Id": "Id", "SortOrder": "SortOrder", "ProductCode": "ProductCode", "Name": "Name", "Quantity": "Quantity", "TotalPrice": "TotalPrice", "UnitPrice": "UnitPrice", "ListPrice": "ListPrice", "ServiceDate": "ServiceDate", "Description": "Description", "CreatedDate": "CreatedDate", "LastModifiedDate": "LastModifiedDate", "SystemModstamp": "SystemModstamp", "IsDeleted": "IsDeleted", "LastViewedDate": "LastViewedDate", "LastReferencedDate": "LastReferencedDate", "DoNotSync __c": "false", "End_Date__ c": "End_Date __c", "Start_Date__ c": "Start_Date __c", "Product2": { "NetSuite_Item_ID__ c": "Product2.NetSuite_Item_ID __c" } }, { "Id": "Id", "SortOrder": "SortOrder", "ProductCode": "ProductCode", "Name": "Name", "Quantity": "Quantity", "TotalPrice": "TotalPrice", "UnitPrice": "UnitPrice", "ListPrice": "ListPrice", "ServiceDate": "ServiceDate", "Description": "Description", "CreatedDate": "CreatedDate", "LastModifiedDate": "LastModifiedDate", "SystemModstamp": "SystemModstamp", "IsDeleted": "IsDeleted", "LastViewedDate": "LastViewedDate", "LastReferencedDate": "LastReferencedDate", "DoNotSync__ c": "true", "End_Date __c": "End_Date__ c", "Start_Date __c": "Start_Date__ c", "Product2": { "NetSuite_Item_ID __c": "Product2.NetSuite_Item_ID__ c" } }] }
```

 ![5301043caa20740200000001-146850de197141378cff58b4d6d75c6d.png](https://us1.discourse-cdn.com/flex001/uploads/celigo/original/2X/d/db0827e4294a746f623737625a45d3f9df2bf275.png)
