if conditions on website field through plugin RRS feed

  • Question

  • I want to check the following conditions through plugin :

    1.if website field = null then insert google.com into website field

    2.if website field = "google.com" then change it to yahoo.com

      if (entity.LogicalName == "account")
                    string web1 = "google.com";
                    if (entity.Attributes["websiteurl"].Equals(web1)  )
                        string web2 = "yahoo.com";
                        entity.Attributes["websiteurl"] = web2.ToString();
                    if (entity.Attributes["websiteurl"].Equals(null))
                        string web = "google.com";
                        entity.Attributes["websiteurl"] = web.ToString();

    I have been using this code but its not working...

    Friday, May 9, 2014 10:44 AM

All replies

  • Hi,

    Your code will give error if the website url field value is null because you are checking below line as the attribute is null, so null.equals will fail for the below line

    if (entity.Attributes["websiteurl"].Equals(web1)  )

    Try with the below code it will work when the record is crating.

    If you want update the Web site Url field on record update also , you need to fetch the account entity website attribute field value
    Because if you did not modify the field value at the time record updation , then you can not get field value direct from  entity.

    if (entity.Attributes.Contains("websiteurl"))
                          if (entity.Attributes["websiteurl"].ToString().ToLower() == "google.com")
                              entity.Attributes["websiteurl"] = "yahoo.com";
                            entity.Attributes["websiteurl"] = "google.com";



    • Proposed as answer by PriyaSwain Friday, May 9, 2014 11:46 AM
    Friday, May 9, 2014 11:45 AM