Answered by:
Properties modified in a Plugin

Question
-
Hello all,
is it possible to obtained what attributes were modified in a plugin execution ?
Thanks
YojanSaturday, January 30, 2010 5:00 PM
Answers
-
ohhh yeah soory(i forgot :)), you will hae all the properties in target.Properties(and not context.Inputparameter), which are modified.
you can apply a foreach loop something like this.
foreach(Property prop in target.Properties)
{
if (prop is CrmFloat)
strValue = ((CrmFloat)prop).Value.ToString();
else if (prop is CrmDateTime)
strValue = ((CrmDateTime)prop).Value;
else if (prop is CrmNumber)
strValue = ((CrmNumber)prop).Value.ToString();
else if (prop is Key)
strValue = ((Key)prop).Value.ToString();
else if (prop is Lookup)
strValue = ((Lookup)prop).Value.ToString();
else if (prop is Owner)
strValue = ((Owner)prop).Value.ToString();
else if (prop is Picklist)
strValue = ((Picklist)prop).name;
else if (prop is CrmBoolean)
strValue = ((CrmBoolean)prop).Value.ToString().ToLower();
else if (prop is Status)
strValue = ((Status)prop).name;
else if (prop is String)
strValue = ((String)prop);
else if (prop is UniqueIdentifier)
strValue = ((UniqueIdentifier)prop).Value.ToString();
}- Proposed as answer by Muhammad Ali Khan Saturday, January 30, 2010 5:28 PM
- Marked as answer by Yojan Saturday, January 30, 2010 8:59 PM
Saturday, January 30, 2010 5:25 PM
All replies
-
If it is an update event, you have "InputParameter", collection in the IPluginExecutionContext object . it will only have the property that are modified.
InputParameters Gets the parameters of the request message which triggered the event. Saturday, January 30, 2010 5:11 PM -
sure,
I have always used
DynamicEntity target = (DynamicEntity)context.InputParameters[ParameterName.Target];
but that gives me the entity. an later to access an specific property it is used
((Picklist)target.Properties["new_registrationrequeststatus"]).Value
But is there any way to find what attributes are included in InputParameters, as well their types.
All of this because I would like to check all string properties before saving operation and making a correction to that one
Whatever clue is welcome.
YojanSaturday, January 30, 2010 5:15 PM -
ohhh yeah soory(i forgot :)), you will hae all the properties in target.Properties(and not context.Inputparameter), which are modified.
you can apply a foreach loop something like this.
foreach(Property prop in target.Properties)
{
if (prop is CrmFloat)
strValue = ((CrmFloat)prop).Value.ToString();
else if (prop is CrmDateTime)
strValue = ((CrmDateTime)prop).Value;
else if (prop is CrmNumber)
strValue = ((CrmNumber)prop).Value.ToString();
else if (prop is Key)
strValue = ((Key)prop).Value.ToString();
else if (prop is Lookup)
strValue = ((Lookup)prop).Value.ToString();
else if (prop is Owner)
strValue = ((Owner)prop).Value.ToString();
else if (prop is Picklist)
strValue = ((Picklist)prop).name;
else if (prop is CrmBoolean)
strValue = ((CrmBoolean)prop).Value.ToString().ToLower();
else if (prop is Status)
strValue = ((Status)prop).name;
else if (prop is String)
strValue = ((String)prop);
else if (prop is UniqueIdentifier)
strValue = ((UniqueIdentifier)prop).Value.ToString();
}- Proposed as answer by Muhammad Ali Khan Saturday, January 30, 2010 5:28 PM
- Marked as answer by Yojan Saturday, January 30, 2010 8:59 PM
Saturday, January 30, 2010 5:25 PM -
Thanks .. that certanly took out the problem
YojanSaturday, January 30, 2010 8:58 PM