- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 03:49 AM
Hi All,
How to retrieve a value from HTML Table. I need to get the User Name.
Regards,
Siva
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 12:09 PM
Hello Guys @Ansh1 , @sivareddy ,
Apologizes for the late reply. I was stuck in someother work. Here we go. I just worked with your HTML and pasting the code below to print the User Name --> Creddy.
Cheers🥂.
var html = 'Your HTML Code';
var splitHtml = html.split('</td>');
var count = 0;
for (var i = 0; i < splitHtml.length; i++) {
if (splitHtml[i].includes('User Name')) {
count = i + 1;
}
}
var result = splitHtml[count].replace(/<[^>]*>/g, '').replace(' ', '').trim();
gs.info(result)
Regards,
Dhanraj.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 04:36 AM
Hi Siva,
Did you try something as below for parsing
var userdomainis=email.caller_user_domain; //should ideally give you value
gs.log('User domain ',userdomainis);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 05:13 AM
Hi @Jaspal Singh I'm trying to pull the value from the received mail. i've attached sample template as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:45 AM
Hi @sivareddy ,
Is all that values pulled from the table or somewhere else?
If it is pulled from the table, you can use the target record to print the values of it.
If it is not from table, you can split the html body using tags and pull the values from it. I have wrote a script for it using sample HTML and the JS to print the value of some string value in the HTML.
<style>
#snc_notification_preference {
text-decoration: none;
}
#snc_notification_unsubscribe {
text-decoration: none;
}
</style>
<style> #schedule-report table, #schedule-report th, #schedule-report td { border-collapse: collapse; border: 1px solid black; text-align: center; padding: 5px; font-size: 10pt; font-family: SourceSansPro, "Helvetica Neue", Arial; } #schedule-report th, #schedule-report tr > td:first-child { background-color: #767676; color: white; } </style><div><div id="schedule-report"><p>Please review pending actions for your On-Call group(s).</p><table><tr> <th>On-Call Coverage Gaps</th> <th>Group Name</th> <th>Manager Name</th> <th>Schedule Name</th> <th>Occurrences</th> <th>Take Action</th> </tr><tr> <td></td> <td>Application Development</td> <td>Bushra Akhtar</td> <td>Working Hours</td> <td>11</td> <td> <a href='https://dev57352.service-now.com/$oc_workbench.do?sysparm_group_id=0a52d3dcd7011200f2d224837e6103f2' target='_blank'>View Workbench</a></td> </tr></table></div></div>
<br></br>
<a id="snc_notification_unsubscribe" href="mailto:dev57352@servicenowdevelopers.com?subject=Unsubscribe from "On-Call Schedule - Gaps and Conflicts"&body=Sending this email with the predefined content in the subject and body will unsubscribe you from the notification "On-Call Schedule - Gaps and Conflicts"%0D%0A%0D%0AUnsubscribe:{"id":"5d7cfc2273602300cbb654eb7df6a7ce","token":"c797e62132"}">Unsubscribe</a> | <a id="snc_notification_preference" href="https://dev57352.service-now.com/nav_to.do?uri=notification_preferences.do%3Fsysparm_notification=5d7cfc2273602300cbb654eb7df6a7ce">Notification Preferences</a>
In the below script, I used <td> to split the body of the html and I have printed the value of "Bushra Akhtar". You can use the same logic to print the value of username. Here I have used 'Application Development', you can use 'User Name'.
var email = new GlideRecord('sys_email');
if(email.get('fc03c369974e4a104020b986f053af32')){
var body = email.body;
var spBody = body.split('<td>');
for (var i = 0; i < spBody.length; i++){
if(spBody[i].includes('Application Development')){
var count = i;
}
}
var name = spBody[count+1].replace('</td>','');
gs.info(name);
}
This code might not work, because your HTML might differ from mine. If you are facing difficulties in print the value, paste the HTML here. I will give you the exact code to print the value of username.
Regards,
Dhanraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 04:26 AM