Expand my Community achievements bar.

SOLVED

MCM Component Click_Through_Link through error "Uncaught TypeError: Cannot read property 'getElementsByTagName' of null".

Avatar

Former Community Member

When I drag and drop the component Click_Through_Link of group  Call To Action on the page and refresh , I can see error in the console "Uncaught TypeError: Cannot read property 'getElementsByTagName' of null".

Why this is happening, please help .

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I got the problem.  Its is happening because of the way divID is created in the OOB component.

See /libs/mcm/components/cta-clickthroughlink/cta-clickthroughlink.jsp #line 72 

Id is encoded and used is html [divId = xssAPI.encodeForHTMLAttr(divId);]

And the same string divID is encoded in javascript (Written in /libs/mcm/components/cta-clickthroughlink/tracking-js.jsp #line21 ) to find the element which is wrong.

Solution : 

Override the component and replace below code in cta-clickthroughlink.jsp #line 72 

 divId = xssAPI.encodeForHTMLAttr(divId);
            %>
        <div id="<%=divId%>">

 

With

String divHTMLId =xssAPI.encodeForHTMLAttr(divId);

            %>
        <div id="<%=divHTMLId %>">

View solution in original post

4 Replies

Avatar

Level 10

How are you setting the component in its dialog. Are you setting valid values: 

Make sure that you enter a valid URL. See this AEM doc for more information:

https://docs.adobe.com/docs/en/cq/5-6-1/wcm/campaigns/landingpages/extending-and-configuring-the-des...

Avatar

Former Community Member

Thank you for your response.

I am facing the same problem attached is the screen for my dialog.

Avatar

Level 9

@Aditi,

It seems there are some actions (On insert, edit etc) at the component level and those actions has some javascript functions which are failing. It seems the object which calls "getElementsByTagName" this method is undefined.

Check the listeners at the component level. Also, verify javascript in the component jsp.

Jitendra

Avatar

Correct answer by
Former Community Member

I got the problem.  Its is happening because of the way divID is created in the OOB component.

See /libs/mcm/components/cta-clickthroughlink/cta-clickthroughlink.jsp #line 72 

Id is encoded and used is html [divId = xssAPI.encodeForHTMLAttr(divId);]

And the same string divID is encoded in javascript (Written in /libs/mcm/components/cta-clickthroughlink/tracking-js.jsp #line21 ) to find the element which is wrong.

Solution : 

Override the component and replace below code in cta-clickthroughlink.jsp #line 72 

 divId = xssAPI.encodeForHTMLAttr(divId);
            %>
        <div id="<%=divId%>">

 

With

String divHTMLId =xssAPI.encodeForHTMLAttr(divId);

            %>
        <div id="<%=divHTMLId %>">

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----