
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2023 12:40 PM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2023 09:36 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2023 10:02 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2023 12:52 PM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2023 07:37 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2023 08:39 AM - edited ‎06-07-2023 08:43 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2023 09:30 AM
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?