Importing Into Set of String Data Type #424
Replies: 12 comments
-
Hi,
You need to insert an array rather than a string, just as you are getting
it from API
…On Thu, Jul 4, 2019, 7:16 PM ramyabitorder ***@***.***> wrote:
Hello All,
We have a Set of Strings Data Type in our Product object. We need to
populate it programmatically. I am getting the values and iterating as
follows.
activityArrayToLoop.forEach(function(key ) {
xmlString += ''+key+''+'
';
});
to generate a string as below.
Snorkel + Scuba
Travel
Hike + Backpack
Ski + Snowboard
When i import the same into the product object , all the values are
populating in one field rather than multiple fields in the Set of Strings
Data Type. I have tried adding ‘\n’ ‘
<\br>’ and
to insert new lines. I have even tried putting the above into CDATA. But
none of these have helped inserting them separately into product.
When I import the xml from the instance i get below , so I believe Im
building it correctly, however I am missing something to do with new line .
Please suggest I am doing anything wrong here.
Snorkel + Scuba Travel Hike + Backpack Ski + Snowboard
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/orgs/SalesforceCommerceCloud/teams/community/discussions/74?email_source=notifications&email_token=AKECNZLL77WAHC5M7ZJJ6OLP5XXB5A5CNFSM4H5Z4KD2YY3PNVWWK3TUL52HS4DFVZCGS43DOVZXG2LPNZIG643UVJRW63LNMVXHIX3JMTHAAAIZQM>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKECNZORHKTUBMBOX6DO65DP5XXB5ANCNFSM4H5Z4KDQ>
.
|
Beta Was this translation helpful? Give feedback.
-
Hello Praveen Gaur, Sorry for the delay. Im sure, Im missing something minor here, because when I manually import the file , the value within in the below string get populated correctly in my Custom Activity field. Snorkel + Scuba Travel Hike + Backpack Ski + Snowboard |
Beta Was this translation helpful? Give feedback.
-
Have you tried to do a manual edit and export of XML to see how exactly the XML looks like after the export? |
Beta Was this translation helpful? Give feedback.
-
Hello Zlatin, It looks exactly like how I have built it when I export it from the system. Below is the one i just got from the exported xml again.
|
Beta Was this translation helpful? Give feedback.
-
Hi @ramyabitorder, |
Beta Was this translation helpful? Give feedback.
-
Hi @ramyabitorder & Zlatin, If I understood correctly then Ramya you are trying to insert the values in a set of string attribute on product object. And you are trying to do it programmatically but ending up in setting all the values as a single String literal in the first value in the attribute, as opposed to having it as different string values. For setting the set of strings, arrays need to be passed as set-of-string attribute value, pseudo code: require('dw/system/Transaction').wrap(function(){
This code works for me, have a look at the attached image - setting up the right values using the above code. I am somehow not able to attach the files here. Irrespective of the source data, if you trying to update set of string then arrays need to be used. Both, let me know if I misunderstood it or Ramya if you face any issue in going through the code. |
Beta Was this translation helpful? Give feedback.
-
Hi @pravngaur, |
Beta Was this translation helpful? Give feedback.
-
Thats correct.
|
Beta Was this translation helpful? Give feedback.
-
Hi @ramyabitorder Thanks, |
Beta Was this translation helpful? Give feedback.
-
Hello @zlatinz Here is my code snippet. The following code is within a while loop. Please note this is not complete code , but just to give a brief of how its built. I have attribute map from which Im setting the values for the fields. Here Activity field is of type set of strings. `if (file.createNewFile()) { exportFileWriter.write('\n'); var productID : String = eachProject.getCustom()['ArtifactID']; var displayName : String = attributesMap.get("name"); var productBrand : String = attributesMap.get("brand"); var activity : String = attributesMap.get("activity”);//the data type of this field is Set-Of_strings. Contains Snorkel + Scuba Travel Hike + Backpack Ski + Snowboard if(productID != undefined && productID != null && productID != '')
if(activity != undefined && activity != null && activity != '')
` |
Beta Was this translation helpful? Give feedback.
-
Several recommendations:
|
Beta Was this translation helpful? Give feedback.
-
My bad!! Just to add to what Zlatin said, please check if you can use XMLStreamWriter, that will wrap around the XML specific functions, which will take away a lot of low level stuff. As @zlatinz suggested, flush and try-catch holds true to both the writers. Let us know how it goes. |
Beta Was this translation helpful? Give feedback.
-
Hello All,
We have a Set of Strings Data Type in our Product object. We need to populate it programmatically. I am getting the values and iterating as follows.
activityArrayToLoop.forEach(function(key ) {
xmlString += ''+key+''+'
';
});
to generate a string as below.
<custom-attribute attribute-id="activity" xml:lang="x-default"> <value>Snorkel + Scuba</value><br /> <value>Travel</value><br /> <value>Hike + Backpack</value><br /> <value>Ski + Snowboard</value><br /> </custom-attribute>
When i import the same into the product object , all the values are populating in one field rather than multiple fields in the Set of Strings Data Type. I have tried adding ‘\n’ ‘
<\br>’ and
to insert new lines. I have even tried putting the above into CDATA. But none of these have helped inserting them separately into product.
When I import the xml from the instance i get below , so I believe Im building it correctly, however I am missing something to do with new line . Please suggest I am doing anything wrong here.
<custom-attribute attribute-id="activity" xml:lang="x-default"> <value>Snorkel + Scuba</value> <value>Travel</value> <value>Hike + Backpack</value> <value>Ski + Snowboard</value> </custom-attribute>
Beta Was this translation helpful? Give feedback.
All reactions