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.

Unable to split parm in email script

dauger
Kilo Expert

Hello devs!

 

I am having trouble with parm2 in an email script I am writing.

 
var parm = event.parm2;
var splitParm = parm.split('~');

 

Using that code I had thought splitParm would be delimited by ~ but when I print splitParm the data is delimited by ;

 

Am I going about this the wrong way? How can I have parm2 use ~ as a delimiter?

 

Let me know if there's any other information needed.

1 ACCEPTED SOLUTION

@Juhi Poddar @Tanushree Maiti 

Thank you for all of your help! I discovered the input source for parm2, it was part of a workflow that I overlooked and an event in that workflow delimited by ;

 

I have since changed the ; to ~ and everything is working as expected, thanks again!

View solution in original post

10 REPLIES 10

dauger
Kilo Expert

Hey @Tanushree Maiti 

 

Here's the script:

 

var parm = event.parm2;
var splitParm = parm.split('~');

 

And here is how I'm printing:

 

template.print("START TEST<br>");
template.print("parm: " + parm + "<br>");
template.print("splitParm: " + splitParm);
template.print("<br>END TEST<br>");

 

And the output:

 

START TEST

parm: Other; Data Center Engineering Services; $300000.00; 115.02; 5 year contract (Note, *** would like a full 5 year term, without the restrictions imposed on C001175); Facilities Management; This procurement is intended to replace C001175. The term of C001175 was for 5 years, expiring on 6/5/2029. However, *** required language in the contract limiting the period that new work can be assigned to Sigma7 to only three years, which will be reached on 6/5/2027.; ; ; 3050389; 12751; 55252; 10600; 51092; *** requires engineering services related to data center facility maintenance, including disaster recovery planning; performing mechanical and electrical reviews; assisting with the implementation of a branch circuiting management system process; assisting *** with planning for future growth; creating an accurate infrastructure capacity profile; and providing new or updating existing engineering/architectural site drawings and technical documents. These services are necessary to ensure our Data Center continues to operate as a Tier III facility.; Colin ***** - 03/10/2026 03:07 PM; Pete * ******* - 03/10/2026 03:08 PM; Request for Qualifications (RFQual); Kellie * **********, Patrick ******, Peter * *****, Sara * ******; Sara * ******; 2027-06-07; Peter *****; Peter *****; Continuing; Lack of Expertise; C001175; undefined; ; ;

splitParm: Other; Data Center Engineering Services; $300000.00; 115.02; 5 year contract (Note, *** would like a full 5 year term, without the restrictions imposed on C001175); Facilities Management; This procurement is intended to replace C001175. The term of C001175 was for 5 years, expiring on 6/5/2029. However, *** required language in the contract limiting the period that new work can be assigned to Sigma7 to only three years, which will be reached on 6/5/2027.; ; ; 3050389; 12751; 55252; 10600; 51092; *** requires engineering services related to data center facility maintenance, including disaster recovery planning; performing mechanical and electrical reviews; assisting with the implementation of a branch circuiting management system process; assisting *** with planning for future growth; creating an accurate infrastructure capacity profile; and providing new or updating existing engineering/architectural site drawings and technical documents. These services are necessary to ensure our Data Center continues to operate as a Tier III facility.; Colin ***** - 03/10/2026 03:07 PM; Pete * ******* - 03/10/2026 03:08 PM; Request for Qualifications (RFQual); Kellie * **********, Patrick ******, Peter * *****, Sara * ******; Sara * ******; 2027-06-07; Peter *****; Peter *****; Continuing; Lack of Expertise; C001175; undefined; ; ;

END TEST

 

parm and splitParm are identical, from what I can tell.

 

Based on what @Juhi Poddar said I know that parm.split('~') won't work since parm2 is delimited by ;

 

Any info on how to have parm2 be delimited by ~ would be helpful! Since my main issue is how the data contains a paragraph where a user used semi-colons to separate thoughts, but in so doing made the delimiting give incorrect data to fields in an email notification.

@dauger 

It looks like your parm2 value is actually delimited by ;. Since the string does not contain ~, split("~") will not break the string.

 

Why don’t you try using:

var splitParm = parm.split(';');

 

This should split the values correctly based on the delimiter present in your data.

Hope this helps!

 

Thank You
Juhi Poddar

Hi @dauger ,

 

In JavaScript split()  is a method that divides a string into an array of substrings using a character (it could be special char) as the separator.

 

Here Parm is your string and it is NOT having ANY  '~' char separator

 

Either in param2  input source , you replace ';' by '~'

 

OR  You change your separator  

       from: 

var splitParm = parm.split('~');

To 

var splitParm = parm.split(';');

 

It will work.

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

@Juhi Poddar 

 

Thank you for your responses!

 

My issue is that a user used semi-colons in a field as parts of a sentence, thereby delimiting by semi-colons would throw off the rest of data as it's placed into an email.

 

Given what I've learned from folks on here, I believe that the best solution would be to change how parm2 is being populated before my script attempts to use it.

 

@Tanushree Maiti 

 

Any idea how to change the parm2 input source?

 


@Tanushree Maiti wrote:

 

Either in param2  input source , you replace ';' by '~'

 


 

SO @dauger 

 

In the input source where you need the splits you can try with a special char which we generally do not use like '#'  etc.

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: