web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error on Custom Workflow Activity With Fetch XML Input Parameter when <filter type="and" > <condition attribute="cpp_jobid" operator="eq" value="{0}" /> </filter>

(0) ShareShare
ReportReport
Posted on by 1,589

I have a custom workflow activity that accepts a FetchXML string as an input parameter.

I need to execute the Fetch XML up against whatever the current record is.

My fetch XML looks like this:

<fetch>
  <entity name="cpp_job" >
    <attribute name="cpp_dateinprogress" />
    <attribute name="cpp_dateproposed" />
    <attribute name="cpp_datebooked" />
    <attribute name="cpp_datecompleted" />
    <attribute name="cpp_jobnumber" />
    <attribute name="cpp_jobstatusprimary" />
    <filter type="and" >
      <condition attribute="cpp_jobid" operator="eq" value="{0}" />
    </filter>
  </entity>
</fetch>


The problem is what when I run the workflow on demand to test it, I get the following error:

Unhandled exception:
Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
Message: System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> Microsoft.Crm.CrmException: An exception System.FormatException was thrown while trying to convert input value '{0}' to attribute 'cpp_job.cpp_jobid'. Expected type of attribute value: System.Guid. Exception raised: Expected hex 0x in '{0}'.

Why is this giving me an error about the {0} in the filter shown below?

<filter type="and" > <condition attribute="cpp_jobid" operator="eq" value="{0}" /> </filter>

If I manually insert the real GUID, it will run without error, but this will always be run against a different record and we will never know the GUID of that record.

The goal is that the Fetch XML uses "whatever the current record is" based on the operator="eq" value="{0}"

I am basing the use of the {0} on the article that explains it here - practical-crm.blogspot.com/.../workflow-fetchxml-query.html

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    What would be used in {0} depends upon what you have written in your custom workflow activity. Below is the code snippet on updating the {0} in the fetch (extracted from the same solution)

    ==============

    string fetch = FetchXML.Get<string>(executionContext);

    fetch = String.Format(fetch, context.PrimaryEntityId);

    ==============

    Check if this is what you are doing in your custom activity, if not try this and see if it works. If it doesn't work, share you custom woirkflow assembly code here.

    Hope this helps.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    Make sure you are passing correct format  GUID inside  {} , if you are passing other than GUID type you need to convert the value to GUID like below .

    string lookupid = "A16B3F4B-1BE7-E611-8101-E0071B6AF231";

                           EntityCollection OppMem = organizationService.RetrieveMultiple(new FetchExpression(String.Format(FetchXml, new Guid(lookupid))));

    You can check some sample code here from my answer-

    community.dynamics.com/.../318732

  • ACECORP Profile Picture
    1,589 on at

    Ravi, that worked. Thanks so much!

  • ACECORP Profile Picture
    1,589 on at

    This may also work -- slightly different approach. I will use this if and when it makes sense to do so. Thanks!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans