Accessing the DOM object in client script

GnaneshP
Tera Contributor

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?

5 REPLIES 5

Marcos Kassak
Kilo Sage
Kilo Sage

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  🎯

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.

You are running this from a Client Script, right? I have just run the very same code and it works with .value:

 

Script:

 

MarcosKassak_0-1729875968423.png

 

Result:

 

MarcosKassak_1-1729875994246.png

 

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  🎯

 

jusfory1
Tera Expert
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', '');
}