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)

Set Option set value into a text field

(0) ShareShare
ReportReport
Posted on by 277

Hi

I have been trying to set few fields when a lookup value is changed. The field values are being retrieved from the lookup Id. I was able to get text fields but I couldn't get value of option set. Thing is I need to set the option set value in a text field. Below the code I have been using.

function changespecifier() {

  
        var AccountLookup = Xrm.Page.getAttribute("new_specifier").getValue();

            SDK.REST.retrieveRecord(
                                    AccountLookup[0].id,
                                    "Account",
                                    null, null,
                                    function (account) {

                                        Xrm.Page.getAttribute("new_specifierstreet").setValue(account.Address1_Line1);
                                        Xrm.Page.getAttribute("new_specifiercity").setValue(account.Address1_City);
                                        Xrm.Page.getAttribute("new_specifierstate").setValue(account.Address1_StateOrProvince);
                                        Xrm.Page.getAttribute("new_specifierzip").setValue(account.Address1_PostalCode);

                                        if (account.new_strategic != null) {

                                        var AccountValue = Xrm.Page.getAttribute("new_strategic").getOption(account.new_strategic.Value);
                                        var AccountText = AccountValue.text;


                                        Xrm.Page.getAttribute("new_specifiersa").setValue(AccountText);

                                    }   

                                    },
                                    function (message) {
                                        alert("ERROR: " + message);
                                    }
                                    );
        

        Xrm.Page.data.entity.attributes.forEach(
function (attribute, index) {
    Xrm.Page.getAttribute(attribute.getName()).setSubmitMode("always");
});
    
}



new_strategic is a optionset on account entity while new_specifiersa is a text field on the current entity.

Please suggest.


 

*This post is locked for comments

I have the same question (0)
  • yosra.walid Profile Picture
    on at

    i did the same thing like this, this function display an option set in textField, 

    or listOptionset is the optionset, and textFiledchoosed is a text Field, 

    function suggestlist(listOptionSet, textFieldChoosed)
    
    {
    
    var optionsCategorie = Xrm.Page.getAttribute(listOptionSet).getOptions();
    
    var keyPressFcn = function (ext)
    
    {
    
    try
    
    {
    
    var userInput = Xrm.Page.getControl(textFieldChoosed).getValue();
    
    var userInputLowerCase = userInput.toLowerCase();
    
    var resultSet = {
    
    results: []
    
    };
    
    for (i = 0; i < optionsCategorie.length; i++)
    
    {
    
    if (userInputLowerCase === optionsCategorie[i].text.substring(0, userInputLowerCase.length).toLowerCase())
    
    {
    
    resultSet.results.push(
    
    {
    
    id: i,
    
    fields: [optionsCategorie[i].text]
    
    });
    
    }
    
    if (resultSet.results.length >= 28) break;
    
    }
    
    if (resultSet.results.length > 0)
    
    {
    
    ext.getEventSource().showAutoComplete(resultSet);
    
    }
    
    }
    
    catch (e)
    
    {
    
    // Handle any exceptions. In the sample code,
    
    // we are just displaying the exception, if any.
    
    console.log(e);
    
    }
    
    };
    
    Xrm.Page.getControl(textFieldChoosed).addOnKeyPress(keyPressFcn);
    
    }

    may this help you

    Best regards, 

    Yosra 

    my blog : https://moncrm.wordpress.com/

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You can't do this directly using SDK.Rest, you will need to get the Metadata for the field and that way get the label that you are looking for.

    See below forum with links on how to do that:

    community.dynamics.com/.../184177

    Saying that, it seems like you are on Dynamics CRM 2016. CRM 2016 introduced the webapi, which actually does allow you to do that. See the following link on different options and libraries that are available for the webapi:

    community.dynamics.com/.../webapi-library-comparison-in-dynamics-365

    Hope this helps.

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