Answered by:
Data Retrieve from one field and display in another

Question
-
Dear All,
I am trying to write a plugin for crm 2011, in which I am trying to poulate a field from data entered in another field.
to be precise I am dealing with a case entity and description is the attribute I want to pull data out of and display in some other custom fields.
Please point me in right direction.
thank you.
Wednesday, August 17, 2011 12:00 PM
Answers
-
Hi,
You can use JScript or Workflow to do the same functionality, you can place the second field on Case form and can hide it so on Description field OnChange event can copy the Description field value into the new field or can create a workflow that will trigger on New record and On Description attribute value change, can add a Updaet Record step and set the second field value with Description field.
If using plugin then you can do it like this:
if (jj_CaseEntity.Contains("description"))
{
if (jj_CaseEntity.Contains("jj_custom_field"))
{
jj_CaseEntity["jj_custom_field"] = jj_CaseEntity["description"];
}
else
{
jj_CaseEntity.Attributes.Add("jj_custom_field",jj_CaseEntity["description"]);
}
}
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Proposed as answer by Gonzalo Ruiz RModerator Wednesday, August 17, 2011 12:32 PM
- Marked as answer by CRMizer Wednesday, August 17, 2011 1:29 PM
Wednesday, August 17, 2011 12:25 PM -
Hi,
Make sure that your code is plugin step is registered on Pre-Operation stage and the new_site field value will be only added if match.Success will return true. You can check by throwing exception on else if the regular expression matching failed i.e.
if (match.Success)
{
string key = match.Groups[1].Value;
entity.Attributes.Add("new_site", key);
}else
{
throw new InvalidPluginExecutionException ("Regular expression failed to match");
}
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
- Edited by Jehanzeb.Javeed Wednesday, August 17, 2011 4:07 PM Exception Details Added
- Marked as answer by CRMizer Thursday, August 18, 2011 8:38 AM
Wednesday, August 17, 2011 4:05 PM
All replies
-
Hi,
You can use JScript or Workflow to do the same functionality, you can place the second field on Case form and can hide it so on Description field OnChange event can copy the Description field value into the new field or can create a workflow that will trigger on New record and On Description attribute value change, can add a Updaet Record step and set the second field value with Description field.
If using plugin then you can do it like this:
if (jj_CaseEntity.Contains("description"))
{
if (jj_CaseEntity.Contains("jj_custom_field"))
{
jj_CaseEntity["jj_custom_field"] = jj_CaseEntity["description"];
}
else
{
jj_CaseEntity.Attributes.Add("jj_custom_field",jj_CaseEntity["description"]);
}
}
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Proposed as answer by Gonzalo Ruiz RModerator Wednesday, August 17, 2011 12:32 PM
- Marked as answer by CRMizer Wednesday, August 17, 2011 1:29 PM
Wednesday, August 17, 2011 12:25 PM -
Dear Javeed,
Thank you for your help. That is working magic.
Wednesday, August 17, 2011 1:29 PM -
Dear Javeed,
I wonder if you could help me further on. I am trying to update a custom field with the help of using Regex method. the code snippet is as follows. I would be thankful if you could throw some light on this.
The description field will typically have data like this " {|CLIENT|}NVISION {|CALLTYPE|}SUPPORT {|SITE|}Blackpool {|DESCRIPTION|}Backup Check - Microsoft NT Backup failed on device BSSRV01. Additional information : One or more jobs failed Error detail : Backup Check - Microsoft NT Backup One or more jobs failed"
if (entity.Contains("new_site"))
{
entity["new_site"] = entity["description"];
}
else
{string input = entity["description"].ToString();
Match match = Regex.Match(input, @"SITE\|\}(.*)\s$");
if (match.Success)
{
string key = match.Groups[1].Value;
entity.Attributes.Add("new_site", key);
}Wednesday, August 17, 2011 3:59 PM -
FYI : I am not able to get the desired out put and the new_site field is not populated with any thing after save.Wednesday, August 17, 2011 4:00 PM
-
Hi,
Make sure that your code is plugin step is registered on Pre-Operation stage and the new_site field value will be only added if match.Success will return true. You can check by throwing exception on else if the regular expression matching failed i.e.
if (match.Success)
{
string key = match.Groups[1].Value;
entity.Attributes.Add("new_site", key);
}else
{
throw new InvalidPluginExecutionException ("Regular expression failed to match");
}
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
- Edited by Jehanzeb.Javeed Wednesday, August 17, 2011 4:07 PM Exception Details Added
- Marked as answer by CRMizer Thursday, August 18, 2011 8:38 AM
Wednesday, August 17, 2011 4:05 PM