Notifications
Announcements
No record found.
Is there other way to get field object other than document.all.fieldName?
Preferred way would be not to use document.all at all, but use fieldName.XXX instead
*This post is locked for comments
You should always use MS CRM supported JavaScript syntax's where ever you need it, any ways GUIDO Preite gave you a right way , you can use that syntax, document .all will be use if something will not be available by supported way.
Sorry, but I can't get it done.
I am using document.all.new_textbox inside a JavaScript function, and I'm passing it as a parameter. I'm also passing field name, which is "new_tesxtbox" as another parameter. What I want to do is reduce the parameters and leave just the field name, somehow it is not working.
Try to get varibale like this.
var variablename = Xrm.Page.getAttribute("fieldname").getValue();
If it is not working please provide bit details :
your JS code
Field type
Field name
Purpose for javascript :
Thanks!!
function loadPickList(optionSetFieldName, textBoxFieldName, optionSetFieldObj, textBoxFieldObj, divHeight, divBorderColor, divBackgroundColor) { if (optionSetFieldObj != null && textBoxFieldObj != null) { var optionSet = Xrm.Page.getAttribute(optionSetFieldName); optionSetFieldObj.style.display = "none";
var htmlDiv = document.createElement("div");
if (divBorderColor == null && divBackgroundColor == null) { divBorderColor = "#c6c6c6"; divBackgroundColor = "#ffffff"; } htmlDiv.setAttribute("style", "overflow-y:auto; height:" + divHeight + "px; border:1px " + divBorderColor + " solid; background-color:" + divBackgroundColor + ";"); optionSetFieldObj.parentNode.appendChild(htmlDiv);
for ( var i = 0; i < optionSet.getOptions().length - 1; i++) { var item = optionSet.getOptions()[i]; var htmlInput = document.createElement("input"); htmlInput.setAttribute("type", "checkbox"); htmlInput.setAttribute("style", "border:none; width:25px; align:left;vertical-align: middle;"); if (isChecked(item.text, textBoxFieldObj)) { htmlInput.setAttribute("checked", "checked"); } var htmlLabel = document.createElement("label"); htmlLabel.innerText = item.text; htmlLabel.setAttribute("style", "vertical-align: middle;"); var htmlBr = document.createElement("br");
optionSetFieldObj.nextSibling.appendChild(htmlInput); optionSetFieldObj.nextSibling.appendChild(htmlLabel); optionSetFieldObj.nextSibling.appendChild(htmlBr); } }}
Parameters example: "new_optionset", "new_textbox", document.all.new_optionset, document.all.new_textbox, "120"
This function transforms Option Set to Multi-Select Option Set, it's used in Form OnLoad
It works great, but I want to reduce the parameter number in the function.
I think like this way you can set your variable and ease your JS ..
function loadPickList(optionSetFieldName, textBoxFieldName,divHeight, divBorderColor, divBackgroundColor) { var optionSet = Xrm.Page.getAttribute(optionSetFieldName); optionSetFieldObj = document.all.item(optionSet.getName()); textBoxFieldObj = document.all.item(textBoxFieldName); if (optionSetFieldObj != null && textBoxFieldObj != null) { optionSetFieldObj.style.display = "none";
Hope it will help !!!
That was exactly what I was looking for, thank you
This is not working in CRM 2015.
Any idea?
thanks
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2