Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

attachment added for case within 2 days

(0) ShareShare
ReportReport
Posted on by 245

I have a requirement like when there is no attachment for a case within 2 days from created date the case should be closed and SMS should be sent to the customer that case is closed.

Already i have custom workflow that sends SMS on case closure.So kindly let me know how to check if attachment is added within 2 days? if this could be achieved with OOB?

*This post is locked for comments

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,052 on at
    RE: attachment added for case within 2 days

    Hi

    Yes you will have to create the CWA using the code snippet. 

    I have uploaded sample code to the following github reppo if you wanna have a look

    https://github.com/Kokulan365/WorkflowEssentials/blob/master/Workflows/RecordHasNoteAttachment.cs

    using System;
    using System.Linq;
    using System.Activities;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Workflow;
    using KED365.Workflows.Helpers;
    using Microsoft.Xrm.Sdk.Query;
    namespace KED365.Workflows
    {
    public class RecordHasNoteAttachment: WorkFlowActivityBase
    {
    [Input("Note Source Record")]
    public InArgument<string> SourceRecord { get; set; }
    [Output("HasAttachment")]
    public OutArgument<bool> HasAttachment { get; set; }
    [Output("IsSuccess")]
    public OutArgument<bool> IsSuccess { get; set; }
    [Output("Message")]
    public OutArgument<string> Message { get; set; }
    protected override void Execute(CodeActivityContext activityContext, IWorkflowContext workflowContext, IOrganizationService crmService,
    ITracingService tracingService)
    {
    try
    {
    // Get the Source Record URL
    string sourceRecordUrl = SourceRecord.Get(activityContext);
    if (string.IsNullOrEmpty(sourceRecordUrl) )
    {
    Message.Set(activityContext, "Source Record URL cannot be empty or null");
    return;
    }
    // Convert Record URL to ER
    EntityReference sourceRecordEr = EntityRecordUrlHelpers.ConvertRecordUrLtoEntityReference(sourceRecordUrl, crmService);
    if (sourceRecordEr == null)
    {
    Message.Set(activityContext, "Failed to convert record URL into Entity Reference. Please make sure you provide valid record URL");
    return;
    }
    var recordId = sourceRecordEr.Id;
    var annotation_isdocument = true;
    var query = new QueryExpression(sourceRecordEr.LogicalName);
    query.Distinct = true;
    query.ColumnSet.AddColumns("createdon");
    query.Criteria.AddCondition($"{sourceRecordEr.LogicalName}id", ConditionOperator.Equal, recordId);
    var queryAnnotation = query.AddLink("annotation", $"{sourceRecordEr.LogicalName}id", "objectid");
    queryAnnotation.EntityAlias = "aa";
    queryAnnotation.LinkCriteria.AddCondition("isdocument", ConditionOperator.Equal, annotation_isdocument);
    queryAnnotation.LinkCriteria.AddCondition("filename", ConditionOperator.NotNull);
    var results = crmService.RetrieveMultiple(query);
    if (!results.Entities.Any())
    {
    // No attachments found
    HasAttachment.Set(activityContext, false);
    return;
    }
    // Attachments found
    HasAttachment.Set(activityContext, true);
    IsSuccess.Set(activityContext, true);
    }
    catch (Exception ex)
    {
    IsSuccess.Set(activityContext, false);
    Message.Set(activityContext, "An error occurred while check for attachments -" + ex.Message);
    }
    }
    }
    }

    This solution will work for not just case any entity, you will have to pass Record URL as shown below

    ScreenClip-_5B00_215_5D00_.png

    ScreenClip-_5B00_215_5D00_.png

    Hope this helps

  • DivyaBharathi Profile Picture
    DivyaBharathi 245 on at
    RE: attachment added for case within 2 days

    Thanks for the response Kokulan,

    I have followed the same which you suggested but instead of creating Action i did custom workflow and registered it and used its output parameter and achieved the same.

    If you can share me how to add action with custom code .And which is preferred Action or custom workflow

  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,052 on at
    RE: attachment added for case within 2 days

    Hi

    You will have to create a Custom Workflow Activity (CWA) that takes case as Input parameter and checks if there are any attachments to the case and returns a boolean (HasDocument/HasAttachment) as output. You can then use this custom workflow activity as shown below in your workflow

    4578.ScreenClip-_5B00_154_5D00_.png

    Your workflow should have a parallel wait condition on case status so that if the case resolved before 2 days, there is no point in waiting so the workflow can end.

    The second wait is based on time,  2 days from created on and when it times out, your CWA will be called to check if the Case has any attachments.

    If the case does not have any, you can resolve the case as shown in the screenshot.

    To check if a case has any attachment, the query could be defined as shown below

    4578.ScreenClip-_5B00_154_5D00_.png

    Since we cant execute this query in Workflow step, we need the CWA to execute this and please see the section below for c# version of the above advance find query.

    Your custom workflow activity could execute the following code to check if the case has any attachment

    // Define Condition Values
    var QEincident_incidentid = "b69e62a8-90df-e311-9565-a45d36fc5fe8"; - Case ID Goes here
    var QEincident_annotation_isdocument = true;

    var QEincident = new QueryExpression("incident");
    QEincident.Distinct = true;

    QEincident.ColumnSet.AddColumns("title");

    QEincident.Criteria.AddCondition("incidentid", ConditionOperator.Equal, QEincident_incidentid);

    var QEincident_annotation = QEincident.AddLink("annotation", "incidentid", "objectid");
    QEincident_annotation.EntityAlias = "aa";

    QEincident_annotation.LinkCriteria.AddCondition("isdocument", ConditionOperator.Equal, QEincident_annotation_isdocument);
    QEincident_annotation.LinkCriteria.AddCondition("filename", ConditionOperator.NotNull);

    var results = crmService.RetrieveMultiple(QEincident);

    if (results.Entities.Any())

    {

    // Case has attachments - return true

    }

    else

    {

    //Case has no attachment - return false

    }

    Hope this helps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans