Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Non-breaking space

HagosT
Tera Contributor

How can I add none-breaking space when exporting data to excel or csv ?

1 ACCEPTED SOLUTION

Ratnakar7
Mega Sage

Hi @HagosT ,

 

You can use the Unicode character for a non-breaking space, which is U+00A0. Here's an example of how you can achieve this in different scenarios:

  1. Excel export with ServiceNow Export Sets or Reports: When exporting data to Excel using ServiceNow Export Sets or Reports, you can include the non-breaking space character within your data fields. For example, if you want to add a non-breaking space after a specific value in a field, you can concatenate the value with the non-breaking space character like this: "Value" + "\u00A0". This will ensure that the space is preserved in Excel.

  2. CSV export with ServiceNow Transform Maps: When exporting data to CSV using ServiceNow Transform Maps, you can utilize the GlideStringUtil API to replace regular spaces with non-breaking spaces before exporting. Here's an example script that demonstrates this:

 

 

// Create a CSV string
var csvString = 'Field 1,Field 2,Field 3\nValue 1,Value 2,Value 3';

// Replace spaces with non-breaking spaces
csvString = csvString.replace(/ /g, '\u00A0');


// Create a new attachment record
var attachment = new GlideSysAttachment();
attachment.write('table_name', 'record_sys_id', 'filename.csv', 'text/csv', csvString);

// Attach the file to the record
attachment.setEntryRecord('table_name', 'record_sys_id');
attachment.setEntryID('record_sys_id');
attachment.setContentType('text/csv');
attachment.setFileName('filename.csv');
attachment.attach();

// Optional: Delete the attachment record if needed
attachment.deleteRecord();

 

 

 

Also, refer https://unicode-explorer.com/c/00A0 & https://symbl.cc/en/00A0/ 

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

View solution in original post

2 REPLIES 2

Ratnakar7
Mega Sage

Hi @HagosT ,

 

You can use the Unicode character for a non-breaking space, which is U+00A0. Here's an example of how you can achieve this in different scenarios:

  1. Excel export with ServiceNow Export Sets or Reports: When exporting data to Excel using ServiceNow Export Sets or Reports, you can include the non-breaking space character within your data fields. For example, if you want to add a non-breaking space after a specific value in a field, you can concatenate the value with the non-breaking space character like this: "Value" + "\u00A0". This will ensure that the space is preserved in Excel.

  2. CSV export with ServiceNow Transform Maps: When exporting data to CSV using ServiceNow Transform Maps, you can utilize the GlideStringUtil API to replace regular spaces with non-breaking spaces before exporting. Here's an example script that demonstrates this:

 

 

// Create a CSV string
var csvString = 'Field 1,Field 2,Field 3\nValue 1,Value 2,Value 3';

// Replace spaces with non-breaking spaces
csvString = csvString.replace(/ /g, '\u00A0');


// Create a new attachment record
var attachment = new GlideSysAttachment();
attachment.write('table_name', 'record_sys_id', 'filename.csv', 'text/csv', csvString);

// Attach the file to the record
attachment.setEntryRecord('table_name', 'record_sys_id');
attachment.setEntryID('record_sys_id');
attachment.setContentType('text/csv');
attachment.setFileName('filename.csv');
attachment.attach();

// Optional: Delete the attachment record if needed
attachment.deleteRecord();

 

 

 

Also, refer https://unicode-explorer.com/c/00A0 & https://symbl.cc/en/00A0/ 

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

HagosT
Tera Contributor

Great! Thanks

this was really helpful