Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Update WorkerId in QueueItem entity with JavaScript

Posted on by Microsoft Employee

Hi!

I'm trying to update WorkerId(in QueueItem) with XrmSvcToolkit.updateRecord and get success in return but nothing happens!

Any good ideas what I'm doing wrong?

Here is my code:

function setIncidentWorkedOn(incidentGuid) {

   var iGuid = incidentGuid.replace("{", "'").replace("}", "'");

   var queueitemid;

   var systemUser;

   //Get the QueueItem entity

   var filterQueryQueueItem = "?$filter=ObjectId/Id eq guid" + iGuid;

   XrmSvcToolkit.retrieveMultiple({

       entityName: "QueueItem",

       async: false,

       odataQuery: filterQueryQueueItem,

       successCallback: function (result) {

           queueitemid = result[0].QueueItemId;

           //Get the user entity

           var uRef = Xrm.Page.context.getUserId();

           XrmSvcToolkit.retrieve({

               entityName: "SystemUser",

               id: uRef,

               async: false,

               successCallback: function (resultUser) {

                   systemUser = resultUser;

               },

               errorCallback: function (error) {

                   alert(error.description);

               }

           });

       },

       errorCallback: function (error) {

           alert(error.description);

       }

   });

   //Update QueueItem - WorkerId attribute with user    

   XrmSvcToolkit.updateRecord({

       entityName: "QueueItem",

       id: queueitemid,

       entity: { WorkerId: systemUser.Id },

       async: false,

       successCallback: function (resultUpdate) {

           //Xrm.Page.data.entity.save();

            alert("Success!");

               } ,

        errorCallback: function (error) {

           alert(error.description);

       }

   });

}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update WorkerId in QueueItem entity with JavaScript

    Thanks a lot for answers!

    I had to an adjustment, this code Works Perfect:

    var contextUserId = Xrm.Page.context.getUserId();

       XrmSvcToolkit.updateRecord({

           entityName: "QueueItem",

           id: queueitemid,

           entity: {

               WorkerId: {

                   Id: contextUserId,

                   LogicalName: "systemuser"

               }

           },

           async: false,

           successCallback: function (result) {

           },

           errorCallback: function (error) {

               alert("Det oppstod en feil, vennligst kontakt EVRY. Update QueueItem: " + error.description);

           }

       });

    Cheers:-)

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Update WorkerId in QueueItem entity with JavaScript

    Hello Knut,

    you colud try to remove " ' " from replace function and to put only ""

    Also you could to try to update a simple field as a string field... only for test.

    Let me know,

    Thanks

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans