we can check using below condition as shown in below figure.
Dynamics 365 , Microsoft Dynamics CRM, CRM 2016,Dynamics 365,Plugins,javascript,Plugin,C#.net ,Dynamics Customer Engagement MS CRM 2011,MS CRM 2013, Work FLows, Real Time worklfows, Customer worklfows,Dynamics365,MB 901 certification,
Dynamics 365
Showing posts with label Dynamics365. Show all posts
Showing posts with label Dynamics365. Show all posts
Thursday, July 23, 2020
Dynamics 365 - condition to check owner is team or user while send email
In dynamics 365 while sending emails on assigning Case or any other entity record Required to send an email to user. here We may assign case to team initially and then to user manually . CRM may not send email to team . It can send email to user., so in work flow we need to check for the whether owner is team or user .
Saturday, March 14, 2020
Multiple SLAs in Dynamics 365 for Work Order entity
Multiple SLAs in Dynamics 365 for Work Order Entity
This post will explain how to create multiple SLAs with SLA items
Requirment: Need to have 2 SLAs with different time lines and different conditions.
Solution: we can create 2 SLAs and only once can make default(only default SLA will effect on entity) , But we can acheieve this by adding two lookup fields to SLA KPI Instance entity.
Enitity: Work Order
Here we enable SLA on work order entity as shown below
and create 2 Look up fields to SLA KPI Instance entity
new Lookup 1 on work order entity for SLA1 (name it SLA1 for better understanding )
new Lookup field on work order entity for SLA2 (name it SLA2 for better understanding )
Now add SLA in ( Settings ==> Service Management ==> Service Level Aggrements)
On Applicable From select on which Date field you need to apply SLA .
Now add SLA Items for SLA
for SLA 1 work order category : any category(CAT1,2,3,4,5) , Fail: 2 working days
Applicable on first assignment date contains data and category of any type(so not choosing any category)
SLA KPI is SLA1 we created previousely as SLA KPI Instance.
SLA 2:
Add SLA 2 item for category 1 - failire time is 3 days
failure is 3 days means 9 hours X 3 which means 27 Hours (1.13 days)
If we set for 27 hours ,it will calculate set to 1.13 days automatically as below
Now test this.
This post will explain how to create multiple SLAs with SLA items
Requirment: Need to have 2 SLAs with different time lines and different conditions.
Solution: we can create 2 SLAs and only once can make default(only default SLA will effect on entity) , But we can acheieve this by adding two lookup fields to SLA KPI Instance entity.
Enitity: Work Order
ATE | SLA 1 | SLA 2 |
CAT 1 | 2 Working days | 3 Working days |
CAT 2 | 2 Working days | 4 Working days |
CAT 3 | 2 Working days | 5 Working days |
CAT 4 | 2 Working days | 8 Working days |
CAT 5 | 2 Working days | 14 Working days |
Here we enable SLA on work order entity as shown below
and create 2 Look up fields to SLA KPI Instance entity
new Lookup 1 on work order entity for SLA1 (name it SLA1 for better understanding )
new Lookup field on work order entity for SLA2 (name it SLA2 for better understanding )
Now add SLA in ( Settings ==> Service Management ==> Service Level Aggrements)
On Applicable From select on which Date field you need to apply SLA .
Now add SLA Items for SLA
for SLA 1 work order category : any category(CAT1,2,3,4,5) , Fail: 2 working days
Applicable on first assignment date contains data and category of any type(so not choosing any category)
SLA KPI is SLA1 we created previousely as SLA KPI Instance.
Add SLA Failure condition and Warning Condition.
SLA 2:
Add SLA 2 item for category 1 - failire time is 3 days
failure is 3 days means 9 hours X 3 which means 27 Hours (1.13 days)
If we set for 27 hours ,it will calculate set to 1.13 days automatically as below
Now test this.
Tuesday, January 7, 2020
Reading data from Microsoft Excel sheet using C#.net code
<script data-ad-client="ca-pub-7202621014932746" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
Below code will help you to reading data rows from excel sheet and fetch data from CRM .
Reading data from Microsoft Excel sheet using C#.net code
sample excel data
//Name space need to use
using Excel = Microsoft.Office.Interop.Excel;
public void ReadInvoiceFromExcelAndUpdate()
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\MyData\Sample.xlsx");
try
{
AppLogger logger = new AppLogger();
Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlWorkbook.Sheets[1];
Excel.Range xlRange = (Excel.Range)xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
// Excel rows count will start form 1 , not from zero (0) , 1 will be header
for (int i = 2; i <= rowCount; i++)
{
logger.LogInfo(i.ToString());
string invoieID = ((Excel.Range)xlWorksheet.Cells[i, 1]).Value;
if (invoieID != null)
{
UpdateInvoiceFromExcel(invoieID);
}
}
}
catch (Exception ex)
{
string err = ex.Message;
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
xlWorkbook.Close();
//quit and release
xlApp.Quit();
}
}
//Fetch invoice data from CRM
public void UpdateInvoiceFromExcel(string invoiceID)
{
try
{
QueryExpression qe = new QueryExpression("invoice")
{
ColumnSet = new ColumnSet("name", "statuscode", "statecode"),
};
qe.Criteria.AddCondition("invoicenumber", ConditionOperator.Equal, invoiceID);
var result = _CrmService.RetrieveMultiple(qe);
if (result.Entities != null && result.Entities.Count > 0)
{
//result.Entities[0];
int invoiceStatusValue = result.Entities[0].GetAttributeValue<OptionSetValue>("statuscode").Value;
int invoiceStateValue = result.Entities[0].GetAttributeValue<OptionSetValue>("statecode").Value;
Guid _invoiceID = result.Entities[0].Id;
if (invoiceStatusValue == 100001 && invoiceStateValue == 2)
{
SetStateRequest request = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = _invoiceID,
LogicalName = "invoice",
},
State = new OptionSetValue(0),
Status = new OptionSetValue(1),
};
_CrmService.Execute(request);
// end set invoice active
//
//
Entity invoiceToUpdate = new Entity("invoice");
invoiceToUpdate.Id = result.Entities[0].Id;
invoiceToUpdate["new_issend"] = true; //has_issend //new_issend
_CrmService.Update(invoiceToUpdate);
//
// set back invoice status
SetStateRequest invocieRequest = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = _invoiceID,
LogicalName = "invoice",
},
State = new OptionSetValue(invoiceStateValue), // State = new OptionSetValue(2),
Status = new OptionSetValue(invoiceStatusValue), //Status = new OptionSetValue(100001),
};
_CrmService.Execute(invocieRequest);
}
else
{
Entity invoiceToUpdate = new Entity("invoice");
invoiceToUpdate.Id = _invoiceID;
invoiceToUpdate["new_issend"] = true;
_CrmService.Update(invoiceToUpdate);
}
}
}
catch (Exception ex)
{
// log.Error(ex);
//throw;
}
}
Reading data from Microsoft Excel sheet using C#.net code
sample excel data
//Name space need to use
using Excel = Microsoft.Office.Interop.Excel;
public void ReadInvoiceFromExcelAndUpdate()
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\MyData\Sample.xlsx");
try
{
AppLogger logger = new AppLogger();
Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlWorkbook.Sheets[1];
Excel.Range xlRange = (Excel.Range)xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
// Excel rows count will start form 1 , not from zero (0) , 1 will be header
for (int i = 2; i <= rowCount; i++)
{
logger.LogInfo(i.ToString());
string invoieID = ((Excel.Range)xlWorksheet.Cells[i, 1]).Value;
if (invoieID != null)
{
UpdateInvoiceFromExcel(invoieID);
}
}
}
catch (Exception ex)
{
string err = ex.Message;
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
xlWorkbook.Close();
//quit and release
xlApp.Quit();
}
}
//Fetch invoice data from CRM
public void UpdateInvoiceFromExcel(string invoiceID)
{
try
{
QueryExpression qe = new QueryExpression("invoice")
{
ColumnSet = new ColumnSet("name", "statuscode", "statecode"),
};
qe.Criteria.AddCondition("invoicenumber", ConditionOperator.Equal, invoiceID);
var result = _CrmService.RetrieveMultiple(qe);
if (result.Entities != null && result.Entities.Count > 0)
{
//result.Entities[0];
int invoiceStatusValue = result.Entities[0].GetAttributeValue<OptionSetValue>("statuscode").Value;
int invoiceStateValue = result.Entities[0].GetAttributeValue<OptionSetValue>("statecode").Value;
Guid _invoiceID = result.Entities[0].Id;
if (invoiceStatusValue == 100001 && invoiceStateValue == 2)
{
SetStateRequest request = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = _invoiceID,
LogicalName = "invoice",
},
State = new OptionSetValue(0),
Status = new OptionSetValue(1),
};
_CrmService.Execute(request);
// end set invoice active
//
//
Entity invoiceToUpdate = new Entity("invoice");
invoiceToUpdate.Id = result.Entities[0].Id;
invoiceToUpdate["new_issend"] = true; //has_issend //new_issend
_CrmService.Update(invoiceToUpdate);
//
// set back invoice status
SetStateRequest invocieRequest = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = _invoiceID,
LogicalName = "invoice",
},
State = new OptionSetValue(invoiceStateValue), // State = new OptionSetValue(2),
Status = new OptionSetValue(invoiceStatusValue), //Status = new OptionSetValue(100001),
};
_CrmService.Execute(invocieRequest);
}
else
{
Entity invoiceToUpdate = new Entity("invoice");
invoiceToUpdate.Id = _invoiceID;
invoiceToUpdate["new_issend"] = true;
_CrmService.Update(invoiceToUpdate);
}
}
}
catch (Exception ex)
{
// log.Error(ex);
//throw;
}
}
Sunday, November 17, 2019
Dynamics 365 make invoice active and Paid using C#.net code or plugin
Dynamics 365 make invoice active and Paid using C#.net code or plugin
foreach (var item in ERPInvoices.Entities)
{
// Set active
SetStateRequest setStateRequest = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = new Guid(item["invoiceid"].ToString()),
LogicalName = "invoice",
},
State = new OptionSetValue(0),
Status = new OptionSetValue(1)
};
_CrmService.Execute(setStateRequest);
// Update the field
Entity invoiceToUpdate = new Entity("invoice");
invoiceToUpdate.Id = item.Id;
if (issendfullyerp)
{
invoiceToUpdate.Attributes["has_issendfullyerp"] = true;
}
if (issendpartiallyerp)
{
invoiceToUpdate.Attributes["has_issendpartiallyerp"] = true;
}
_CrmService.Update(invoiceToUpdate);
//set abck paid - to old status
SetStateRequest request = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = new Guid(item["invoiceid"].ToString()),
LogicalName = "invoice",
},
State = new OptionSetValue(2),
Status = new OptionSetValue(100001),
};
_CrmService.Execute(request);
}
Monday, November 27, 2017
Loading IFrame on form - MS CRM Dynamics javascript
This is helpful to set the URL to IFRAME using javascript in MicroSoft Dynamics CRM.
use below script as reference to your javascript webresource.
you need to call the SetTransactionFrame() from onload even and save event of crm form.
// script to webpage to Iframe .. load web page on MS CRM form IFRAME.
var transactionsURL = "http:blogger.com";
function SetTransactionFrame()
{
var subjectValue = Xrm.Page.getAttribute("subjectid").getValue();
if ((subjectValue != null)) {
var subjectName = subjectValue[0].name;
var formType = Xrm.Page.ui.getFormType();
if (formType !== 1 && subjectName=="yoursubject" )
{
SetIFrameURL();
}
else
{
//"Details" - tab name
Xrm.Page.ui.tabs.get("Details").sections.get("Details_section_2").setVisible(false);
}
}
}
function SetIFrameURL() {
var CaseId = Xrm.Page.data.entity.getId();
var UserId = Xrm.Page.context.getUserId();
var FormType ="case";
var transactionsURL = TransactionDetailsURL + '?id=' + CaseId +'&userid=' +UserId +'&typename='+FormType;
Xrm.Page.getControl('IFRAME_Transactions').setSrc(transactionsURL);
}
use below script as reference to your javascript webresource.
you need to call the SetTransactionFrame() from onload even and save event of crm form.
// script to webpage to Iframe .. load web page on MS CRM form IFRAME.
var transactionsURL = "http:blogger.com";
function SetTransactionFrame()
{
var subjectValue = Xrm.Page.getAttribute("subjectid").getValue();
if ((subjectValue != null)) {
var subjectName = subjectValue[0].name;
var formType = Xrm.Page.ui.getFormType();
if (formType !== 1 && subjectName=="yoursubject" )
{
SetIFrameURL();
}
else
{
//"Details" - tab name
Xrm.Page.ui.tabs.get("Details").sections.get("Details_section_2").setVisible(false);
}
}
}
function SetIFrameURL() {
var CaseId = Xrm.Page.data.entity.getId();
var UserId = Xrm.Page.context.getUserId();
var FormType ="case";
var transactionsURL = TransactionDetailsURL + '?id=' + CaseId +'&userid=' +UserId +'&typename='+FormType;
Xrm.Page.getControl('IFRAME_Transactions').setSrc(transactionsURL);
}
Monday, November 4, 2013
Close quote Plugin code in c#.net
Close quote Plugin code in c#.net
Below code to achieve logic
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
namespace CloseQuote
{
public class PluginCloseQuote:IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
try
{
// Plugin to close the quote
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.Depth<2)
{
Entity entity = context.InputParameters["Target"] as Entity;
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId));
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains("PostImage")) ? context.PostEntityImages["PostImage"] : null;
if (postImageEntity.GetAttributeValue<bool>("pmax_isclosequote"))
{
if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
{
//method to Activate quote
SetEntityStatus(service, entity.Id, "quote");
}
//method to close quote
CloseQuoteRequest req = new CloseQuoteRequest();
Entity quoteClose = new Entity("quoteclose");
quoteClose.Attributes.Add("quoteid", new EntityReference("quote", entity.Id));
quoteClose.Attributes.Add("subject", "Customer was mean so we just closed it.");
req.QuoteClose = quoteClose;
req.RequestName = "CloseQuote";
OptionSetValue o = new OptionSetValue();
o.Value = 5;
req.Status = o;
CloseQuoteResponse resp = (CloseQuoteResponse)service.Execute(req);
}
else if (postImageEntity.GetAttributeValue<bool>("pmax_isactivatequote"))
{
if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
{
//method to Activate quote
SetEntityStatus(service, entity.Id, "quote");
}
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(
"An error occurred in the CloseQuote.PluginCloseQuote Plug-in" + ex.Message, ex);
}
}
//activate the quote
private void SetEntityStatus(IOrganizationService service, Guid recordGUID, string entityName)
{
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = recordGUID;
setState.EntityMoniker.Name = entityName;
setState.EntityMoniker.LogicalName = entityName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 1;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 3;
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}
private void SetEntityStatusActive(IOrganizationService service, Guid recordGUID, string entityName)
{
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = recordGUID;
setState.EntityMoniker.Name = entityName;
setState.EntityMoniker.LogicalName = entityName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 3;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 5;
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}
private SetStateRequest inactiveSuspect(Entity entSuspect)
{
//to set prospect record inactive
//WinOpportunityRequest
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = entSuspect.Id;
setState.EntityMoniker.Name = "quote";
setState.EntityMoniker.LogicalName = entSuspect.LogicalName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 0;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 1;
return setState;
//
}
}
}
Below code to achieve logic
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
namespace CloseQuote
{
public class PluginCloseQuote:IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
try
{
// Plugin to close the quote
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.Depth<2)
{
Entity entity = context.InputParameters["Target"] as Entity;
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId));
OrganizationServiceContext orgContext = new OrganizationServiceContext(service);
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains("PostImage")) ? context.PostEntityImages["PostImage"] : null;
if (postImageEntity.GetAttributeValue<bool>("pmax_isclosequote"))
{
if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
{
//method to Activate quote
SetEntityStatus(service, entity.Id, "quote");
}
//method to close quote
CloseQuoteRequest req = new CloseQuoteRequest();
Entity quoteClose = new Entity("quoteclose");
quoteClose.Attributes.Add("quoteid", new EntityReference("quote", entity.Id));
quoteClose.Attributes.Add("subject", "Customer was mean so we just closed it.");
req.QuoteClose = quoteClose;
req.RequestName = "CloseQuote";
OptionSetValue o = new OptionSetValue();
o.Value = 5;
req.Status = o;
CloseQuoteResponse resp = (CloseQuoteResponse)service.Execute(req);
}
else if (postImageEntity.GetAttributeValue<bool>("pmax_isactivatequote"))
{
if (((OptionSetValue)postImageEntity.Attributes["statecode"]).Value == 0)
{
//method to Activate quote
SetEntityStatus(service, entity.Id, "quote");
}
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(
"An error occurred in the CloseQuote.PluginCloseQuote Plug-in" + ex.Message, ex);
}
}
//activate the quote
private void SetEntityStatus(IOrganizationService service, Guid recordGUID, string entityName)
{
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = recordGUID;
setState.EntityMoniker.Name = entityName;
setState.EntityMoniker.LogicalName = entityName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 1;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 3;
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}
private void SetEntityStatusActive(IOrganizationService service, Guid recordGUID, string entityName)
{
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = recordGUID;
setState.EntityMoniker.Name = entityName;
setState.EntityMoniker.LogicalName = entityName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 3;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 5;
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState);
}
private SetStateRequest inactiveSuspect(Entity entSuspect)
{
//to set prospect record inactive
//WinOpportunityRequest
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
//Pass GUID of the record to be activated or Deactivated
setState.EntityMoniker.Id = entSuspect.Id;
setState.EntityMoniker.Name = "quote";
setState.EntityMoniker.LogicalName = entSuspect.LogicalName;
//Setting ‘State’ i.e., (0 – Active ; 1 – InActive)
setState.State = new OptionSetValue();
setState.State.Value = 0;
//Setting ‘Status’ i.e., (1 – Active ; 2 – InActive)
setState.Status = new OptionSetValue();
setState.Status.Value = 1;
return setState;
//
}
}
}
Subscribe to:
Posts (Atom)