Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Can someone please share the formula to trim a text field in SN?

irene_mascari
Tera Expert

I am setting up a PDF Document Template.

The required form field is Middle Initial. I have mapped this Form Field to the Subject Person's Middle Name. There is an option to add an Advanced Script.

I am looking for the correct Formula/Syntax/Function to trim the text in the Middle Name field to 1 character.

 

Any help will be appreciated. I search but have been unable to find anything for how to accomplish this seemingly simple task.

 

Thanks! 

 

 

2 ACCEPTED SOLUTIONS

Hi @irene_mascari 

 

can you try with below script

(function evaluateMappingFieldValue(taskGr /* GlideRecord for parent task */, mappingField /* Pre-computed mapping field value */) {

return ("" +mappingField.charAt(0));

})(taskGr, mappingField);

View solution in original post

THANK YOU!!!!! That worked perfectly. This solves a host of problems for us. I am so very grateful. Thank you for your time and your expertise.

View solution in original post

7 REPLIES 7

Hi @irene_mascari 

 

can you try with below script

(function evaluateMappingFieldValue(taskGr /* GlideRecord for parent task */, mappingField /* Pre-computed mapping field value */) {

return ("" +mappingField.charAt(0));

})(taskGr, mappingField);

THANK YOU!!!!! That worked perfectly. This solves a host of problems for us. I am so very grateful. Thank you for your time and your expertise.

I was just giving an example of how you could do it.  My code was in no way a cut and paste.  Based on what you posted you should have used taskGr.  Also if you want to get the first char you need to use zero not one.