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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Form Javascript: getoptiontext to field (not working)

(0) ShareShare
ReportReport
Posted on by

Hi,

I have very little knowledge of javascript, but what's wrong with the following code which is active on field change:

function setAdressCountryFromOptionSet()
{
var CountryFieldText = Xrm.Page.getAttribute("x_countrylistglobal").getText();
Xrm.Page.getAttribute("address1_country").setValue(CountryFieldText);
}

x_countrylistglobal = option set field where I'm trying to get the text from, not the value, whenever something is selected (I guess onChange).

Any help greatly appreciated!

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Form Javascript: getoptiontext to field (not working)

    Pointed me in the right direction, the name was correct but it seems the actual field needed to be present on the form, so I added it to a hidden tab and all started working perfectly!

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Form Javascript: getoptiontext to field (not working)

    Hi

    From the error message your are getting, we can infer that Xrm.Page.getAttribute("x_countrylistglobal") is not able to get the reference of the attribute on form.

    Can you please check x_countrylistglobal is the correct name of the attribute.

  • Community Member Profile Picture
    on at
    RE: Form Javascript: getoptiontext to field (not working)

    TypeError: Cannot read property 'getText' of null

       at setAdressCountryFromOptionSet (x.x.dynamics.com/.../itw_SetCountryFromOptionSet)

       at eval (eval at RunHandlerInternal (x.x.dynamics.com/.../ClientApiWrapper.aspx), <anonymous>:1:1)

       at RunHandlerInternal (x.x.dynamics.com/.../ClientApiWrapper.aspx)

       at RunHandlers (x.x.dynamics.com/.../ClientApiWrapper.aspx)

       at ExecuteHandler (x.x.dynamics.com/.../ClientApiWrapper.aspx)

       at Mscrm.TurboForm.Control.CustomScriptsManager.$C7_1 (x.x.dynamics.com/.../JsProvider.ashx;ids=1223231347-405283869:8911:91)

       at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandler (x.x.dynamics.com/.../JsProvider.ashx;ids=1223231347-405283869:8857:18)

       at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandlerByDescriptor (x.x.dynamics.com/.../JsProvider.ashx;ids=1223231347-405283869:8888:18)

       at x.x.dynamics.com/.../JsProvider.ashx;ids=1223231347-405283869:8896:19

       at x.x.dynamics.com/.../global.ashx

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Form Javascript: getoptiontext to field (not working)

    Your code is correct. What error are you getting? It looks like some other line in your code is not running.

    Also you are setting value in address1_country which is a composite address field. You have to click on Address field to reflect the change in value

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans