none
Wert einer Picklist RRS feed

  • Frage

  • Hallo.

    Ich kann den aktuellen Wert einer Picklist auslesen.

    Doch über welche Tabelle o.ä. bekomme ich den dazugehörigen Wert?
    Ich möchte somit den Indexer der Picklist direkt mit dem Wert verknüpfen und so direkt den richtigen Wert zu dem ausgelesenen Index

    erhalten.

    Weiß jemand Rat?
    Vielen Dank :)

    Freitag, 19. März 2010 09:47

Antworten

  • Hallo CRMMorpheus,

    sag das doch! :)

    Das geht so:

    public string getPropertyValue(Property myProperty)
            {
                String AttributType = myProperty.GetType().ToString();                 
                string strErmittelterWert = String.Empty;
                switch (AttributType)
                {
                    case "Microsoft.Crm.Sdk.StringProperty":
                        StringProperty myStrProp = (StringProperty)myProperty;
                        strErmittelterWert = myStrProp.Value;
                        break;
                    case "Microsoft.Crm.Sdk.CrmMoney":
                        CrmMoneyProperty myMoneyProp = (CrmMoneyProperty)myProperty;
                        strErmittelterWert = myMoneyProp.Value.IsNull ? "0" : String.Format("{0:0.00}", myMoneyProp.Value);
                        break;
                    case "Microsoft.Crm.Sdk.CrmNumber":
                        CrmNumberProperty myNumberProp = (CrmNumberProperty)myProperty;
                        strErmittelterWert = myNumberProp.Value.IsNull ? "0" : myNumberProp.Value.formattedvalue;
                        break;
                    case "Microsoft.Crm.Sdk.Picklist":
                        PicklistProperty myPicklistProp =(PicklistProperty)myProperty;
    
                        if (myPicklistProp.Value.IsNull)
                        {
                            strErmittelterWert = "";
                        }
                        else
                        {
    
                            strErmittelterWert = myPicklistProp.Name.ToString();
                        }
                        break;
    
                }
                return strErmittelterWert; 
            }

    Aufruf mit:

    foreach (Property DynProp in retrDynEntity.Properties)
                                            {
                                                string myPropErgebnis = getPropertyValue(DynProp);
    
                                            }

    Damit könntest du beginnen. Es sind nicht alle Propertys (Bspw. Lookup) in der Funktion aber zum verstehen sollte es reichen.

    Gruß Michael

    Freitag, 19. März 2010 13:19

Alle Antworten

  • Anscheinend ist es wie ich gerade sehe IMMER der Name, kann das jemand bestätigen?

    Vielen Dank
    Freitag, 19. März 2010 09:49
  • Hallo Morpheus,

    wie das geht steht im SDK.

    Per Javascript beispielsweise so:

    var oField = crmForm.all.SOME_PICKLIST_FIELD_ID;
    
    // Show how many options are available
    alert("Original length :"+ oField.Options.length);
    
    // Set the field to the first option by value
    oField.DataValue = 1;
    
    // Show the text for the first option
    alert(oField.SelectedText);
    
    

    Selected Text gibt also den angezeigten Text und DataValue die eigentlichte Value des Picklistenwerts.

    Gruß Micha

     

    Freitag, 19. März 2010 09:56
  • Ich arbeite mit C#, doch weiß ich nicht wie ich eine entität in eine Picklist konvertieren um an den Namen zu gelangen.

    Beispiel:

    case eType.picklist:
                                Picklist oPicklist = entity.Properties[strProperty];
                                return oPicklist.name;
                                break;

    Das funktioniert leider nicht.

    Kann mir jemand weiter helfen?

    Freitag, 19. März 2010 10:10
  • Ich muss nur wissen, wie ich unterscheiden kann,

    welcher Datentyp das jeweilige Property ist um jedes einzeln bearbeiten zu können.

    Hat niemand eine Idee?

    Freitag, 19. März 2010 12:53
  • Hallo CRMMorpheus,

    sag das doch! :)

    Das geht so:

    public string getPropertyValue(Property myProperty)
            {
                String AttributType = myProperty.GetType().ToString();                 
                string strErmittelterWert = String.Empty;
                switch (AttributType)
                {
                    case "Microsoft.Crm.Sdk.StringProperty":
                        StringProperty myStrProp = (StringProperty)myProperty;
                        strErmittelterWert = myStrProp.Value;
                        break;
                    case "Microsoft.Crm.Sdk.CrmMoney":
                        CrmMoneyProperty myMoneyProp = (CrmMoneyProperty)myProperty;
                        strErmittelterWert = myMoneyProp.Value.IsNull ? "0" : String.Format("{0:0.00}", myMoneyProp.Value);
                        break;
                    case "Microsoft.Crm.Sdk.CrmNumber":
                        CrmNumberProperty myNumberProp = (CrmNumberProperty)myProperty;
                        strErmittelterWert = myNumberProp.Value.IsNull ? "0" : myNumberProp.Value.formattedvalue;
                        break;
                    case "Microsoft.Crm.Sdk.Picklist":
                        PicklistProperty myPicklistProp =(PicklistProperty)myProperty;
    
                        if (myPicklistProp.Value.IsNull)
                        {
                            strErmittelterWert = "";
                        }
                        else
                        {
    
                            strErmittelterWert = myPicklistProp.Name.ToString();
                        }
                        break;
    
                }
                return strErmittelterWert; 
            }

    Aufruf mit:

    foreach (Property DynProp in retrDynEntity.Properties)
                                            {
                                                string myPropErgebnis = getPropertyValue(DynProp);
    
                                            }

    Damit könntest du beginnen. Es sind nicht alle Propertys (Bspw. Lookup) in der Funktion aber zum verstehen sollte es reichen.

    Gruß Michael

    Freitag, 19. März 2010 13:19
  • Genau das habe ich gesucht.

    Eine Frage noch dazu.

    Ich nutze keine foreach Schleife sondern übergebe der getPropertyValue funktion ein genaues Property.

    Doch wie isoliere ich ein spezielles Property aus meiner DynamicEntity?

    Bislang habe ich den Wert über entity.Properties[strProperty] (.toString()) abgefragt.

    Doch nun muss ich ja die vollständige Property übergeben und nicht nur den Wert.

    Wie isoliere ich also ein bestimmtes Property über eine Namensangabe wie z.B. "new_kundennr" ?

    Vielen Dank

     

     

    Freitag, 19. März 2010 14:09
  • public string getPropertyValue(Property myProperty)
            {
                String AttributType = myProperty.GetType().ToString();                 
                string strErmittelterWert = String.Empty;
                switch (AttributType)
                {
    
    
    in
    
    if (entity.Properties.Contains(strProperty))
                                                {
                                                    String AttributType = entity.Properties[strProperty].GetType().ToString();
    var stringWert =getPropertyValue(AttributType);
                                                    }
    
    
    
     
    public string getPropertyValue(String AttributType )
            {
                string strErmittelterWert = String.Empty;
                switch (AttributType)
                {
    

    Hallo,

    dann änder die Funktion und Frage die Property Type vorher ab und übergib nur diese? Siehe oben!

     

     

     

    Freitag, 19. März 2010 15:33
  • Hallo.

    Dennoch muss ich eine isolierte Property übergeben und ohne foreach weiß ich nicht, wie ich diese herauskristalisieren kann.

    Ich hatte überlegt eine Property-Variable durch den Indexwert der Entität zu füllen, doch die Konvertierung ist nicht möglich.

    Am besten zeige ich es einmal:

    public string getPropertyValue(DynamicEntity entity, string strProperty)
            {
                try
                {
                    if (entity.Properties.Contains(strProperty))
                    {
                        string strErmittelterWert = String.Empty;
                        string strAttributType = entity.Properties[strProperty].GetType().ToString();
                        Property property = (Property)entity.Properties[strProperty]; //Hier müsste ich irgendwie die einzelne Property aus der Entität herausbekommen. Nur wie? Diese Art der Konvertierung funktioniert leider nicht.
                        switch (strAttributType)
                        {
                            case "Microsoft.Crm.Sdk.StringProperty":
                                StringProperty myStrProp = (StringProperty)property;
                                strErmittelterWert = myStrProp.Value;
                                break;
                            case "Microsoft.Crm.Sdk.CrmMoney":
                                CrmMoneyProperty myMoneyProp = (CrmMoneyProperty)property;
                                strErmittelterWert = myMoneyProp.Value.IsNull ? "0" : String.Format("{0:0.00}", myMoneyProp.Value);
                                break;
                            case "Microsoft.Crm.Sdk.CrmNumber":
                                CrmNumberProperty myNumberProp = (CrmNumberProperty)property;
                                strErmittelterWert = myNumberProp.Value.IsNull ? "0" : myNumberProp.Value.formattedvalue;
                                break;
                            case "Microsoft.Crm.Sdk.Picklist":
                                PicklistProperty myPicklistProp = (PicklistProperty)property;
    
                                if (myPicklistProp.Value.IsNull)
                                {
                                    strErmittelterWert = "";
                                }
                                else
                                {
    
                                    strErmittelterWert = myPicklistProp.Name.ToString();
                                }
                                break;
                        }
                        return strErmittelterWert;
    Montag, 22. März 2010 09:34
  • Ist das nicht vielleicht garnicht möglich?
    Montag, 22. März 2010 14:47