- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 06:08 AM
Hi All,
Can you tell me how store Last word one of the variable :
short Description :HR Profile GET API failure for cili
In this case i want to store Cili in on of the variable, Can you help me .
Thanks and Regards,
chandan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 04:33 AM
You're not invoking the function correctly. Have you used JavaScript previously to ServiceNow?
Correct usage:
function getLastWord(str) {
// Trim any whitespace from the ends of the string
str = str.trim();
// Split the string into an array of words
var words = str.split(/\s+/);
// Return the last word
return words[words.length - 1];
}
getLastWord(current.getValue('short_description'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 04:33 AM
You're not invoking the function correctly. Have you used JavaScript previously to ServiceNow?
Correct usage:
function getLastWord(str) {
// Trim any whitespace from the ends of the string
str = str.trim();
// Split the string into an array of words
var words = str.split(/\s+/);
// Return the last word
return words[words.length - 1];
}
getLastWord(current.getValue('short_description'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 10:04 AM
Hi @chandan31
PPlease try this below code
// Assuming 'shortDescription' contains the short description provided
var shortDescription = 'HR Profile GET API failure for cili';
// Split the string by spaces
var words = shortDescription.split(' ');
// Get the last word
var lastWord = words[words.length - 1];
// Now 'lastWord' contains 'cili', you can store it in a variable or use it a s needed
Please accept my solution if it resolves your issue and thumps 👍 up
Thanks
Jitendra
