Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Custom Resolve button Vs OOTB Resolve Case Button

(0) ShareShare
ReportReport
Posted on by 940

Hi All,

As per client requirement, I made a custom button which is used to resolve the case record. But anyhow Onsave Event scripts are not working through the custom button. Even I write a statement/line to save the form first as the OOTB Resolve button did but nothing happens. It saves the form but did not execute the Onsave event scripts.

May I know what is the reason or Is there something that I am missing?

Thanks in advance!

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Custom Resolve button Vs OOTB Resolve Case Button

    I mean if Xrm.Page.data.entity.save(); works fine then

    Xrm.Page.getAttribute("new_isresolved").setValue(true);

    Xrm.Page.getAttribute("new_timerstatus").setValue("0");

    should work fine as well.

  • RE: Custom Resolve button Vs OOTB Resolve Case Button

    My client doesn't like the pop-up window which appears after a click on the Resolve Case(OOTB) button that's why we have created a custom button to do the same.

    Ans 1) As System Resolve button did like when we hit the OOTB button it saves the form first and then an incident resolution window is appeared to make the case record resolved. I need to set a value within the fields 

    "window.parent.Xrm.Page.getAttribute("new_isresolved").setValue(true);" -----> This field is used for make the record resolved. Using this field the plugin will execute and change the status of record as resolved.

    "window.parent.Xrm.Page.getAttribute("new_timerstatus").setValue("0");" -----> This is used to stop the session timer which was running on the record.

    "Xrm.Page.data.entity.save();" ------> This is to save the form.

    Ans 2) Actually I don't know about the solution that you have provided. So I am gonna try the same and let you know.

    Thanks again for the response

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Custom Resolve button Vs OOTB Resolve Case Button

    Hello,

    Question 1 - why do you set attributes using window.parent.Xrm.Page and call save using Xrm.Page?

    Question 2 - why do you use set attribute + plugin instead of direct call of the WebApi? Here is an example - butenko.pro/.../

  • RE: Custom Resolve button Vs OOTB Resolve Case Button

    Hi Andrew,

    Thanks for the response and below are the elements:-

    First, I have created a field type of "Two Options" with field name is "new_isresolved" which sets Yes within that field when I click on the custom Resolve button it sets Yes into "new_isresolved" field and then saves the form.

    function ResolveCaseCustom()

    {
             try

    {


    window.parent.Xrm.Page.getAttribute("new_isresolved").setValue(true);
    window.parent.Xrm.Page.getAttribute("new_timerstatus").setValue("0");
    Xrm.Page.data.entity.save();

    }
    catch (error) { Xrm.Utility.alertDialog(error.message, null); }

    }

    Then I have implemented a plugin which check the value of "new_isresolved". If value is Yes then make the case record Resolved, the plugin code is given below:-

    using Microsoft.Crm.Sdk.Messages;
    using Microsoft.Xrm.Sdk;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace Samples
    {
    public class PostUpdateCase : IPlugin
    {
    public void Execute(IServiceProvider serviceProvider)
    {
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
    {
    Entity entity = (Entity)context.InputParameters["Target"];

    if (entity.LogicalName != "incident")
    return;

    try
    {
    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    //If Case Resolved flag check
    if (entity.Attributes.Contains("new_isresolved") && entity.Attributes["new_isresolved"] != null && Convert.ToBoolean(entity.Attributes["new_isresolved"]))
    {
    //Update the Is Resolve Flag to False.
    Entity updateCase = new Entity();
    updateCase.LogicalName = "incident";

    updateCase.Id = entity.Id;

    updateCase.Attributes.Add("new_isresolved", false);

    service.Update(updateCase);

    // Create the incidentresolution.
    Entity caseResolution = new Entity("incidentresolution");
    caseResolution.Attributes.Add("incidentid", new EntityReference("incident", entity.Id));
    caseResolution.Attributes.Add("subject", "Closed");
    // Close the incident with the resolution.
    CloseIncidentRequest req = new CloseIncidentRequest();
    req.IncidentResolution = caseResolution;
    req.RequestName = "CloseIncident";
    OptionSetValue o = new OptionSetValue();
    o.Value = 5;
    req.Status = o;

    CloseIncidentResponse resp = (CloseIncidentResponse)service.Execute(req);
    }
    }
    catch (InvalidPluginExecutionException)
    {
    throw;
    }
    }
    }
    }
    }

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Custom Resolve button Vs OOTB Resolve Case Button

    Can you please share the code that runs when your button is clicked?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans