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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Fetching Multiple Resources Details while Generating Invoice

(0) ShareShare
ReportReport
Posted on by 225

Hi All,

I have a requirement that , when a work order is generated in dynamics CRM, and we assign the work order to a resource or multiple resources  ,when the Work order is Completed ,we all know that a Invoice is generated through the Work order. I want to fetch  the Resource details such as "Resource name", "Resource Work hours Logged" and some other details in the Invoice  Form.

And also if more than one resources has worked on a particular Work order ,I want all of them in the Invoice Form.(Like a Grid) in CRM.

How can I achieve this? Anyone has worked on related issue. please guide.

*This post is locked for comments

I have the same question (0)
  • Thomas David Dayman Profile Picture
    11,323 on at

    Hi Varsha,

    Not sure how familiar you are with advanced FetchXML techniques. But I was able to retrieve most of the details using this fetch:

    <fetch distinct="true" mapping="logical" output-format="xml-platform" version="1.0" >
      <entity name="msdyn_bookingjournal" >
        <attribute name="createdon" />
        <attribute name="msdyn_journaltype" />
        <attribute name="msdyn_starttime" />
        <attribute name="msdyn_endtime" />
        <attribute name="msdyn_duration" />
        <attribute name="msdyn_bookingjournalid" />
        <order descending="false" attribute="msdyn_journaltype" />
        <link-entity name="bookableresourcebooking" alias="af" link-type="inner" to="msdyn_booking" from="bookableresourcebookingid" >
          <attribute name="resource" />
          <link-entity name="msdyn_workorder" alias="ag" link-type="inner" to="msdyn_workorder" from="msdyn_workorderid" >
            <link-entity name="msdyn_workorderproduct" alias="ah" link-type="inner" to="msdyn_workorderid" from="msdyn_workorder" >
              <link-entity name="invoicedetail" alias="ai" link-type="inner" to="msdyn_workorderproductid" from="msdyn_workorderproductid" >
                <link-entity name="invoice" alias="aj" link-type="inner" to="invoiceid" from="invoiceid" >
                  <attribute name="invoiceid" />
                  <attribute name="invoicenumber" />
                  <filter type="and" >
                    <condition attribute="invoiceid" value="{45893471-D87E-4A58-9DCF-AAB59894221D}" uitype="invoice" uiname="INV-00028" operator="eq" />
                  </filter>
                </link-entity>
              </link-entity>
            </link-entity>
          </link-entity>
        </link-entity>
      </entity>
    </fetch>


    You might need to edit this fetch to your liking though. Let me know f you have any questions.

  • Varsha Naithani Profile Picture
    225 on at

    how am I suppose to use this fetch for retrieving records in a Grid or similar type. I do not want the records in a report , can you please elaborate how can I use this fetch in a web resource or any other technique to fetch multiple records in a Grid.

  • Thomas David Dayman Profile Picture
    11,323 on at

    You can use FetchXML pretty much everywhere. Just need to do a little googling.

    Below is some sample code I created which waits for a particular subgrid to load on the form and then loads the fetch to the subgrid once loaded.

    function formOnLoad()
    {
    	filterPartsReturnPRGrid();
    }
    
    //Filter the Parts Return Parts Request Sub Grid
    function filterPartsReturnPRGrid()
    {
    	//get the subgrid 
    	var objSubGrid = window.parent.document.getElementById("Part_Returns_Parts_Request");
    	//CRM loads subgrid after form is loaded.. so when we are adding script on form load.. need to wait until sub grid is loaded. 
    	// that's why we are adding a delay..
    	var isGridLoaded = null;
    	try
    	{
    		isGridLoaded = objSubGrid.control.getEntityName();
    	}
    	catch (err)
    	{
    		setTimeout(filterPartsReturnPRGrid, 2000);
    		return;
    	}
    	if (isGridLoaded != null)
    	{
    		//when subgrid is loaded, get GUID
    		var GUIDvalue = Xrm.Page.data.entity.getId();
    		//Create FetchXML for sub grid to filter records based on GUID
    		var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
    			"  <entity name='new_part_returns'>" +
    			"    <attribute name='new_part_returnsid' />" +
    			"    <attribute name='createdon' />" +
    			"    <attribute name='new_work_order_used_on' />" +
    			"    <attribute name='new_reason_for_return' />" +
    			"    <attribute name='new_serial_number' />" +
    			"    <attribute name='new_product' />" +
    			"    <attribute name='new_partreturnid' />" +
    		    "    <order attribute='createdon' descending='true' />" +
    			"    <link-entity name='f1_purchaseorder' from='f1_purchaseorderid' to='new_parts_request' alias='af'>" +
    			"      <link-entity name='f1_workorder' from='f1_workorderid' to='f1_workorder' alias='ag'>" +
    			"        <filter type='and'>" +
    			"          <condition attribute='f1_serviceaccount' operator='eq' value='" + GUIDvalue + "' />" +
    			"        </filter>" +
    			"      </link-entity>" +
    			"    </link-entity>" +
    			"  </entity>" +
    			"</fetch>";
    		// Layout of subgrid.
    		var LayoutXml = "<grid name='resultset' object='10287' jump='new_partreturnid' select='1' preview='1' icon='1'>" +
    			" <row name='result' id='new_part_returnsid'>" +
    			"<cell name='new_partreturnid' width='100' />" +
    			"<cell name='new_product' width='200' />" +
    			"<cell name='new_serial_number' width='150' />" +
    			"<cell name='new_work_order_used_on' width='100' />" +
    			"<cell name='new_reason_for_return' width='200' />" +
    			"<cell name='createdon' width='150' />" +
    			"</row>" +
    			"</grid>";
    		//apply layout and filtered fetchXML
    		objSubGrid.control.SetParameter("layoutXml", LayoutXml);
    		objSubGrid.control.SetParameter("fetchXml", FetchXml);
    		//Refresh grid to show filtered records only. 
    		objSubGrid.control.Refresh();
    	}
    }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
RichardM Profile Picture

RichardM 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans