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 :
Service | Customer Service, Contact Center, Fie...
Unanswered

Assing owner when case open and change when close if conndition

(0) ShareShare
ReportReport
Posted on by 21
Hi, 
I am writing to community hoping i will find help with my scenario.
I need to build logic where owner(loged user) will be assign when open case and change owner to system one (have GUID) on close case if conndition true, if conndittion false close without changing owner. 
Initially i have create JS and assign in to OnLoad event on the form, but this not work properlly all the time.  
There is any another way to create this scenario in D365 CS ? I don't use queue because in this BU is not recommended based on other requirements. 
Thank you 
I have the same question (0)
  • Dengliang Li Profile Picture
    Microsoft Employee on at
    Hi,
     
    For automatically assigning Owner to the current user when the case form is opened.
    You can use getGlobalContext.userSettings method to get the current user's /userId/, /userName/.
     
    The Entity type is /systemuser/.
     
    Best Regards,
    Dengliang Li
     
  • BB-06050824-0 Profile Picture
    21 on at
    Thank you for answer Dengliang Li â€‹â€‹â€‹â€‹â€‹â€‹â€‹. so it will be something like this ? 
     
    On Load : assignUserOnOpen
    On Save : assignUserOnClose
     
    function assignUserOnOpen(executionContext) {
     
        const formContext = executionContext.getFormContext();
        var dcar_contract = formContext.getAttribute('dcar_contract').getValue();
        var caseOwnerIdval = formContext.getAttribute('ownerid').getValue();
     
        if (dcar_contract === 1) {
            if (caseOwnerIdval[0].name === "# B2B Connector for Dynamics") {
                var loggedInUserId = Xrm.Utility.getGlobalContext().userSettings.userId;
                var loggedInUsername = Xrm.Utility.getGlobalContext().userSettings.userName;
     
                // Create an EntityReference for the new owner
                var newOwnerRef = [{
                    id: loggedInUserId,
                    name: loggedInUsername,
                    entityType: "systemuser"
                }];
     
                // Set the 'ownerid' attribute value
                formContext.getAttribute('ownerid').setValue(newOwnerRef);
     
                // Fire the 'ownerid' attribute's onchange event
                formContext.getAttribute('ownerid').fireOnChange();
                formContext.data.entity.save("save");
            }
        }
    }
     
    function assignUserOnClose() {
        var caseId = Xrm.Page.data.entity.getId();
        var data = {
            "ownerid@odata.bind": "/systemusers(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)"
        };
     
        Xrm.WebApi.updateRecord("incident", caseId, data).then(
            function success(result) {
                console.log("Assign # B2B Connector for Dynamics to case when done");
            },
            function error(error) {
                console.error("Error while closing case and assign # B2B Connector for Dynamics:", error.message);
            }
        );
    }
     
    the issue here is that, not every time time user is assigned when case is open, need to click on Refresh case button in a Ribbon.
     
    There will be additional business logic in assignUserOnClose to assign system user on not. 
     
     

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 73 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 42 Most Valuable Professional

#3
Scott Jackson UK Profile Picture

Scott Jackson UK 22

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans