Skip to main content

Notifications

Announcements

No record found.

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 
  • BB-06050824-0 Profile Picture
    BB-06050824-0 21 on at
    Assing owner when case open and change when close if conndition
    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. 
     
     
  • Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Assing owner when case open and change when close if conndition
    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
     

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans