Javascript workflow rule condition : find another user than the currentUser

Hi I have a problem with a javascript condition in a workflow rule.

I want to limit the ability of closing a case to members of the case creator team only.

For that purpose I need to get the user_primarychannelid related to the "case_createdby" userID and compare it with the currentUser.user_userprimarychannelid.

Here is the code I've tried which I have decomposed step by step but it doesn't work.

Any help would be appreciated !

/*

var CreatedBy = eware.GetContextInfo("Case","case_createdby");
var Creator = eWare.FindRecord("Users","user_userid="+ CreatedBy);
var ChannelId = Creator.user_userprimarychannelid;
var CurrentChannelID = CurrentUser.user_userprimarychannelid;

if (CurrentChannelID == ChannelId)
{
Valid=true;
}
else
{
Valid=false;
}

*/

Thanks

Valérian

  • 0

    Hi,

    You can follow below code to check whether current user’s team is same as case created by user’s team.

    var ChannelId="";
    var CurrentChannelID="";
    //' Get Created By User and its Channel Id
    var CreatedBy = new String(eWare.GetContextInfo("Cases","case_createdby"));
    if (CreatedBy == "" || CreatedBy == "undefined" || CreatedBy == "null") CreatedBy = "";
    var Creator = eWare.FindRecord("Users","user_userid="+ CreatedBy);
    if(!Creator.eof)
    {
    ChannelId=new String(Creator("user_primarychannelid"))
    if (ChannelId == "" || ChannelId == "undefined" || ChannelId == "null") ChannelId = "";
    }

    //' Get Current User's Channel Id
    CurrentChannelID = new String(eWare.GetContextInfo("User","user_primarychannelid"));
    if (CurrentChannelID == "" || CurrentChannelID == "undefined" || CurrentChannelID == "null") CurrentChannelID = "";

    if(CurrentChannelID!="" && ChannelId!="")
    {
    CurrentChannelID=parseInt(CurrentChannelID)
    ChannelId=parseInt(ChannelId)

    if(CurrentChannelID==ChannelId)
    Valid=true;
    else
    Valid=false;
    }

    Hope this helps!

    Regards,
    Dinesh

  • 0

    Works perfectly !

    thank you Dinesh for the help !

    Regards,

    Valérian