The Zurich release has arrived! Interested in new features and functionalities? Click here for more

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

DrewW
Mega Sage
Mega Sage

You can use the charAt method.

https://www.w3schools.com/jsref/jsref_charat.asp

 

So something like this

return ("" + current.getValue("some_field")).charAt(0);

 

Hello Drew,

Thank you so much for trying to help me. I tried to incorporate the formula you provided but the PDF is returning a blank instead of the first letter of the person's middle name.

 

Here is what I have for the Advanced Script:

 

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

return ("" + current.getValue("subject_person.middle_name")).charAt(1);

})(taskGr, mappingField);

Hi @irene_mascari 

 

The syntax used for current.getValue() is wrong. Please tell in which field is the middle name stored and in which table

Also which table does current refers to in the script below

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

return ("" + current.getValue("subject_person.middle_name")).charAt(1);

})(taskGr, mappingField);

 

Hi Manmohan

Thank you for responding. I appreciate it!

 

I just used the field name that is indicated on the mapping in the "formula." (See screenshot attached.)

 

If I am understanding you correctly I would need to put:    sn_hr_core_case.subject_person.middle_name

 

instead of:    subject_person.middle_name 

Is that correct?