Accessing the DOM object in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 11:23 AM - edited 10-23-2024 11:25 AM
I'm trying to get the text content from a HTML field (the content will be dynamic) and then display the value in another field (say 'description'). The client script I tried is not working as expected. The ID which is mentioned within the getElement() is for 'div' tag. For simple actions like button.click() is working but not when it comes to retrieving the text content.
Below is the code which I'm trying
var summaryText = g_form.getElement('gen-summaryText');
var strSummary = String.valueOf(summaryText);
alert(strSummary);
if (strSummary !== null) {
g_form.setValue('description', strSummary);
} else {
g_form.setValue('description', '');
}
Output:
function String() { [native code] }
Can anyone please pour your suggestions?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 12:46 PM
Hi @GnaneshP,
Can you try the code below and let me know the output?
var summaryTextElement = g_form.getElement('gen-summaryText');
var strSummary = summaryTextElement.value || '';
g_form.setValue('description', strSummary);
If you found my answer helpful or correct ✔️ in any way, please don't forget to mark it to help future readers! 👍
--
Kind regards,
Marcos Kassak
Solution Consultant 🎯
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 09:16 PM
Hi @Marcos Kassak, I tried this but no luck. Also I tried delay function to get the value after few seconds and stored it in separate variable, but same output.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 10:07 AM
You are running this from a Client Script, right? I have just run the very same code and it works with .value:
Script:
Result:
incident.short_description is the ID tag of the div
If you found my answer helpful or correct ✔️ in any way, please don't forget to mark it to help future readers! 👍
--
Kind regards,
Marcos Kassak
Solution Consultant 🎯
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 11:29 PM
var rootEle = g_form.getElement('description').getRootNode();// DOM;
var summaryEleID = 'gen-summaryText';
var summaryEle = rootEle.querySelector(summaryEleID);
var summaryInnerHtml = summaryEle.innerHTML;// or summaryEle.innerText;
alert(summaryInnerHtml);
if (summaryInnerHtml) {
g_form.setValue('description', strSummary);
} else {
g_form.setValue('description', '');
}