Created
January 13, 2020 08:38
-
-
Save melamriD365/ad5aed60d7d083c09d90244886893cfe to your computer and use it in GitHub Desktop.
Dynamics365 CRM UCI get all activities (subgrid refresh)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getActivities(executionContext) { | |
var formContext = executionContext.getFormContext(); | |
//get current contact id; | |
var recordId = formContext.data.entity.getId(); | |
var ActivitiesSubGridControl = formContext.getControl("ActivitiesSubGrid"); | |
//recordId = recordId.replace("{", "").replace("}", ""); | |
recordId = recordId.slice(1, -1); | |
var orConditionsList = []; | |
var orConditionsFetchXml = ""; | |
var fetchXml = ""; | |
Xrm.WebApi.online.retrieveMultipleRecords("activityparty", "?$select=_activityid_value&$filter=_partyid_value eq " + recordId).then( | |
function success(result) { | |
for (var i = 0; i < result.entities.length; i++) { | |
orConditionsList.push(result.entities[i]["_activityid_value"]); | |
} | |
for (var i = 0; i < orConditionsList.length; i++) { | |
orConditionsFetchXml += '<value>' + orConditionsList[i] + '</value>' | |
//console.log(orConditionsList[i]); | |
} | |
if (orConditionsList.length != 0) { | |
fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + | |
" <entity name='activitypointer'>" + | |
" <attribute name='subject' />" + | |
" <attribute name='ownerid' />" + | |
" <attribute name='prioritycode' />" + | |
" <attribute name='regardingobjectid' />" + | |
" <attribute name='activitytypecode' />" + | |
" <attribute name='statecode' />" + | |
" <attribute name='scheduledstart' />" + | |
" <attribute name='scheduledend' />" + | |
" <attribute name='activityid' />" + | |
" <attribute name='instancetypecode' />" + | |
" <attribute name='community' />" + | |
" <attribute name='senton' />" + | |
" <attribute name='statuscode' />" + | |
" <order attribute='scheduledend' descending='false' />" + | |
" <filter type='and'>" + | |
" <condition attribute='isregularactivity' operator='eq' value='1' />" + | |
" <condition attribute='activityid' operator='in'>" + | |
orConditionsFetchXml + | |
" </condition>" + | |
" </filter>" + | |
" </entity>" + | |
"</fetch>" | |
console.log(fetchXml); | |
ActivitiesSubGridControl.setFilterXml(fetchXml); | |
ActivitiesSubGridControl.refresh(); | |
} else { | |
fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + | |
" <entity name='activitypointer'>" + | |
" <filter type='and'>" + | |
" <condition attribute='statecode' operator='null'/>" + | |
" </filter>" + | |
" </entity>" + | |
"</fetch>"; | |
ActivitiesSubGridControl.setFilterXml(fetchXml); | |
ActivitiesSubGridControl.refresh(); | |
} | |
}, | |
function (error) { | |
console.log(error.message); | |
// handle error conditions | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment