Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new step - GetRecordUrl #274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions msdyncrmWorkflowTools/msdyncrmWorkflowTools/Class/GetRecordUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Microsoft.Xrm.Sdk.Workflow;
using System;
using System.Activities;

namespace msdyncrmWorkflowTools
{
/// <summary>
/// Gets the URL for a record
/// </summary>
public class GetRecordUrl : CodeActivity
{
/// <summary>
/// A reference Record URL (use the URL for the record on which the flow is running)
/// </summary>
[RequiredArgument]
[Input("Reference Record URL")]
public InArgument<string> ReferenceRecordUrl { get; set; }

/// <summary>
/// ID of the record
/// </summary>
[RequiredArgument]
[Input("Record ID")]
public InArgument<string> RecordId { get; set; }

/// <summary>
/// Logical name of the entity
/// </summary>
[RequiredArgument]
[Input("Entity Logical Name")]
public InArgument<string> EntityName { get; set; }

/// <summary>
/// URL of the record
/// </summary>
[Output("Record URL")]
public OutArgument<string> RecordUrl { get; set; }

protected override void Execute(CodeActivityContext context)
{
Common objCommon = new Common(context);
msdyncrmWorkflowTools_Class commonClass = new msdyncrmWorkflowTools_Class(objCommon.service, objCommon.tracingService);
string entityName = this.EntityName.Get(context);
Guid recordId = Guid.Parse(this.RecordId.Get(context));
string referenceRecordUrl = this.ReferenceRecordUrl.Get(context);

var entityCode = objCommon.GetEntityCodeFromName(entityName, objCommon.service);
var recordUrl = commonClass.GetRecordUrl(referenceRecordUrl, entityCode, recordId);
this.RecordUrl.Set(context, recordUrl);
}
}
}
17 changes: 17 additions & 0 deletions msdyncrmWorkflowTools/msdyncrmWorkflowTools/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ public string sGetEntityNameFromCode(string ObjectTypeCode, IOrganizationService
return entityMetadata.SchemaName.ToLower();
}

public string GetEntityCodeFromName(string entityName, IOrganizationService service)
{
MetadataFilterExpression entityFilter = new MetadataFilterExpression(LogicalOperator.And);
entityFilter.Conditions.Add(new MetadataConditionExpression("LogicalName", MetadataConditionOperator.Equals, entityName));
EntityQueryExpression entityQueryExpression = new EntityQueryExpression()
{
Criteria = entityFilter
};
RetrieveMetadataChangesRequest retrieveMetadataChangesRequest = new RetrieveMetadataChangesRequest()
{
Query = entityQueryExpression,
ClientVersionStamp = null
};
RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)service.Execute(retrieveMetadataChangesRequest);
EntityMetadata entityMetadata = response.EntityMetadata.Count > 0 ? (EntityMetadata)response.EntityMetadata[0] : null;
return entityMetadata?.ObjectTypeCode.Value.ToString();
}

public EntityCollection getAssociations(string PrimaryEntityName, Guid PrimaryEntityId, string _relationshipName, string entityName, string ParentId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<Compile Include="Class\DistributeWFActivityManyToMany.cs" />
<Compile Include="Class\DistributeWFActivityOneToMany.cs" />
<Compile Include="Class\ExecuteWorkflowForRecordsinQuery.cs" />
<Compile Include="Class\GetRecordUrl.cs" />
<Compile Include="Class\SetLookupFieldFromRecordUrl.cs" />
<Compile Include="Class\ResolveCase.cs" />
<Compile Include="Class\ShareSecuredField.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ public string GetRecordID(string recordURL)
return objectId;
}

public string GetRecordUrl(string referenceRecordUrl, string entityCode, Guid recordId)
{
string[] urlParts = referenceRecordUrl.Split("?".ToArray());
string dynamicsUrl = urlParts[0];
return $"{dynamicsUrl}?etc={entityCode}&id={recordId}";
}


public string GetAppModuleId(string appModuleUniqueName)
{
var query = new QueryExpression
Expand Down