Name: Flow - Push Approved Time Entries To CRSM Description: This Power Automate Flow triggers when the “ap_timsheetstatus” field is modified to “Approved”. The flow uses the “TMAPI” custom connector, specifically the following end points: Add a time entry To add a time entry, the flow gets all the rows where the current timesheet is approved from the “Time Entries” table filtered via a FetchXML query to only get the rows where “Added to CRSM” is false and hours are not empty or null. Here’s the query:
Code Block |
---|
| <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="ap_timeentry">
<attribute name="ap_timeentryid" />
<attribute name="ap_timeid" />
<attribute name="createdon" />
<order attribute="ap_timeid" descending="false" />
<filter type="and">
<condition attribute="ap_addedtocrsm" operator="eq" value="0" />
<condition attribute="ap_timesheet" operator="eq" uitype="ap_timesheet" value="{@{triggerOutputs()?['body/ap_timesheetid']}}" />
<condition attribute="ap_employeelogin" operator="eq" value="@{triggerOutputs()?['body/ap_employeelogin']}" />
<condition attribute="ap_timecard" operator="eq" value="@{triggerOutputs()?['body/ap_reportingperiod']}" />
<condition attribute="ap_timeentryhours" operator="not-null" />
</filter>
</entity>
</fetch> |
Create a time entry record in the CRSM database.
Add hours to time entry This endpoint is used to create a record for adding hours for the time entry that was created in the previous step. Depending upon the “ap_timeentrytype” i.e. “Regular”, “Travel” or “Other”, corresponding action is called.
At the end of the flow, the flag “Added to CRSM” is set to true in the Time Entries table.
Push Time Entry to CRSM Step inside flow TypeCode: Regular (REG), Travel (TH), Other (DH) Code Block |
---|
[
{
"ServiceRequestId": @{int(variables('ServiceRequestID'))},
"ServiceId": @{outputs('Get_a_row_by_ID')?['body/ap_serviceid']},
"ApproverNetworkId": @{triggerOutputs()?['body/ap_approvedby']},
"Comment": @{items('Apply_to_each_-_Push_to_CRSM')?['ap_comments']},
"SubmitterNetworkId": @{items('Apply_to_each_-_Push_to_CRSM')?['ap_employeelogin']},
"DateTime": @{items('Apply_to_each_-_Push_to_CRSM')?['ap_timeentrydate']},
"Hours": [
{
"Quantity": @{items('Apply_to_each_-_Push_to_CRSM')?['ap_timeentryhours']},
"TypeCode": "REG",
"IsBillable": @{items('Apply_to_each_-_Push_to_CRSM')?['ap_billable']},
"StatusCode": 2
}
]
}
] |
|