Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Plugin not triggering

$
0
0

Hi Guys,

   I have created and registered a plugin, registered on Update and on a single field, but for whatever reason, it is not triggering, neither is it producing any form of trace log message. My plugin code is below:

if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity )
{
Entity conStaffRol = (Entity)context.InputParameters["Target"];

if (!(conStaffRol.LogicalName == "new_consultantstaffingrole" || conStaffRol.LogicalName == "new_nursestaffingrole")) { return; }

try
{

EntityReference staffRef = conStaffRol.GetAttributeValue<EntityReference>("gg_travelbooking");

if (context.MessageName == "update")
{
if (staffRef == null)
{
OptionSetValue conStaff = conStaffRol.GetAttributeValue<OptionSetValue>("new_plandaystatus");
//conStaff = new OptionSetValue(100000004);

if (conStaff == new OptionSetValue(100000004))
{
CreateTravelDetail(service, conStaffRol);
}

}

}

}catch(FaultException<OrganizationServiceFault> ex)
{
tracing.Trace("Unable to create travel Detail entity: ", ex.ToString());
}
catch(Exception e)
{
tracing.Trace("Error :" + e.ToString());
}


}
}

The travelDetail() method code called can be seen below:

ivate void CreateTravelDetail(IOrganizationService service, Entity entity)
        {
            Entity travelDetail = new Entity("gg_traveldetail");
  

            if(entity.LogicalName == "new_consultantstaffingrole")
            {
                EntityReference conEntityReference = entity.GetAttributeValue<EntityReference>("new_consultant");


                Entity consultant = service.Retrieve(conEntityReference.LogicalName, conEntityReference.Id, new ColumnSet(new string[] { "new_name" }));
                travelDetail["gg_name"] = entity.GetAttributeValue<string>("new_name");
                travelDetail["gg_travellersname"] = consultant.GetAttributeValue<string>("new_name");
                travelDetail["gg_consultantstaffingrole"] = entity.GetAttributeValue<OptionSetValue>("new_role");
                Guid travelId = service.Create(travelDetail);
                entity["gg_travelbooking"] = new EntityReference(travelDetail.LogicalName, travelId);

                service.Create(consultant);

            }

            if (entity.LogicalName == "new_nursestaffingrole")
            {
                EntityReference nurEntityReference = entity.GetAttributeValue<EntityReference>("new_nurse");
                Entity nurse = service.Retrieve(nurEntityReference.LogicalName, nurEntityReference.Id, new ColumnSet(new string[] { "new_name" }));

                travelDetail["gg_name"] = entity.GetAttributeValue<string>("new_name");
                travelDetail["gg_travellersname"] = nurse.GetAttributeValue<string>("new_name");
                travelDetail["gg_nursestaffingrole"] = entity.GetAttributeValue<OptionSetValue>("new_role");
                Guid travelId = service.Create(travelDetail);

                entity["gg_travelbooking"] = new EntityReference(travelDetail.LogicalName, travelId);
                service.Create(nurse);

            }
        }
    }


I have looked thoroughly in the forum and no oneseems to have had this same problem. I am only trying to populate and create another entity record if a field in the context is equal to a specific value. Thanks for the help


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images