locked
How to catch unassigned value in a Picklist in CRM2011 RRS feed

  • Question

  • Hi all,

    i have a picklist with payment methods....the default value for it is unassigned.

    i am using below code to catch if no option is selected but it throws an error:

    PicklistValue=Xrm.Page.getAttribute("picklistname").getSelectedOption().value;
         if(PicklistValue==866130000 && PicklistValue!=null)
         {

               here there is some code

          }

    i want if this particular value is selected then only the logic will work otherwise do nothing.so how i can catch that unassigned value.

    This is written on Onsave event in CRM2011

    Any help will be highly appreciated.

    Tuesday, May 24, 2011 11:33 AM

Answers

  • You are using the variable sPaymentModePickList in this function before you declare the variable.

    Add:

    ...

    var sPaymentModePickList = Xrm.Page.data.entity.attributes.get("new_yourpicklistname");

    if(sPaymentModePickList.getValue() != null) {

    ...

    Also, keep in mind that option set values are passed as a String data type (even though the representation is an integer. You'll need to use parseInt to change the type to an Int, or just put quotes around the value:

    if(parseInt(iPaymentModeValue, 10) == 866130000 && iPayementModeValue != null)

    OR

    if(iPaymentModeValue == "866130000" && iPayementModeValue != null)

    HTH


    --Dodd
    Tuesday, June 28, 2011 5:19 PM

All replies

  • You can use the following to test if no option is selected:

    if (Xrm.Page.getAttribute("picklistname").getValue == null)


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Tuesday, May 24, 2011 1:43 PM
    Moderator
  • Thanks david,

    i used this but like below :

    function Donation_CheckCreditCard(sPayementModePicklist,sCardTypePickList)
    {

            if(Xrm.Page.getAttribute(sPayementModePickList).getValue!=null)

            {
           
                iPaymentModeValue=Xrm.Page.getAttribute(sPayementModePickList).getSelectedOption().value;
                if(iPaymentModeValue==866130000 && iPayementModeValue!=null)
                {
                  iCardTypeValue=Xrm.Page.getAttribute(sCardTypePickList).getSelectedOption().value;
                  switch(iCardTypeValue)
                 {
                          

                           some logic;

                  }

            }

    }

     

    but it gives error on onsave if i keep the paymentmode picklist null.

    it gives

    ---------------------------
    Message from webpage
    ---------------------------
    There was an error with this field's customized event.

    Field:crmForm

    Event:onsave

    Error:'Xrm.Page.getAttribute(...).getValue().0' is null or not an object
    ---------------------------
    OK  
    ---------------------------

    why its not catching that default unassigned value i dont know...?

     

           

    Wednesday, May 25, 2011 5:00 AM
  • I am running into a similar situation with an OnLoad event.

    One way I solved this way by setting the picklist to a default value upon creation of a new record. This works for all new records but for the old records that I had before I created the picklist, I had to go in and update.

    It seems that no matter how I write my code, I get an error if the picklist is null.

    Tuesday, June 28, 2011 3:21 PM
  • You are using the variable sPaymentModePickList in this function before you declare the variable.

    Add:

    ...

    var sPaymentModePickList = Xrm.Page.data.entity.attributes.get("new_yourpicklistname");

    if(sPaymentModePickList.getValue() != null) {

    ...

    Also, keep in mind that option set values are passed as a String data type (even though the representation is an integer. You'll need to use parseInt to change the type to an Int, or just put quotes around the value:

    if(parseInt(iPaymentModeValue, 10) == 866130000 && iPayementModeValue != null)

    OR

    if(iPaymentModeValue == "866130000" && iPayementModeValue != null)

    HTH


    --Dodd
    Tuesday, June 28, 2011 5:19 PM
  • MDodd-

    "Also, keep in mind that option set values are passed as a String data type (even though the representation is an integer. You'll need to use parseInt to change the type to an Int, or just put quotes around the value:"

    Very nice! Solved my issue!

     

    Tuesday, June 28, 2011 6:11 PM
  • Excellent.


    --Dodd
    Tuesday, June 28, 2011 7:05 PM