MS CRM: Check the status of a child workflow - dynamics-crm-2011

I am designing a few workflows. The main workflow calls some child workflow. If the child workflows fail I need to wait for a time period and then rerun that child workflow. If it fails again send a task to a queue.
I am having troubles checking the status of the child workflow. When it fails I am stopping the child workflow with the status cancelled.

You can create custom workflow step that queries async operation table and checks state of child workflow.
Query to get state of child workflow:
<?xml version='1.0' encoding='utf-8'?>
<fetch distinct='false' no-lock='false' mapping='logical' page='1' count='100'>
<entity name='asyncoperation'>
<attribute name='statuscode' />
<filter type='and'>
<filter type='and'>
<condition attribute='correlationid' operator='eq' value='{Correlation ID of workflow>' />
<condition attribute='name' operator='eq' value='NAME OF CHILD WORKFLOW' />
</filter>
</filter>
</entity>
</fetch>
It's sample query, and matches child by name and correlation id. It will work if you have only one call to child workflow.
Here you can find a list of state values for async processes: https://msdn.microsoft.com/en-us/library/gg309288.aspx
Then main workflow steps would look like:
call child workflow
wait some time
call custom step to check status of child workflow
if child status is ok - carry on with main
if not add logic to handle failure

Related

Use date parameter in Azure Pipeline FetchXML query

in my Azure Data Factory pipeline, I have a parameter, let's call it 'pDate', and it has a default value of 2023-01-01.
But every time I run the pipeline (copy data), I want to be able to change it.
I can do that with a variable as shown below (date1 variable), but then I have to change the value of the variable.
How could I insert a parameter here instead?
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="my_attachment">
<all-attributes/>
<filter type="and">
<condition attribute="createdon" operator="on-or-after" value="#{variables('date1')}" />
</filter>
</entity>
</fetch>
Parameters are constants across the particular pipeline. So, you can't change its value within the pipeline.
A variable with static value (say 2023-01-01) is a parameter itself. Every time you execute the pipeline, the same value will be assigned to the variable making its functionality similar to parameter.
If there is a pattern for your date like created on or before 10 days (from today's date), then you can build a dynamic pipeline expression for this value. So, each time you run the pipeline, the value would be dynamic as required.
If there is no such pattern, then you have to make use of parameters. You can still change the value each time you run the pipeline.
When you try to trigger or debug the pipeline, the pipeline run tab will prompt you to enter the value for your parameter. You can simply give the required value and proceed accordingly.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="my_attachment">
<all-attributes/>
<filter type="and">
<condition attribute="createdon" operator="on-or-after" value="#{pipeline().parameters.req_date}" />
</filter>
</entity>
</fetch>

multiple level of expansion in crm webapi

I have an entity called as medicalcase
Each medical case has a subgrid, N:N relationship with an entity called as mcfamily
Each mcfamily has Father, Mother, Child fields which are lookups to contact field
Now if I make a webapi call
http://serverurl/api/data/v8.0/new_medicalcase(caseid)?$expand=new_medcase_mcfamily
I get the new_father_value, but I want to expand the Father lookup and get the contact name. How can I do it?
I tried
http://serverurl/api/data/v8.0/new_medicalcase(caseid)?$expand=new_medcase_mcfamily($expand=new_father($select=fullname))
But it said
navigation property can't be expanded. Multiple levels of expansion
aren't supported.
You'll have to manually expand by making a second request for the father contact.
If you make the request using a FetchXml query, you should be able to double-expand with one call. Here's an example of how to send a fetch query via the WebAPI (too long to copy here).
Update in response to your comment
Here's a fetch query that would retrieve all of your father names in one call. It assumes the following logical names:
medicalcase entity: new_medicalcase
mcfamily entity: new_mcfamily
lookup to father contact: new_fatherid
N:N entity: new_medicalcase_new_mcfamily
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="contact" >
<attribute name="fullname" />
<link-entity name="new_mcfamily" from="new_fatherid" to="contactid">
<link-entity name="new_medicalcase_new_mcfamily" from="new_mcfamilyid" to="new_mcfamilyid" intersect="true">
<link-entity name="new_medicalcase" from="new_medicalcaseid" to="new_medicalcaseid">
<filter>
<condition attribute="new_medicalcaseid" operator="eq" value="FAEEE5D8-D67C-E511-80E6-3863BB3CA578" />
</filter>
</link-entity>
</link-entity>
</link-entity>
</entity>
</fetch>
To get the query working right, use the FetchXml Tester tool that comes with the XrmToolbox. After you get it working correctly, reference the link from earlier in my answer to execute the fetch query using the WebAPI.

Limit the result from FetchXML query in CRM online 2015

I am using a service that gets data from CRM ONLINE and transfers it to SQL database for reporting purposes. I am using the following Fetch XML query to query CRM
string fetchXml = string.Format(#"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='new_studentinformation' enableprefiltering ='1' prefilterparametername='CRM_Filterednew_studentinformation'>
<attribute name='new_studentid' />
<attribute name='new_primaryhomeroom' />
<attribute name='new_lastname' />
<attribute name='new_firstname' />
<attribute name='new_busnumber' />
<attribute name='new_schoolname' />
<attribute name='new_gradecode' />
<attribute name='modifiedon' />
<attribute name='new_studentinformationid' />
<filter type='and'>
<condition attribute='modifiedon' value='{0}' operator='on-or-after'/>
</filter>
<order attribute='modifiedon' descending='true' />
<link-entity name='annotation' from='objectid' to='new_studentinformationid' alias='Notes' link-type='outer'>
<attribute name='documentbody'/>
<filter type='and'>
<condition attribute='createdon' value='{0}' operator='on-or-after'/>
</filter>
<order attribute='createdon' descending='true' />
</link-entity>
</entity>
</fetch>"
Every record has more than one image attached to it in Notes entity, however I want to transfer the latest picture ONLY. I have tried using the createdon in the order attribute but it keep bringing the images with the record till the oldest one. I only want it to bring the latest image and stop it there and move to the next record.
How can I limit it to querying only the latest image attached with the record?
Unfortunately <link-entity> doesn't allow it.
If you want a quick cheat around this limitation, you could do this (we do it all the time when specs go nuts):
Add a lookup to annotation to your new_studentinformation entity (keep it out of forms)
Register a plugin on new_studentinformation (Pre-Op, Sync, both for Retrieve and RetrieveMultiple) in which you fill the new attribute with the reference to the record you want in the report. I expect this to take 15 minutes tops.
Now switch the from attribute in the link-entity to the new one
BONUS: If your plugin is designed correctly, the reference in the custom attribute (and consequently your report) will automagically update itself.
I have a simple solution for your problem which will save you time and effort which you will put in making a plugin.
You should make a javascript resource , add a hidden field on your form.
Run that javascript on OnSave event. Store that document body in a text view.
Just query the document body text area while you are retrieving the image.
It may sound a hack! but it will increase the efficiency of your code.

how to get task those are not in any queue in crm 2011

I am using CRM 2011 on-Premisis. I have a portal in which client create a ticket(task in crm) and it goes in specific queue line (CS Queue,EDI Queue, Lab Quue). But some tasks created but do not goes in any quue. How I get these taks which are not in any queue.
If anyone have an idea please share with me.
Thanks in advance.
Regards,
Riaz Usmani
I believe you can try to use Left Outer Join to get your data. I've built provided query based on following article - http://msdn.microsoft.com/en-us/library/dn531006.aspx Try it:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="task">
<attribute name="activityid" />
<attribute name="subject" />
<link-entity name="queueitem" from="objectid" to="activityid" alias="ab" link-type="outer">
<attribute name="objectid" />
</link-entity>
<filter type="and">
<condition entityname="ab" attribute="objectid" operator="null" />
</filter>
</entity>
<fetch/>

How Can I Find All Accounts Who Have Not Modified Any Activity in Last One Month Using FetchXMl

Is it possible to find all accounts who has not modified any activity in last one month in CRM. I have tried one but i am not sure whether it is correct or not. can anybody please help me. I am not sure whether it is possible or not.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="account">
<attribute name="name" />
<attribute name="primarycontactid" />
<attribute name="telephone1" />
<attribute name="accountid" />
<order attribute="name" descending="false" />
<link-entity name="activitypointer" from="regardingobjectid" to="accountid" alias="au" link-type="outer">
<filter type="and">
<condition attribute="modifiedon" operator="olderthan-x-months" value="1" />
</filter>
</link-entity>
I think the best way to do this without making multiple queries is to create a custom field on the account entity and then have a plugin that populates that field whenever an activity related to the account is updated. That will make your query a lot easier and work in CRM.
I'm afraid that it is not possible to get such kind of fetch xml. You will have to implement your logic in 2 steps:
Retrieve all accounts.
Remove all the accounts that have activities that were modified during last month.
I guess your problem here is that you will only get Accounts that have an associated activity. While your query also needs to return accounts that have no associated activities as well.
What you need is a Left Outer Join. This is only available in 2013 so, if you are upgrading any time soon, you will be able to add the following condition to your query to get the required results.
<condition entityname='account' attribute='regardingobjectid' operator='null'/>

Resources