web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Is it possible to create a Save and Resolve button using Javascript so that it saves the record and then immediately uses the record ID

(0) ShareShare
ReportReport
Posted on by 2,175

Hi all,

I've been this week trying to put a few easier to use ribbon buttons in cases so that resolving a case can be a quick one click thing. One thing that I'm having trouble figuring out is how would I go about creating a ribbon button that on create of the case allows it to save the case and then immediately grab the saved case's GUID and use it in a CloseIncident function.

This is what I got to so far. Just trying to console.log the case ID to see if I can actually get it as soon as I save the record.

// SAVE AND RESOLVE FUNCTION


   function ribbonSaveAndResolveTrigger (PrimaryItemIds,PrimaryControl,CommandProperties) {
    // Determine the button context. Whether it's in the Form, Home or Subgrid
    var buttonContextArray = CommandProperties.SourceControlId.split("|");
    var buttonContext = buttonContextArray[2];      
 //Create the formContext variable based on the button context.
    var formContext;
    if (buttonContext == 'Form') {
        formContext = PrimaryControl;
    } else {
        formContext = PrimaryControl.getFormContext();
    }
    // Trying to save the Case record first so that it will generate a GUID
    formContext.data.entity.save();
    // Then trying to refresh the record
    formContext.data.refresh();
    // Trying to get the GUID and then console.log it.
    var caseId = formContext.data.entity.getId();
    console.log(caseId);
   }

At the moment it won't get the ID at all. Is there a way to do this using javascript or will this have to be a plugin?

pastedimage1582773672856v1.png

I have the same question (0)
  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    You think about having an OnChange event on a field like ModifiedOn or createdon and then do the resolve but what about the following approach?

    You could add a two options field to to the case, lets call it : Resolve Case?

    When your Save & Resolve button is clicked, you have to set value true to the above field first and then call :  formContext.data.entity.save(saveOption);

    docs.microsoft.com/.../save

    Now, on the server side, create a real-time workflow that triggers on Create / Update of the field Resolve Case.

    In this workflow, you will check if the value is true, if so, just use the Change Status step to resolve the case.

    One added benefit of this is that you do not have to write JS to close the case, its done by Workflow.

    Remember to use real-time workflow not background.

  • Suggested answer
    Luis Nogueira Profile Picture
    on at

    Hi MikeC282,

    You need to get the new record GUID on the onload event.

    You can use addOnLoad for that.

    Please check :

    community.dynamics.com/.../firing-on-load-event-every-time-when-record-is-saved-exploring-the-data-onload-event-in-dynamics-v9-0

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans