Travis
Travis

Reputation: 420

Turning Array Into String in SnapLogic

I have the output of a SalesForce SOQL snap that is a JSON in this format.

[
  {
    "QualifiedApiName": "Accelerator_Pack__c"
  },
  {
    "QualifiedApiName": "Access_Certifications__c"
  },
  {
    "QualifiedApiName": "Access_Requests__c"
  },
  {
    "QualifiedApiName": "Account_Cleansed__c"
  },
  {
    "QualifiedApiName": "Account_Contract_Status__c"
  }
]

I am attempting to take those values and turn them into a string with the values separated by commas, like this, so that I can use that in the SELECT clause of another query.

Accelerator_Pack__c, Access_Certifications__c, Access_Requests__c, Account_Cleansed__c, Account_Contract_Status__c

From the documentation, my understanding was that .toString() would convert the array into a comma-separated string, but as shown in the attached image, it isn't doing anything. Does anyone have experience with this?

enter image description here

Upvotes: 3

Views: 2326

Answers (2)

Patan
Patan

Reputation: 23

You can also use the array functions directly to achieve this. see the below pipeline that can be used to concat the values:

enter image description here

I have used the JSONGenerator for taking your sample data as input. Then I have used the GroupByN snap with '0' as the group size to formulate the array.

enter image description here

Finally in the mapper you can use the below expression to concat:

jsonPath($, "$arrayAccom[*].QualifiedApiName").join(",")

enter image description here

Upvotes: 0

Bilesh Ganguly
Bilesh Ganguly

Reputation: 4131

You need to aggregate the incoming documents.

Use the Aggregate snap with the function CONCAT. This will give you a | delimited concatenated string as the output like as follows.

Accelerator_Pack__c|Access_Certifications__c|Access_Requests__c|Account_Cleansed__c|Account_Contract_Status__c

You can then replace the | with , like $concatenated_fields.split('|').join(',') or $concatenated_fields.replace(/\|/g, ',').

Following is a detailed explanation of the configuration.

Sample Pipeline:

Sample Pipeline

Sample Input:

I set the sample JSON you provided in a JSON Generator for testing.

Sample Input

Aggregation:

Aggregation

Result of Aggregation:

You get a | delimited concatenated string.

aggregate output

Mapper Expression:

mapper

Output:

Both expressions give the same result.

Output

Upvotes: 2

Related Questions