Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Set Option set value into a text field

Posted on by 275

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

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Set Option set value into a text field

    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.

  • yosra.walid Profile Picture
    yosra.walid on at
    RE: Set Option set value into a text field

    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/

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans