Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Plug-in that populates an Entity LOOKUP derived from another Entity

$
0
0

New to Plugin coding and need help figuring out how to derive a lookup fromone entity to another entity

Document Queue (vbs_crm_documentqueue)

  • Connect to Document XREF (vbs_vbs_crm_documentincidentxref)  via concatenation of Category – SubCategory
    • Primary Field - vbs_documenttypecd_subtypecd
  • Returning Below
    • Rule Department (LOOKUP TO Rule Department)
    • Rule Category (LOOKUP TO Rule Category)
    • Rule SubCategory (LOOKUP TO SubCategory)
      • Trying to Populate above Retrieved LOOKUP’s back into Document Queue which has the same Exact lookup fields
        • Rule Department (LOOKUP TO Rule Department)
        • Rule Category (LOOKUP TO Rule Category)
        • Rule SubCategory (LOOKUP TO SubCategory)

Service.Update highlighted below is ABORTING!!!

// Link to Entity VBS_CRM_DocumentIncidentXREF to retrieve Department, Category, SubCategory

                           try

                           {

                               ConditionExpression condition =newConditionExpression();

                               condition.AttributeName = "vbs_documenttypecd_subtypecd";

                               condition.Operator = ConditionOperator.Equal;

                               condition.Values.Add(lookupkey.ToString());

                               //create a column set.

                               ColumnSet columns =newColumnSet("vbs_documenttypecd_subtypecd" , "vbs_ruledepartmentid","vbs_rulecategoryid","vbs_rulesubcategoryid");

                               //Create query expression

                               QueryExpression query1 =newQueryExpression();

                               query1.ColumnSet = columns;

                               query1.EntityName = "vbs_vbs_crm_documentincidentxref";

                               query1.Criteria.AddCondition(condition);

                               EntityCollection result1 = service.RetrieveMultiple(query1);

                               int result1count = result1.Entities.Count;

                               

                               if (result1count == 1)

                               { 

                                   var r = result1.Entities[0];

           

                                   foreach(var c in r.Attributes)

                                   {

                                       if (r.Attributes.Contains("vbs_ruledepartmentid"))

                                       {

                                           Guid deptGUID = ((EntityReference)r.Attributes["vbs_ruledepartmentid"]).Id;

                                           docqueue.Attributes["vbs_ruledepartmentid"] = deptGUID;

                                       }

                                       if (r.Attributes.Contains("vbs_rulecategoryid"))

                                       {

                                           Guid catGUID = ((EntityReference)r.Attributes["vbs_rulecategoryid"]).Id;

                                           string cat = ((EntityReference)r.Attributes["vbs_rulecategoryid"]).Name;

                                           docqueue.Attributes["vbs_rulecategory"] = catGUID;

                                           docqueue.Attributes["vbs_category"] = cat;

                                       }

                                       if (r.Attributes.Contains("vbs_rulesubcategoryid"))

                                       {

                                           Guid subcatGUID = ((EntityReference)r.Attributes["vbs_rulesubcategoryid"]).Id;

                                           string subcat = ((EntityReference)r.Attributes["vbs_rulesubcategoryid"]).Name;

                                           docqueue.Attributes["vbs_rulesubcategoryid"] = subcatGUID;

                                           docqueue.Attributes["vbs_subcategory"] = subcat;

                                       }

            

      //                                service.Update(docqueue);

                                       

                                   }


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>