Step1: Get current login user
Step2: Check login user Business unit if the business unit is a library
Step3: Get user role name if user role name is case management rep
Step4: Get the queue record & set that queue record email-sender lookup field in email entity
Step5: download XRM soap filed and call that file
function isLibraryUser(executionContext)
{
debugger;
var formContext = executionContext.getFormContext();
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var userid = userSettings.userId.replace('{','').replace('}','');
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
"<entity name='systemuser'>" +
"<attribute name='fullname' />" +
"<attribute name='businessunitid' />" +
"<attribute name='title' />" +
"<attribute name='address1_telephone1' />" +
"<attribute name='positionid' />" +
"<attribute name='systemuserid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='businessunitid' operator='eq' uiname='Library (LIB)' uitype='businessunit' value='{884BF9AC-62DB-E911-A813-000D3A851FF7}' />" +
"<condition attribute='systemuserid' operator='eq' uiname='# CRM_DEV1' uitype='systemuser' value='"+userid+"' />" +
"</filter>" +
"<link-entity name='systemuserroles' from='systemuserid' to='systemuserid' visible='false' intersect='true'>" +
"<link-entity name='role' from='roleid' to='roleid' alias='ac'>" +
"<filter type='and'>" +
"<condition attribute='name' operator='eq' value='Case Management Rep' />" +
"</filter>" +
"</link-entity>" +
"</link-entity>" +
"</entity>" +
"</fetch>";
var fetchedUsers = XrmServiceToolkit.Soap.Fetch(fetchXml);
if (fetchedUsers.length > 0) {
fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='queue'>"+
"<attribute name='name' />"+
"<attribute name='emailaddress' />"+
"<attribute name='queueid' />"+
"<order attribute='name' descending='false' />"+
"<filter type='and'>"+
"<condition attribute='name' operator='eq' value='Library (Lib)' />"+
"</filter>"+
"</entity>"+
"</fetch>";
var fetchedQueue = XrmServiceToolkit.Soap.Fetch(fetchXml);
if (fetchedQueue.length > 0)
{
var recorid = fetchedQueue[0].id;
var recordname = fetchedQueue[0].attributes.name.value;
var entityname = fetchedQueue[0].logicalName;
formContext.getAttribute("sp_senderservicemailbox").setValue([{ id: recorid, name: recordname, entityType: entityname}]);
}
}
}
Step2: Check login user Business unit if the business unit is a library
Step3: Get user role name if user role name is case management rep
Step4: Get the queue record & set that queue record email-sender lookup field in email entity
Step5: download XRM soap filed and call that file
function isLibraryUser(executionContext)
{
debugger;
var formContext = executionContext.getFormContext();
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var userid = userSettings.userId.replace('{','').replace('}','');
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
"<entity name='systemuser'>" +
"<attribute name='fullname' />" +
"<attribute name='businessunitid' />" +
"<attribute name='title' />" +
"<attribute name='address1_telephone1' />" +
"<attribute name='positionid' />" +
"<attribute name='systemuserid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='businessunitid' operator='eq' uiname='Library (LIB)' uitype='businessunit' value='{884BF9AC-62DB-E911-A813-000D3A851FF7}' />" +
"<condition attribute='systemuserid' operator='eq' uiname='# CRM_DEV1' uitype='systemuser' value='"+userid+"' />" +
"</filter>" +
"<link-entity name='systemuserroles' from='systemuserid' to='systemuserid' visible='false' intersect='true'>" +
"<link-entity name='role' from='roleid' to='roleid' alias='ac'>" +
"<filter type='and'>" +
"<condition attribute='name' operator='eq' value='Case Management Rep' />" +
"</filter>" +
"</link-entity>" +
"</link-entity>" +
"</entity>" +
"</fetch>";
var fetchedUsers = XrmServiceToolkit.Soap.Fetch(fetchXml);
if (fetchedUsers.length > 0) {
fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='queue'>"+
"<attribute name='name' />"+
"<attribute name='emailaddress' />"+
"<attribute name='queueid' />"+
"<order attribute='name' descending='false' />"+
"<filter type='and'>"+
"<condition attribute='name' operator='eq' value='Library (Lib)' />"+
"</filter>"+
"</entity>"+
"</fetch>";
var fetchedQueue = XrmServiceToolkit.Soap.Fetch(fetchXml);
if (fetchedQueue.length > 0)
{
var recorid = fetchedQueue[0].id;
var recordname = fetchedQueue[0].attributes.name.value;
var entityname = fetchedQueue[0].logicalName;
formContext.getAttribute("sp_senderservicemailbox").setValue([{ id: recorid, name: recordname, entityType: entityname}]);
}
}
}
No comments:
Post a Comment