Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Workflow Activity to retrieve outputs from fetchxml query

Posted on by 55

I need to retrieved all emails value from fetchxml query in workflow activity.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Workflow Activity to retrieve outputs from fetchxml query

    I will quote myself:

    You would not be able to do that. What you can do is to pass pre-created email as a parameter to that custom workflow activity and populate "to" field of it based on your query. I did something similar in my workflow toolkit. As an example you can check this - github.com/.../SendEmailToTeam.cs

  • moelshimy Profile Picture
    moelshimy 55 on at
    RE: Workflow Activity to retrieve outputs from fetchxml query

    6320.Capture.JPG

    The problem that i need to retrieve multi contacts as one output of type EntityReference

    here is code which return one contact as per highlighted ,so is it possible to return multi contacts once and use this output to send one mail to multi contacts as per attached screenshot.

    public class GetAllContacts : CodeActivity

       {

    [RequiredArgument]

           [Input("FetchXML Query")]

           public InArgument<string> FetchXmlQuery { get; set; }

           [Input("FetchXML Query Format Argument 1")]

           public InArgument<string> FetchXmlQueryFormatArg1 { get; set; }

           [Output("Contacts List")]

           [ReferenceTarget("contact")]

           public OutArgument<EntityReference> EntityRef { get; set; }

           protected override void Execute(CodeActivityContext  context)

           {

               var entityReference = new EntityReference();

               var serviceFactory = context.GetExtension<IOrganizationServiceFactory>();

               var service = serviceFactory.CreateOrganizationService(Guid.Empty);

               var recordsToProcess = service.RetrieveMultiple(new FetchExpression(GetFormattedFetchQuery(context)));

               if (recordsToProcess != null && recordsToProcess.Entities != null && recordsToProcess.Entities.Count()>0)

               {

                   entityReference = recordsToProcess.Entities.FirstOrDefault().ToEntityReference();

                   EntityRef.Set(context, entityReference);

               }

           }

       private string GetFormattedFetchQuery(CodeActivityContext context)

           {

               var query = this.FetchXmlQuery.Get(context);

               return String.Format(query,

                   this.FetchXmlQueryFormatArg1.Get(context));

           }

       }

    }

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Workflow Activity to retrieve outputs from fetchxml query

    Please, don't create follow up of previous thread as a new one. Can you please be more specific - what exactly doesn't work?

  • moelshimy Profile Picture
    moelshimy 55 on at
    Send mail through Workflow activity

    I created new Workflow activity with Fetchxml as an input and the output is a list of recipient emails in one variable as output but when i trying to set this output in  TO field of step send mail not accepted as this field it a lookup for (contacts or Account.etc) , so how can i map the out put to this field (to)

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Workflow Activity to retrieve outputs from fetchxml query

    Hello,

    You would not be able to do that. What you can do is to pass pre-created email as a parameter to that custom workflow activity and populate "to" field of it based on your query. I did something similar in my workflow toolkit. As an example you can check this - github.com/.../SendEmailToTeam.cs

    Feel free to update the thread if you have any questions.

  • moelshimy Profile Picture
    moelshimy 55 on at
    RE: Workflow Activity to retrieve outputs from fetchxml query

    I read it but i still don't know how to return multiple email addresses in one output (from fetchxml query ) in workflow activity to send one mail for many recipients

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Workflow Activity to retrieve outputs from fetchxml query

    Hi,

    See below link to construct fetchxml and use in workflow activity.

    docs.microsoft.com/.../use-fetchxml-construct-query

    Please mark my answer verified if i were helpful

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans