Change channel based on selected user in an onchange Workflow script ?

Hi all,

I've read as much as possible in the forum and find it strange that no one ever asked for that exactly...

During Case creation, which runs under an enabled new Case Workflow rule, I want that the Channel field is dynamically changed when the user changes the assigned user.

I supposed basically that I would solve this easily with :

1) a Create Script that sets the case_assigneduserid "Defaultvalue=CurrentUser.user_userid;"

2)an OnChange Script on the case_assigneduserid to change the case_channelid, but then I find it impossible to do that easily as I am here stuck at a client side level.

var AssignedUserID = crm.fields("case_assigneduserid").value(); //this is quite easy to retrieve the assigned user id.

But what about finding the Channel Id of this AssignedUserId ?

How can I do that within the scope of the new Case Workflow rule ?

Any help would be appreciated...

Parents Reply Children
  • Wow this looks very elegant. It's a very clean way for OP to do this.

  • I tried this but it's not working...

    // Retrieves a User record from within a Ticket and collects that record in var.
    function getUser(userID)
        var returnedValue, successUser = function (crmRecord) {
                    returnedValue = crmRecord;
                entity: "users",
                async: false,
                id: userID,
                success: successUser
          return returnedValue;

    var curUserID = crm.fields("case_assigneduserid").value();
    var ChannelID = getUser(curUserID).user_primarychannelid;

    Could you help me ?

  • Your code looks sound, however I think something might be going wrong when you want to return from the getUser function, it might be returning a null because of the way the sdata calls works. 

    Perhaps try something more "ancient" like this - 

    customUserObject = null;
    function getUser(userID)
    entity: "users",
    async: true,
    id: userID,
    success: function(crmRecord){customUserObject=crmRecord}

    so yes, there is a "global" variable for the user object, but then you can handle the getUser as a void and just call the customUserObject every time you need values from it.
    Like so - 

    var channelid = customUserObject.user_primarychannelid;

  • Sorry but it doesn't work either.

    Do I have to put all that code in the Workflow rule "New Ticket", in the action "Display field for Amendment" for the field "case_assigneduserid", in the "OnChange Script" ?

    Or somewhere else ? If so, where then ?

  • I would recommend testing in the console first, then placing it in CRM. So in the console you can just copy the code to the console and it should work fine. 

    I would not recommend putting functions in the onchange script, rather use the custom js folder for that and then call the script with onchange, if you want to. 

    It also depends when you want it to fire, on the change of the field, or on load of the screen.