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

SUGGESTED

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
  • 0 in reply to PPI-VDM

    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.

  • 0 in reply to Conrad Roux

    Thank you for your advice. I must confess that I'm not used to deal with the console mode at all. I can read / write js, but I am not a developer and I don't know how to develop / debug using the right tools...

    I get the idea for the custom script by the way I will try it.

    What I want is that the script changes the team field value when I "leave" the assignedUserId field (or on the LostFocus Event of the form if you prefer). I don't if it should be better a "client side" or a "server side" script to work properly.

    Almost first time I'm stuck with that...

  • 0 in reply to PPI-VDM
    SUGGESTED

    If it is for the user select list, then you will have better luck with adding the "blur" effect when loading the page, so again it needs to be in the custom js folder (it can all be in one script file). I have had some issues with the onchange when working with the user selection list.

    so when you open the console on the correct page, try this ->

    $( "#table_fieldid" ).blur(function() {console.log("blur fired")});

    Then change the field value and click out. See if it prints the message in the console. Remember to use the inspect element as the field ID on that field can sometimes be different. See my example below of it working.

    You can see the script I added, and then the console message logging "blur fired"
    Here is the code I used -> 

    $( "#case_assigneduseridInput" ).blur(function() {console.log("blur fired")});

    From here, you can then attach and event/function to the event, so instead of firing a message, you can execute that function that I added in an earlier post.

    Hope this helps

    EDIT - When working with the custom js folder, it is always advise that you run the code of a script only when needed. You can do this with the ACT function and using an if to block execution on certain pages, otherwise it will try and run on every page, and that could break other functions in CRM. Please do some reading on this matter as it will be very important