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)

Retrieve the stored option set value and display in Web Resource

(0) ShareShare
ReportReport
Posted on by 55

I have a Web resource which has a option set(1.Apple, 2.Orange, 3.Plum). When I select any of these options in Html web resource, I am able to save that in CRM option set field.

           

function fruitSelected(selected){
var selectedFruit = selected.options[selected.selectedIndex].text;
setOptionSetValue("fieldname", selectedFruit);
}

function setOptionSetValue(fieldname, selected) {
var options = Xrm.Page.getAttribute(fieldname).getOptions();
for (i = 0; i < options.length; i++) {
if (options[i].text == selected) {
Xrm.Page.getAttribute(fieldname).setValue(options[i].value);
}
}
}

At the same time I need to retrieve the saved option set from CRM and display it in Web resource, just to use it after refresh or save.
I tried 

var attribute = Xrm.Page.getAttribute('new_customerseverity').getoption(value);



This is not helping me to get the saved option set value. Can someone help me in this

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    To access CRM optionset from HTML , you should write

    window.parent.Xrm.Page.getAttribute('new_customerseverity').getoption(value);

  • Indhu Profile Picture
    55 on at

    Is 'new_customerseverity' is the fieldname, Something like    

                 window.parent.Xrm.Page.getAttribute('fieldname').getoption(value);

  • Indhu Profile Picture
    55 on at

    @Goutam Das   can you please reply for this

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    yes your understanding is correct.

  • Suggested answer
    Jharana Baliyar Singh Profile Picture
    2,667 on at

    Hi,

    Just check with below url hope it will help you .

    community.dynamics.com/.../237163

    So you trying to do something like getting all the option set values from crm & setting those values to your field in crm record once you save the record.But before this makes sure you should have all these options available for crm option set field.

    If you are using html page then instead of Xrm.Page.getAttribute("new_customerseverity"); use window.parent.Xrm.Page.getAttribute("new_customerseverity").getOptions();

    Thanks,

    Jharana

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Indhu,

    Try with this  -

        function fruitSelected(selected){
            var selectedFruit = selected.options[selected.selectedIndex].text;
            setOptionSetValue("fieldname", selectedFruit);
        }
    
        function setOptionSetValue(fieldname, selected) {
            var options = window.parent.Xrm.Page.getAttribute(fieldname).getOptions();
            for (i = 0; i < options.length; i++) {
                if (options[i].text == selected) {
                    window.parent.Xrm.Page.getAttribute(fieldname).setValue(options[i].value);
                }
            }
        }


  • Indhu Profile Picture
    55 on at

    This recent one which you have given is for taking the selected option from web resource and storing in CRM field. I can achieve this. But I need to take it back from CRM field and place it in web resource.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    If my understanding is not wrong , similar way you need to retrieve CRM  field using window.parent.Xrm and get selected value of CRM field and the set the HTML dropdown control.

  • shivaram Profile Picture
    3,315 on at

    Hi Indu,

    if you want to get saved option set value, then you can use

    var attribute = Xrm.Page.getAttribute('new_customerseverity').getValue();

    or else if you want to get all options in the selected field then you need to use

    Xrm.Page.getAttribute("new_customerseverity").getOptions()

    Hope it helps.

    Thanks,

    Shivaram.

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