locked
lookup in crm plugin RRS feed

  • Question

  • Crm 2013 on premises

    I have a custom entity that has a lookup field (new_licence ) to accounts. I am trying to write a plugin to export data when a record is created for a legacy system

    how can i get the 'txt value' of 'new_licence' inside the plugin

    This plugin is being written in vb.net


    Dont ask me .. i dont know

    Monday, November 25, 2013 2:32 PM

Answers

  • Hi Vikram,Thank you for your help.  I have tried the following code but when testing the plugin i get a Microsoft.Xrm.Sdk.InvalidPluginExecutionException' was thrown error

                    Dim strLicence As String = String.Empty
                        If entity.Contains("new_licence") Then
                            Dim Account As EntityReference = CType(entity.Attributes("new_licence"), EntityReference)
                            strLicence = Account.Name
                        End If
                    Throw New InvalidPluginExecutionException(strLicence)
    
    The pluging is being executed on a record create on a custom entity 'new_OAccounts' . the new_licence field is a lookup to accounts.  hope that makes sense. Also whilst you are being so kind, I have  several 'two option ' fields that i will need to get the value from.


    Dont ask me .. i dont know

    • Marked as answer by Pete Newman Thursday, December 12, 2013 3:32 PM
    Monday, November 25, 2013 3:10 PM

All replies

  • string Name=((EntityReference)entity.Attributes["new_licence"]).Name;

    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog


    • Edited by _Vikram Monday, November 25, 2013 2:41 PM
    Monday, November 25, 2013 2:39 PM
  • Hi Vikram,

    Forgive my ignorance, but what would that be in vb.net, and would EntityReference be accounts ?


    Dont ask me .. i dont know

    Monday, November 25, 2013 2:44 PM
  • Try this :

    Dim Account As EntityReference = CType(entity.Attributes("new_licence"), EntityReference)

    Dim Name As  String =Account.Name


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    Monday, November 25, 2013 2:54 PM
  • Hi Vikram,Thank you for your help.  I have tried the following code but when testing the plugin i get a Microsoft.Xrm.Sdk.InvalidPluginExecutionException' was thrown error

                    Dim strLicence As String = String.Empty
                        If entity.Contains("new_licence") Then
                            Dim Account As EntityReference = CType(entity.Attributes("new_licence"), EntityReference)
                            strLicence = Account.Name
                        End If
                    Throw New InvalidPluginExecutionException(strLicence)
    
    The pluging is being executed on a record create on a custom entity 'new_OAccounts' . the new_licence field is a lookup to accounts.  hope that makes sense. Also whilst you are being so kind, I have  several 'two option ' fields that i will need to get the value from.


    Dont ask me .. i dont know

    • Marked as answer by Pete Newman Thursday, December 12, 2013 3:32 PM
    Monday, November 25, 2013 3:10 PM
  • Please try to debug your plugin and see which line of code failing.

    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    Monday, November 25, 2013 3:24 PM