web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting field object with JavaScript (alternative to document.all.fieldName )

(0) ShareShare
ReportReport
Posted on by 2,505

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

I have the same question (0)
  • Suggested answer
    #ManoVerse Profile Picture
    457 on at

    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.

  • justasd Profile Picture
    2,505 on at

    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.

  • #ManoVerse Profile Picture
    457 on at

    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!!

  • justasd Profile Picture
    2,505 on at

    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.

  • Verified answer
    #ManoVerse Profile Picture
    457 on at

    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";

    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);
    }
    }
    }

    Hope it  will help !!! 

  • justasd Profile Picture
    2,505 on at

    That was exactly what I was looking for, thank you

  • Community Member Profile Picture
    on at

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans