Skip to main content

Notifications

Announcements

No record found.

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>

Posted on by 1,579

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

  • ACECORP Profile Picture
    ACECORP 1,579 on at
    RE: Error on Custom Workflow Activity With Fetch XML Input Parameter when <filter type="and" > <condition attribute="cpp_jobid" operator="eq" value="{0}" /> </filter>

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

  • ACECORP Profile Picture
    ACECORP 1,579 on at
    RE: Error on Custom Workflow Activity With Fetch XML Input Parameter when <filter type="and" > <condition attribute="cpp_jobid" operator="eq" value="{0}" /> </filter>

    Ravi, that worked. Thanks so much!

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Error on Custom Workflow Activity With Fetch XML Input Parameter when <filter type="and" > <condition attribute="cpp_jobid" operator="eq" value="{0}" /> </filter>

    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

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Error on Custom Workflow Activity With Fetch XML Input Parameter when <filter type="and" > <condition attribute="cpp_jobid" operator="eq" value="{0}" /> </filter>

    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.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans