diff --git a/msdyncrmWorkflowTools/.vs/msdyncrmWorkflowTools/v15/.suo b/msdyncrmWorkflowTools/.vs/msdyncrmWorkflowTools/v15/.suo index 3e10b34..228274a 100644 Binary files a/msdyncrmWorkflowTools/.vs/msdyncrmWorkflowTools/v15/.suo and b/msdyncrmWorkflowTools/.vs/msdyncrmWorkflowTools/v15/.suo differ diff --git a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/AssociateEntity.cs b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/AssociateEntity.cs index 8e8c3ab..0e71f10 100644 --- a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/AssociateEntity.cs +++ b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/AssociateEntity.cs @@ -34,6 +34,9 @@ public class AssociateEntity : CodeActivity [Input("Record URL")] [ReferenceTarget("")] public InArgument RecordURL { get; set; } + + + #endregion protected override void Execute(CodeActivityContext executionContext) diff --git a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/CalculateRollupField.cs b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/CalculateRollupField.cs index 12d506a..79938cb 100644 --- a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/CalculateRollupField.cs +++ b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/CalculateRollupField.cs @@ -42,13 +42,17 @@ protected override void Execute(CodeActivityContext executionContext) #region "Read Parameters" String _FieldName = this.FieldName.Get(executionContext); + objCommon.tracingService.Trace("_FieldName=" + _FieldName); String _ParentRecordURL = this.ParentRecordURL.Get(executionContext); + if (_ParentRecordURL == null || _ParentRecordURL == "") { return; } + objCommon.tracingService.Trace("_ParentRecordURL=" + _ParentRecordURL); string[] urlParts = _ParentRecordURL.Split("?".ToArray()); string[] urlParams=urlParts[1].Split("&".ToCharArray()); + string ParentObjectTypeCode=urlParams[0].Replace("etc=",""); string ParentId = urlParams[1].Replace("id=", ""); objCommon.tracingService.Trace("ParentObjectTypeCode=" + ParentObjectTypeCode + "--ParentId=" + ParentId); diff --git a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/CreateTeam.cs b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/CreateTeam.cs new file mode 100644 index 0000000..7d8e9d1 --- /dev/null +++ b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/CreateTeam.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Activities; +using Microsoft.Xrm.Sdk; +using Microsoft.Xrm.Sdk.Workflow; +using Microsoft.Crm.Sdk.Messages; +using Microsoft.Xrm.Sdk.Metadata.Query; +using Microsoft.Xrm.Sdk.Query; +using Microsoft.Xrm.Sdk.Messages; +using Microsoft.Xrm.Sdk.Metadata; +using msdyncrmWorkflowTools; +using System.ServiceModel; + + +namespace msdyncrmWorkflowTools +{ + + public class CreateTeam : CodeActivity + { + [RequiredArgument] + [Input("Team Name")] + [Default("")] + public InArgument TeamName{ get; set; } + + + [RequiredArgument] + [Input("Team Type")] + public InArgument TeamType{ get; set; } + + [RequiredArgument] + [Input("Administrator")] + [ReferenceTarget("systemuser")] + public InArgument Administrator { get; set; } + + [RequiredArgument] + [Input("Business Unit")] + [ReferenceTarget("businessunit")] + public InArgument BusinessUnit { get; set; } + + + [Output("Team")] + [ReferenceTarget("team")] + public OutArgument createdTeam { get; set; } + + protected override void Execute(CodeActivityContext executionContext) + { + + #region "Load CRM Service from context" + + Common objCommon = new Common(executionContext); + objCommon.tracingService.Trace("Load CRM Service from context --- OK"); + #endregion + + #region "Read Parameters" + String _teamName = this.TeamName.Get(executionContext); + int _teamType = this.TeamType.Get(executionContext); + EntityReference _administrator= this.Administrator.Get(executionContext); + EntityReference _businessUnit= this.BusinessUnit.Get(executionContext); + + objCommon.tracingService.Trace("_teamName=" + _teamName ); + #endregion + + + #region "Associate Execution" + + try + { + msdyncrmWorkflowTools_Class commonClass = new msdyncrmWorkflowTools_Class(objCommon.service); + Guid createdTeamId= commonClass.CreateTeam(_teamName,_teamType, _administrator, _businessUnit); + this.createdTeam.Set(executionContext, new EntityReference("team", createdTeamId)); + + } + catch (FaultException ex) + { + objCommon.tracingService.Trace("Error : {0} - {1}", ex.Message, ex.StackTrace); + //throw ex; + // if (ex.Detail.ErrorCode != 2147220937)//ignore if the error is a duplicate insert + //{ + // throw ex; + //} + } + catch (System.Exception ex) + { + objCommon.tracingService.Trace("Error : {0} - {1}", ex.Message, ex.StackTrace); + //throw ex; + } + #endregion + + } + } +} diff --git a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/GetOptionSetValue.cs b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/GetOptionSetValue.cs new file mode 100644 index 0000000..6fdaf9f --- /dev/null +++ b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/GetOptionSetValue.cs @@ -0,0 +1,84 @@ +using Microsoft.Crm.Sdk.Messages; +using Microsoft.Xrm.Sdk; +using Microsoft.Xrm.Sdk.Query; +using Microsoft.Xrm.Sdk.Workflow; +using System; +using System.Activities; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + + +namespace msdyncrmWorkflowTools +{ + public class GetOptionSetValue : CodeActivity + { + [RequiredArgument] + [Input("Source Record URL")] + public InArgument SourceRecordUrl { get; set; } + + [RequiredArgument] + [Input("Attribute Name")] + public InArgument AttributeName { get; set; } + + [Output("Value")] + public OutArgument SelectedValue { get; set; } + + protected override void Execute(CodeActivityContext executionContext) + { + Common objCommon = new Common(executionContext); + objCommon.tracingService.Trace("Load CRM Service from context --- OK"); + + EntityReference sourceEntityReference = GetSourceEntityReference(objCommon.tracingService, executionContext, objCommon.service); + string attributeName = GetAttributeName(objCommon.tracingService, executionContext); + + int value= GetValue(sourceEntityReference, attributeName, objCommon.tracingService, objCommon.service); + + this.SelectedValue.Set(executionContext, value); + } + + private EntityReference GetSourceEntityReference(ITracingService tracingService, CodeActivityContext executionContext, IOrganizationService organizationService) + { + string sourceRecordUrl = SourceRecordUrl.Get(executionContext) ?? throw new ArgumentNullException("Source URL is empty"); + tracingService.Trace("Source Record URL:'{0}'", sourceRecordUrl); + return new DynamicUrlParser(sourceRecordUrl).ToEntityReference(organizationService); + } + + + private string GetAttributeName(ITracingService tracingService, CodeActivityContext executionContext) + { + string attributeName = AttributeName.Get(executionContext) ?? throw new ArgumentNullException("Attribute Name is empty"); + tracingService.Trace("Attribute name:'{0}'", attributeName); + return attributeName; + } + + + + private int GetValue(EntityReference sourceEntityReference, string attributeName, ITracingService tracingService, IOrganizationService organizationService) + { + if (sourceEntityReference == null || attributeName == null) + { + tracingService.Trace("Null parameters have been passed, so string will be empty"); + return 0; + } + + Entity sourceEntity = organizationService.Retrieve(sourceEntityReference.LogicalName, sourceEntityReference.Id, new ColumnSet(attributeName)); + tracingService.Trace("Source record has been retrieved correctly. Id:{0}", sourceEntity.Id); + + if (!sourceEntity.Contains(attributeName)) + { + tracingService.Trace("Attribues {0} was not found", attributeName); + return 0; + } + int value = 0; + if (sourceEntity.Attributes.Contains(attributeName)) + { + value = ((OptionSetValue)sourceEntity.Attributes[attributeName]).Value; + } + + return value; + } + } +} \ No newline at end of file diff --git a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Properties/AssemblyInfo.cs b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Properties/AssemblyInfo.cs index b17330c..857a45f 100644 --- a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Properties/AssemblyInfo.cs +++ b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/Properties/AssemblyInfo.cs @@ -33,5 +33,5 @@ // Puede especificar todos los valores o usar los valores predeterminados (número de compilación y de revisión) // usando el símbolo '*' como se muestra a continuación: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.58.0")] -[assembly: AssemblyFileVersion("1.0.58.0")] +[assembly: AssemblyVersion("1.0.59.0")] +[assembly: AssemblyFileVersion("1.0.59.0")] diff --git a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/msdyncrmWorkflowTools.csproj b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/msdyncrmWorkflowTools.csproj index 86a4963..c8104d6 100644 --- a/msdyncrmWorkflowTools/msdyncrmWorkflowTools/msdyncrmWorkflowTools.csproj +++ b/msdyncrmWorkflowTools/msdyncrmWorkflowTools/msdyncrmWorkflowTools.csproj @@ -96,10 +96,12 @@ + + diff --git a/msdyncrmWorkflowTools/msdyncrmWorkflowTools_Class/msdyncrmWorkflowTools_Class.cs b/msdyncrmWorkflowTools/msdyncrmWorkflowTools_Class/msdyncrmWorkflowTools_Class.cs index a21fc42..9106d45 100644 --- a/msdyncrmWorkflowTools/msdyncrmWorkflowTools_Class/msdyncrmWorkflowTools_Class.cs +++ b/msdyncrmWorkflowTools/msdyncrmWorkflowTools_Class/msdyncrmWorkflowTools_Class.cs @@ -671,6 +671,19 @@ public bool InsertOptionValue(bool globalOptionSet, string attributeName, string return true; } + + public Guid CreateTeam(string teamName, int teamType, EntityReference administrator, EntityReference businessUnit) + { + Entity team = new Entity("team"); + team.Attributes.Add("administratorid", administrator); + team.Attributes.Add("name", teamName); + team.Attributes.Add("teamtype", new OptionSetValue(teamType)); + team.Attributes.Add("businessunitid", businessUnit); + + Guid _teamId = service.Create(team); + + return _teamId; + } public void AssociateEntity(string PrimaryEntityName, Guid PrimaryEntityId, string _relationshipName, string _relationshipEntityName, string entityName, string ParentId) { try diff --git a/msdyncrmWorkflowTools/msdyncrmWorkflowTools_ConsoleTest/Program.cs b/msdyncrmWorkflowTools/msdyncrmWorkflowTools_ConsoleTest/Program.cs index 9672955..490039c 100644 --- a/msdyncrmWorkflowTools/msdyncrmWorkflowTools_ConsoleTest/Program.cs +++ b/msdyncrmWorkflowTools/msdyncrmWorkflowTools_ConsoleTest/Program.cs @@ -46,7 +46,7 @@ static void Main(string[] args) //bool regexSuccess = false; //classObj.StringFunctions(false, "Lead subject", "", false, 0, false, "", "", 50, 0, false, "", ref capitalizedText, ref paddedText, ref replacedText, ref subStringText, ref regexText, ref uppercaseText, ref lowercaseText, ref regexSuccess); - + Guid createdTeam=classObj.CreateTeam("PruebaTeam2", 1, new EntityReference("systemuser", new Guid("8fe5fd89-f447-4a38-90f1-1180617fcbc5")), new EntityReference("businessunit", new Guid("6025BC19-2E34-EA11-A812-000D3ABAAFE7"))); //string json = @"{""values"": [{""Author"": ""Lisa Simpson"",""Response Date"": ""2018-02-21T08:13:34.284Z""} ], ""SurveyId"": ""5114FA48-1DE6-E711-80E3-005056B37A5C""}"; //string jsonpath = "values[0].Author"; //string res = classObj.JsonParser(json, jsonpath); @@ -64,7 +64,7 @@ static void Main(string[] args) // classObj.SendEmailToUsersInRole(securityRoleLookup, new EntityReference("email",new Guid("B96825B7-CCB0-E711-810F-5065F38BF4A1"))); //classObj.InsertOptionValue(true, "purchaseprocess", "opportunity", "Tipo22", 22, 3082); - classObj.InsertOptionValue(false, "cre36_test", "account", "3", 3, 3082); + //classObj.InsertOptionValue(false, "cre36_test", "account", "3", 3, 3082); //classObj.DeleteOptionValue(true,"purchaseprocess", "opportunity", 22); //classObj.DeleteOptionValue(false, "cdi_test", "opportunity", 1); // classObj.AssociateEntity("new_test", new Guid("612F10EE-32DB-E711-8116-5065F38BF4A1"), "new_new_test_new_test", "new_test", "new_test", "F1F924DC-32DB-E711-8116-5065F38BF4A1"); @@ -80,9 +80,9 @@ static void Main(string[] args) public static IOrganizationService GetCrmService() { - const string crmServerUrl = "https://xxxx.crm4.dynamics.com"; - const string userName = "xxxx@xxxx.com"; - const string password = ""; + const string crmServerUrl = "https://XXX.crm4.dynamics.com"; + const string userName = "XXX@XXX.com"; + const string password = "XXX"; //SecureString theSecureString = new NetworkCredential("", password).SecurePassword;