Quick workaround to solve issue regarding oData Create in Latest Chrome! (version 34)
Note : This issue was specific to the chrome version 34 which has been fixed in the later versions & this workaround is no more needed.
Hey All,
If you get an error as below when you do oData Create,
Open your console and execute the below code & check if your app works (don’t refresh after executing this code in console) https://gist.github.com/arv/9529994
if (!Document.prototype.createAttributeNS) {
Document.prototype.createAttributeNS = function(namespaceURI, qualifiedName) {
var dummy = this.createElement('dummy');
dummy.setAttributeNS(namespaceURI, qualifiedName, '');
var attr = dummy.attributes[0];
dummy.removeAttributeNode(attr);
return attr;
};
}
if (!Element.prototype.setAttributeNodeNS) {
Element.prototype.setAttributeNodeNS = Element.prototype.setAttributeNode;
}
If your app works like a charm 🙂 , then the reason for the above error is just because Chrome has removed some DOM Level 2 API’s. Internally data.js in UI5 uses two functions
document.createAttributeNS() , document.setAttributeNodeNS()
which have been removed from chrome’s API. The workaround code would manually add those functions to the DOM’s document Object.
So, till this is fixed you can create a new js file say, workaround.js and copy the code posted above and import it to your ui5 app index.html as
<script src=”workaround.js”></script>
Once this issue is resolved, you can remove the workaround script 🙂 This is one of the workaround available.
For FIORI Apps that are loaded through component rather than index.html , you can do either of below steps.
- You can do jQuery.sap.require(“folderLocation.workaround”); in your app.js or component.js . But make sure you register the folderLocation using jQuery.sap.registerModulePath() or sap.ui.localResources()
(OR)
- Alternative for above one & much simpler approach, copy the code of workaround and paste it anywhere before you do the first oData crud operation.
Note : I’d suggest you can go for 1st approach only if you know how to import javascript using jQuery.sap.require else go for the second one.
Regards
Sakthivel
Hello, Elango.
Big thanks to you for really helpful post.
Best!
...maybe you have also a good SAPnote to implement for FIORI-Apps?
No, the current FIORI-Apps face also the problem regarding CRUD and latest Chrome...and there you can't change the index.hml
Got it!
1) You can do jQuery.sap.require("folderLocation.workaround"); in your app.js or component.js . But make sure you register the folderLocation using jQuery.sap.registerModulePath() or sap.ui.localResources()
2) Alternative for above one, copy the code of workaround and paste it anywhere before you do the oData crud operations.
This is one serious bug... Are they using private/deprecated apis?
The api isn't deprecated, but it's removed !
Hi,
this bug causes a long night yesterday 😡
Finally this morning I found this blog.
Thanks a lot!!!
My question is: Is there are fiix for SAPUI5 Odata lib or do I have to apply the code above in my program before each OData.create call?
Chers
Jens
I just applied the above workaround - works fine!
So simply put the above code in a file and include it in your index.html like Sakthivel said:
"So, till this is fixed you can create a new js file say, workaround.js and copy the code posted above and import it to your ui5 app index.html as
<script src="workaround.js"></script>"
This issue is occurring in latest chrome version 34. see Issue 347506 - chromium - DOM Level 2 API not available anymore (createAttributeNS, setAttributeNodeNS, ...) - An ope…
We need to watch this thread for further updates. also see this tweet on OpenUI5 account.
thanks for the workaround! Helped a lot!
Thanks for that! We are on a project, this hint saved a lot of time and trouble.
Hi Sakthivel,
I was almost loosing hair on this 😉 Thanks a lot for your post!!!!
Regards,
Tamas
Thank you sharing this with such great details. 🙂
Regards,
Rauf
Perfect! (Y)
Hi Shaktivel,
thanks for the great blog... really helpful....
This was starting to drive me crazy. But with this great blog I am able to spend some more time outside in the sun 🙂
thank u so much for sharing 🙂
Thanks a lot!!!!!!!!!!!!!!!!!!!!!
Another 3hrs saved here... There is no SAP Note about it yet!!!!
All you receive is the message: "undefined is not a function"!
var attribute =
dom.createAttributeNS.... tell me about it.
That's the good thing about this open stuff, they can remove things when they want. No.
Thanks for posting it.
Trick on github link?
Implementation of createAttributeNS and setAttributeNodeNS
Dear Sakthivel,
Thanks for your helpful post. I invested lot of time to get the Create working, should have searched for this error in SCN earlier.. 😛
Cheers,
Sumit
Sakthivel,
I am seeing this error in Firefox now. The above work around does not work. Any clue?
regards
Krishna
which version of firefox ?
I have Firefox 29.0.1
Please ignore. It seems to be a different issue, but very much browser dependent. I will update once I find it.
Are you sure it's the same issue, looking on bugzilla it looks like removing was discussed, but decided against??
https://bugzilla.mozilla.org/show_bug.cgi?id=977960
Regards,
Jason
Official solution propose by SAP:
"Dear customer,
there are two ways to solve the issue with Chrome 34 and Fiori Apps:
- either you use Chrome 35 (that was recently released)
- or you use the UI5 version 1.20.6 or higher."
Hi
Thank you for the post.
I am still getting this error even after implementing the solution. I am able to display the master page. The error appears when I click an item on the master page to view the detail page for the selected item
Regards
It seems the issue you face is not related to the one explained in the blog. I would suggest to open up question in the UI5 community on the same.