Sunday, March 23, 2025

Activity Party

 using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Query;

using System;

using System.Collections.Generic;


public class RetrieveActivityParty

{

    private readonly IOrganizationService _service;


    public RetrieveActivityParty(IOrganizationService service)

    {

        _service = service;

    }


    public void GetActivityParties(Guid activityId)

    {

        QueryExpression query = new QueryExpression("activityparty")

        {

            ColumnSet = new ColumnSet("partyid", "participationtypemask")

        };


        query.Criteria.AddCondition("activityid", ConditionOperator.Equal, activityId);


        EntityCollection results = _service.RetrieveMultiple(query);


        foreach (Entity activityParty in results.Entities)

        {

            EntityReference party = activityParty.GetAttributeValue<EntityReference>("partyid");

            int participationType = activityParty.GetAttributeValue<OptionSetValue>("participationtypemask")?.Value ?? 0;


            Console.WriteLine($"Party ID: {party?.Id}, Type: {party?.LogicalName}, Participation Type: {participationType}");

        }

    }

}

---------
string fetchXml = $@"
    <fetch>
        <entity name='activityparty'>
            <attribute name='partyid' />
            <attribute name='participationtypemask' />
            <filter>
                <condition attribute='activityid' operator='eq' value='{activityId}' />
            </filter>
        </entity>
    </fetch>";

EntityCollection results = _service.RetrieveMultiple(new FetchExpression(fetchXml));

-------

Monday, March 10, 2025

Slpit-string

using System;

using System.Text.RegularExpressions;


class Program

{

    static void Main()

    {

        string url = "https://example.com/a-guid/b-guid/c-guid/d.anyextension";

        

        if (TryExtractFields(url, out string fieldA, out string fieldBC))

        {

            Console.WriteLine($"a: {fieldA}");

            Console.WriteLine($"b/c: {fieldBC}");

        }

        else

        {

            Console.WriteLine("Invalid URL format.");

        }

    }


    static bool TryExtractFields(string url, out string fieldA, out string fieldBC)

    {

        fieldA = string.Empty;

        fieldBC = string.Empty;


        // Regex to match: https://{domain}/{guid}/{guid}/{guid}/filename.anyextension

        Regex regex = new Regex(@"^https://[^/]+/([0-9a-fA-F-]{36})/([0-9a-fA-F-]{36})/([0-9a-fA-F-]{36})/[^/]+\.[a-zA-Z0-9]+$");

        Match match = regex.Match(url);


        if (match.Success)

        {

            fieldA = match.Groups[1].Value;   // Extract GUID 'a'

            fieldBC = $"{match.Groups[2].Value}/{match.Groups[3].Value}";  // Extract 'b/c' as "b-guid/c-guid"

            return true;

        }


        return false;

    }

}