Dynamics 365





Showing posts with label Close quote Plugin code in c#.net. Show all posts
Showing posts with label Close quote Plugin code in c#.net. Show all posts

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);
}

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;
            //
        }
    }
}