Via REST Builder i created a statement to get all workorders with related workorderservicetask and another statement to recieve the inspection of a servicetask. But i dont know how to combine them correctly resulting in nested expands.
Get workorders with related servicetasks
Xrm.WebApi.retrieveRecord( "msdyn_workorder", "6bf60eff-2e64-ed11-9561-6045bd8edfa9", `?$select=msdyn_workorderid &$expand=msdyn_msdyn_workorder_msdyn_workorderservicetask_WorkOrder( $select=msdyn_name, msdyn_description, msdyn_workorderservicetaskid, msdyn_actualduration, )`).then(function success(result) {console.log(result); }, function(error) { console.log(error.message); } );
Get servicetask with related inspection
Xrm.WebApi.retrieveRecord( "msdyn_workorderservicetask", "2ab23304-2f64-ed11-9562-6045bd8c9366", "?$expand=msdyn_Inspection($select=msdyn_inspectionid,msdyn_description,msdyn_name,statecode,msdyn_state,statuscode)").then( function success(result) { console.log(result); }, function(error) { console.log(error.message); } );
I would expect that i have to expand the "msdyn_inspection" property of the servicetasks like this but i get the error "Query option '$expand' was specified more than once, but it must be specified at most once."
Xrm.WebApi.retrieveRecord( "msdyn_workorder", "6bf60eff-2e64-ed11-9561-6045bd8edfa9", `?$select=msdyn_workorderid &$expand=msdyn_msdyn_workorder_msdyn_workorderservicetask_WorkOrder( $select=msdyn_name, msdyn_description, msdyn_workorderservicetaskid, msdyn_actualduration, msdyn_inspection &$expand=msdyn_Inspection($select=msdyn_inspectionid,msdyn_description,msdyn_name,statecode,msdyn_state,statuscode) )`).then(function success(result) {console.log(result); }, function(error) { console.log(error.message); } );