Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to pass GUID dynamically into fetchXML?

(1) ShareShare
ReportReport
Posted on by

Hello,

I am trying to create a workflow that generates an email that includes a table with results of a specific record.

We have a custom entity called "Business Diagnostic" which has a child entity of "Business Diagnostic Contents". When a flag is triggered on the "Business Diagnostic" entity, I want the workflow to pull data from both the "Business Diagnostic" and "Business Diagnostic Contents" for the Account that is related to the diagnostic. (There is an account field on both related entities). 

I have created the workflow which uses 'Kaskela's Workflow Elements:Query - Get Results' which I have passed in some fetchXML to retrieve the data I want to put into a table.

When I hard code a person's GUID into the condition value - the workflow works. However, we want to pass in the GUID for the Account that is related to the specific "Business Diagnostic". After reading a lot of suggestions on the forum, we have tried a number of ways to get the GUID which haven't worked for us, such as:

"#name#"
"+name+"
'"+name+"'
{"+name+"}

The fetchXML is as followed:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="new_businessdiagcontent">
    <attribute name="new_priority" />
    <attribute name="new_discipline" />
    <attribute name="new_businessdiagcontentid" />
    <attribute name="new_primarysupportoffer" />
    <order attribute="new_discipline" descending="false" />
	<filter type="and">
          <condition attribute="new_account" operator="eq" value="#accountid#" />
	</filter>
    <link-entity name="new_supportoffer" from="new_supportofferid" to="new_primarysupportoffer" visible="false" link-type="outer" alias="a_299baed67641e811a96a000d3ab5cc4c">
      <attribute name="new_whatdoesitdo" />
      <attribute name="new_webaddress" />
      <attribute name="new_telnumber" />
      <attribute name="new_suppliername" />
      <attribute name="new_phone" />
      <attribute name="new_howaccessed" />
      <attribute name="new_email" />
      <attribute name="new_contactrole" />
      <attribute name="new_contactname" />
      <attribute name="new_benefittome" />
    </link-entity>
    <link-entity name="new_businessdiagnostic" from="new_businessdiagnosticid" to="new_bdiagnostic2contentid" link-type="inner" alias="a_9a1fb6a10126e71180f95065f38b15b1">
      <attribute name="new_businessdiagnostictitle" />
      <attribute name="new_accounttodiagid" />
    </link-entity>
  </entity>
</fetch>

The main error we seem to be getting is a Plug In Error (xxxx-xxxxxx) looking for 32 GUID... so we know that the error lies within pointing to the right GUID dynamically. 

Any suggestions would be much appreciated! 

Thanks!! 

*This post is locked for comments

  • TSP Profile Picture
    TSP 10 on at
    RE: How to pass GUID dynamically into fetchXML?

    Hi @Katie110596 Did you ever find a solution, I have the same problem, I need to set the GUID ID dynamically in the Workflow

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: How to pass GUID dynamically into fetchXML?

    Hello,

    You can write your fetchxml under string variable something like this

    string FetchXML="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    FetchXML+="<entity name='new_businessdiagcontent'>";
    FetchXML+="<attribute name='new_priority' /><attribute name='new_discipline' />"
    FetchXML+="<attribute name='new_businessdiagcontentid' /><attribute name='new_primarysupportoffer' />"
    FetchXML+="<order attribute='new_discipline' descending='false' /><filter type='and'>";
    FetchXML+="<condition attribute='new_account' operator='eq' value="+accountid+"/>";
    
    

    Also you should use some name for all the alias in your query for example like below

    <link-entity name='new_businessdiagnostic' from='new_businessdiagnosticid' to='new_bdiagnostic2contentid' link-type='inner' alias='businessdiagnosticentity'>

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: How to pass GUID dynamically into fetchXML?

    Hello,

    Try to write like this  - declare the Guid variable first and assigned first .

                string fetchXml = string.Format(@"<fetch version = '1.0' output - format = 'xml-platform' mapping = 'logical' distinct = 'false' >" +         
               "<entity name = 'new_businessdiagcontent' >" +          
                  "<attribute name = 'new_priority' />" +           
                   "<attribute name = 'new_discipline' />" +            
                    "<attribute name = 'new_businessdiagcontentid' />" +             
                     "<attribute name = 'new_primarysupportoffer' />" +              
                      "<order attribute = 'new_discipline' descending = 'false' />" +                 
                         "<filter type = 'and' >" +                  
                                "<condition attribute = 'new_account' operator= 'eq' value = '"+ accountid +"' />" +                      
                              "</filter>" +                      
                              "<link - entity name = 'new_supportoffer' from = 'new_supportofferid' to = 'new_primarysupportoffer' visible = 'false' link - type = 'outer' alias = '"+ GuidVariable1 +"' >" +
                                         
                                               "<attribute name = 'new_whatdoesitdo' />" +                                      
                                                "<attribute name = 'new_webaddress' />" +                                       
                                                 "<attribute name = 'new_telnumber' />" +                                        
                                                  "<attribute name = 'new_suppliername' />" +                                         
                                                   "<attribute name = 'new_phone' />" +                                          
                                                    "<attribute name = 'new_howaccessed' />" +                                           
                                                     "<attribute name = 'new_email' />" +                                            
                                                      "<attribute name = 'new_contactrole' />" +                                             
                                                       "<attribute name = 'new_contactname' />" +                                              
                                                        "<attribute name = 'new_benefittome' />" +                                               
                                                       "</link - entity >" +                                               
                                                       "<link - entity name = 'new_businessdiagnostic' from = 'new_businessdiagnosticid' to = 'new_bdiagnostic2contentid' link - type = 'inner' alias = '"+ GuidVariable2 + "' >" +                                                            
                                                                      "<attribute name = 'new_businessdiagnostictitle' />" +                                                             
                                                                       "<attribute name = 'new_accounttodiagid' />" +                                                              
                                                                      "</link - entity >" +                                                              
                                                                    "</entity >" +
                                                                  "</fetch >");
    
                EntityCollection resultCustEqup = service.RetrieveMultiple(new FetchExpression(fetchXml));


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,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans