locked
dropdown list value from Odata RRS feed

  • Question

  • Hi,

    I want to get dropdown list value from Odata.  Please find script below and kindly help me to find solution. what I can give to get value of dropdown list in retrieved.results[0].new_Department.  I mean 1,2,3  etc depends on option set

    var clientid = Xrm.Page.getAttribute("new_initiated").getValue()[0].id;
    var context = Xrm.Page.context;
    serverUrl = context.getServerUrl(); 
    var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
    var retrieveResult = new XMLHttpRequest();
    retrieveResult.open("GET", ODataPath + "/SystemUserSet?$select=new_Department&$filter=SystemUserId eq guid'" + clientid + "'", false);
    retrieveResult.setRequestHeader("Accept", "application/json");
    retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    retrieveResult.send();
    if (retrieveResult.readyState == 4 )
       {
          if (retrieveResult.status == 200)
                {
                 var retrieved = JSON.parse(retrieveResult.responseText).d;
                 alert(retrieved.results[0].new_Department);
                 Xrm.Page.getAttribute("new_department").setValue(retrieved.results[0].new_Department);
         }
        }


    pnoushu@hotmail.com

    Monday, February 13, 2017 2:12 PM

All replies

    1. retrieved.results[0].new_Department will only bring back a number.
    2. What is the current returned results?
    3. are you using CRMRESTBUILDER? If so you should get an option like "retrieved.results[0].new_Department@OData.Community.Display.V1.FormattedValue". This will give you the dropdown content not a number.
    Monday, February 13, 2017 4:07 PM
  • retrieved.results[0].new_Department.Value

    Hope this helps

    Thanks

    • Proposed as answer by Suresh Sorde Tuesday, February 14, 2017 7:16 AM
    Tuesday, February 14, 2017 7:16 AM
  • Hi Suresh,

    Thanks for your solution. It is working.

    I have one more query and did not get proper solution for this.  kindly help me to get solution. I am using event.returnValue=false; command in in my scripts but for upgrading I want to change the scripts.  I changed scripts but it giving error and not working properly. Please find new scripts and error.

    function new_committed_onchange()
    {

    if (Xrm.Page.getAttribute("opportunityratingcode").getValue() != '200000')
    {
       alert("Please change stage to Forecast before entering committed date");
       Xrm.Page.getAttribute("new_committed").setValue(false);
        event.returnValue=false;
    }

    }

    -----------------------------

    New scripts - I enable pass execution context as first parameter of new_committed_onchange function.

    function new_committed_onchange(executionObj)
    {

    if (Xrm.Page.getAttribute("opportunityratingcode").getValue() != '200000')
    {
       alert("Please change stage to Forecast before entering committed date");
       Xrm.Page.getAttribute("new_committed").setValue(false);
        executionObj.getEventArgs().preventDefault();
    }

    }


    pnoushu@hotmail.com

    Tuesday, February 14, 2017 7:42 AM
  • You are using function new_committed_onchange and in handler property image function name is Form_onsave. ? ??

    Use correct function name.

    Also keep note that -

    getEventArgs will returns null for any event other than the Save event.


    At what event you are getting this error means onload or onSave?

    Have you register your function on save event? If it is on another event also the you need to also tick the check box for 'Pass execution context as first parameter'.

    also check context.

    if (Xrm.Page.getAttribute("opportunityratingcode").getValue() != '200000')

    {

    (executionObj != null && executionObj.getEventArgs() != null)
    {var vSavemode = executionObj.getEventArgs().getSaveMode();
    if(vSavemode == 1 || vSavemode ==2)

       alert("Please change stage to Forecast before entering committed date");
       Xrm.Page.getAttribute("new_committed").setValue(false);
        executionObj.getEventArgs().preventDefault();

        }

    }
    }





    • Edited by Suresh Sorde Tuesday, February 14, 2017 12:27 PM
    • Proposed as answer by Suresh Sorde Tuesday, February 14, 2017 12:56 PM
    Tuesday, February 14, 2017 10:20 AM
  • Hi,

    The error I am getting when save.  As you suggested getEventArgs will returns null for any event other than the Save event.   Can we use getEventArgs this commenet for filed change events. what is alternate option other than  getEventArgs.

    I enabled the option enable pass execution context as first parameter of new_committed_onchange function as mentioned in my previous mail on save event.  I will update your code and inform the result.

    Secondly I have another issue.  I want to update the default price list when enter new opportunity.  I am using only one price list so I am create java script as mentioned below but is not working.  it is updating the price level but not allowing to save the opportunity.  Please find the java script and screen-shots.

    var lookupData = new Array();

    var lookupItem= new Object();

    lookupItem.id = '{FAEE3026-FA58-DF11-A877-001F29C516D6}';

     lookupItem.typename = 'pricelevelid';

     lookupItem.name = 'GENERAL';

    lookupData[0] = lookupItem;
     Xrm.Page.getAttribute("pricelevelid").setValue(lookupData);

    update PRICE LEVEL  as shown in below screen

    but it should be as shown below screen when select from lookup normally


    pnoushu@hotmail.com

    Wednesday, February 15, 2017 8:34 AM
  •  lookupItem.typename = 'pricelevelid';

    replace with

     lookupItem.typename = 'pricelevel';


    • Proposed as answer by Suresh Sorde Wednesday, February 15, 2017 9:39 AM
    Wednesday, February 15, 2017 9:39 AM